diff options
author | Daniel Dunbar <daniel@zuster.org> | 2010-07-13 23:31:40 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2010-07-13 23:31:40 +0000 |
commit | af68a88e6862d26ebf4046a33308d531f85cd197 (patch) | |
tree | f5d70fd5db9b74f218263383e7a9d80967682407 | |
parent | c95a41b510824a8f24f9ba359ba78ff203dfabc0 (diff) | |
download | bcm5719-llvm-af68a88e6862d26ebf4046a33308d531f85cd197.tar.gz bcm5719-llvm-af68a88e6862d26ebf4046a33308d531f85cd197.zip |
Driver/Darwin: Pass -pie/-no_pie to the linker when -fpie/-fno-pie and friends
are explicitly given.
llvm-svn: 108297
-rw-r--r-- | clang/include/clang/Driver/ArgList.h | 2 | ||||
-rw-r--r-- | clang/include/clang/Driver/Options.td | 2 | ||||
-rw-r--r-- | clang/lib/Driver/ArgList.cpp | 19 | ||||
-rw-r--r-- | clang/lib/Driver/Tools.cpp | 11 | ||||
-rw-r--r-- | clang/test/Driver/darwin-ld.c | 12 |
5 files changed, 44 insertions, 2 deletions
diff --git a/clang/include/clang/Driver/ArgList.h b/clang/include/clang/Driver/ArgList.h index 16396daa60e..257b653f57e 100644 --- a/clang/include/clang/Driver/ArgList.h +++ b/clang/include/clang/Driver/ArgList.h @@ -179,6 +179,8 @@ namespace driver { Arg *getLastArg(OptSpecifier Id) const; Arg *getLastArg(OptSpecifier Id0, OptSpecifier Id1) const; Arg *getLastArg(OptSpecifier Id0, OptSpecifier Id1, OptSpecifier Id2) const; + Arg *getLastArg(OptSpecifier Id0, OptSpecifier Id1, OptSpecifier Id2, + OptSpecifier Id3) const; /// getArgString - Return the input argument string at \arg Index. virtual const char *getArgString(unsigned Index) const = 0; diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 96ec12215b4..cdd05ca1f65 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -230,6 +230,7 @@ def exported__symbols__list : Separate<"-exported_symbols_list">; def e : JoinedOrSeparate<"-e">; def fPIC : Flag<"-fPIC">, Group<f_Group>; def fPIE : Flag<"-fPIE">, Group<f_Group>; +def fno_PIE : Flag<"-fno-PIE">, Group<f_Group>; def faccess_control : Flag<"-faccess-control">, Group<f_Group>; def fapple_kext : Flag<"-fapple-kext">, Group<f_Group>; def fasm : Flag<"-fasm">, Group<f_Group>; @@ -356,6 +357,7 @@ def fpascal_strings : Flag<"-fpascal-strings">, Group<f_Group>; def fpch_preprocess : Flag<"-fpch-preprocess">, Group<f_Group>; def fpic : Flag<"-fpic">, Group<f_Group>; def fpie : Flag<"-fpie">, Group<f_Group>; +def fno_pie : Flag<"-fno-pie">, Group<f_Group>; def fprofile_arcs : Flag<"-fprofile-arcs">, Group<f_Group>; def fprofile_generate : Flag<"-fprofile-generate">, Group<f_Group>; def framework : Separate<"-framework">, Flags<[LinkerInput]>; diff --git a/clang/lib/Driver/ArgList.cpp b/clang/lib/Driver/ArgList.cpp index 95fef89b85d..91015237671 100644 --- a/clang/lib/Driver/ArgList.cpp +++ b/clang/lib/Driver/ArgList.cpp @@ -95,6 +95,25 @@ Arg *ArgList::getLastArg(OptSpecifier Id0, OptSpecifier Id1, return Res; } +Arg *ArgList::getLastArg(OptSpecifier Id0, OptSpecifier Id1, + OptSpecifier Id2, OptSpecifier Id3) const { + Arg *Res = 0; + for (const_reverse_iterator it = rbegin(), ie = rend(); it != ie; ++it) { + if ((*it)->getOption().matches(Id0) || + (*it)->getOption().matches(Id1) || + (*it)->getOption().matches(Id2) || + (*it)->getOption().matches(Id3)) { + Res = *it; + break; + } + } + + if (Res) + Res->claim(); + + return Res; +} + bool ArgList::hasFlag(OptSpecifier Pos, OptSpecifier Neg, bool Default) const { if (Arg *A = getLastArg(Pos, Neg)) return A->getOption().matches(Pos); diff --git a/clang/lib/Driver/Tools.cpp b/clang/lib/Driver/Tools.cpp index 9e03a18ae0e..e6465ac72c6 100644 --- a/clang/lib/Driver/Tools.cpp +++ b/clang/lib/Driver/Tools.cpp @@ -2356,8 +2356,15 @@ void darwin::Link::AddLinkArgs(const ArgList &Args, Args.AddAllArgs(CmdArgs, options::OPT_multiply__defined); Args.AddAllArgs(CmdArgs, options::OPT_multiply__defined__unused); - if (Args.hasArg(options::OPT_fpie)) - CmdArgs.push_back("-pie"); + if (const Arg *A = Args.getLastArg(options::OPT_fpie, options::OPT_fPIE, + options::OPT_fno_pie, + options::OPT_fno_PIE)) { + if (A->getOption().matches(options::OPT_fpie) || + A->getOption().matches(options::OPT_fPIE)) + CmdArgs.push_back("-pie"); + else + CmdArgs.push_back("-no_pie"); + } Args.AddLastArg(CmdArgs, options::OPT_prebind); Args.AddLastArg(CmdArgs, options::OPT_noprebind); diff --git a/clang/test/Driver/darwin-ld.c b/clang/test/Driver/darwin-ld.c index 0a898956760..448446885a1 100644 --- a/clang/test/Driver/darwin-ld.c +++ b/clang/test/Driver/darwin-ld.c @@ -70,3 +70,15 @@ // LINK_IPHONE_3_1: ld" // LINK_IPHONE_3_1-NOT: -lbundle1.o // LINK_IPHONE_3_1: -lSystem + +// RUN: %clang -ccc-host-triple i386-apple-darwin9 -### -fpie %t.o 2> %t.log +// RUN: FileCheck -check-prefix=LINK_EXPLICIT_PIE %s < %t.log +// +// LINK_EXPLICIT_PIE: ld" +// LINK_EXPLICIT_PIE: "-pie" + +// RUN: %clang -ccc-host-triple i386-apple-darwin9 -### -fno-pie %t.o 2> %t.log +// RUN: FileCheck -check-prefix=LINK_EXPLICIT_NO_PIE %s < %t.log +// +// LINK_EXPLICIT_NO_PIE: ld" +// LINK_EXPLICIT_NO_PIE: "-no_pie" |