From 73c532e8a916e0c281c8520c6845183d454add8f Mon Sep 17 00:00:00 2001 From: Tim Northover Date: Thu, 10 Jul 2014 11:46:13 +0000 Subject: [PATCH] [mach-o]: support -Z option to skip standard library paths llvm-svn: 212713 --- lld/lib/Driver/DarwinLdDriver.cpp | 7 +++++-- lld/lib/Driver/DarwinLdOptions.td | 2 ++ lld/test/mach-o/libresolve-z.yaml | 21 +++++++++++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 lld/test/mach-o/libresolve-z.yaml diff --git a/lld/lib/Driver/DarwinLdDriver.cpp b/lld/lib/Driver/DarwinLdDriver.cpp index 34eca5d..27946a7 100644 --- a/lld/lib/Driver/DarwinLdDriver.cpp +++ b/lld/lib/Driver/DarwinLdDriver.cpp @@ -302,8 +302,11 @@ bool DarwinLdDriver::parse(int argc, const char *argv[], ctx.addModifiedSearchDir(libPath->getValue(), syslibRoots, false); } - ctx.addModifiedSearchDir("/usr/lib", syslibRoots, true); - ctx.addModifiedSearchDir("/usr/local/lib", syslibRoots, true); + // -Z suppresses the standard search paths. + if (!parsedArgs->hasArg(OPT_Z)) { + ctx.addModifiedSearchDir("/usr/lib", syslibRoots, true); + ctx.addModifiedSearchDir("/usr/local/lib", syslibRoots, true); + } // Now that we've constructed the final set of search paths, print out what // we'll be using for testing purposes. diff --git a/lld/lib/Driver/DarwinLdOptions.td b/lld/lib/Driver/DarwinLdOptions.td index a7dd40a..7aa6777 100644 --- a/lld/lib/Driver/DarwinLdOptions.td +++ b/lld/lib/Driver/DarwinLdOptions.td @@ -66,6 +66,8 @@ def bundle_loader : Separate<["-"], "bundle_loader">, def grp_libs : OptionGroup<"libs">, HelpText<"LIBRARY OPTIONS">; def L : JoinedOrSeparate<["-"], "L">, HelpText<"Add directory to library search path">, Group; +def Z : Flag<["-"], "Z">, + HelpText<"Do not search standard directories for libraries or frameworks">; def all_load : Flag<["-"], "all_load">, HelpText<"Forces all members of all static libraries to be loaded">, Group; diff --git a/lld/test/mach-o/libresolve-z.yaml b/lld/test/mach-o/libresolve-z.yaml new file mode 100644 index 0000000..8edc28d --- /dev/null +++ b/lld/test/mach-o/libresolve-z.yaml @@ -0,0 +1,21 @@ +# RUN: lld -flavor darwin -arch x86_64 -r -test_libresolution \ +# RUN: -path_exists /usr/lib \ +# RUN: -path_exists /usr/local/lib \ +# RUN: -path_exists /usr/lib/libSystem.dylib \ +# RUN: -path_exists hasFoo \ +# RUN: -path_exists hasFoo/libFoo.dylib \ +# RUN: -path_exists /hasBar \ +# RUN: -path_exists /hasBar/libBar.dylib \ +# RUN: -L hasFoo \ +# RUN: -L /hasBar \ +# RUN: -Z \ +# RUN: -lFoo -lBar \ +# RUN: 2>&1 | FileCheck %s + +# CHECK: Library search paths: +# CHECK: hasFoo +# CHECK: /hasBar +# CHECK-NOT: /usr/lib +# CHECK-NOT: /usr/local/lib +# CHECK: Found library hasFoo/libFoo.dylib +# CHECK: Found library /hasBar/libBar.dylib -- 2.7.4