[mach-o]: support user-specified (-L) library search paths

llvm-svn: 212712
This commit is contained in:
Tim Northover 2014-07-10 11:46:08 +00:00
parent 02bb0ec368
commit 18af0573df
5 changed files with 45 additions and 5 deletions

View File

@ -296,8 +296,12 @@ bool DarwinLdDriver::parse(int argc, const char *argv[],
syslibRoots.push_back(syslibRoot->getValue());
}
// FIXME: handle -L options: these get added *before* the default paths,
// possibly modified by any syslibroot options.
// Paths specified with -L come first, and are not considered system paths for
// the case where there is precisely 1 -syslibroot.
for (auto libPath : parsedArgs->filtered(OPT_L)) {
ctx.addModifiedSearchDir(libPath->getValue(), syslibRoots, false);
}
ctx.addModifiedSearchDir("/usr/lib", syslibRoots, true);
ctx.addModifiedSearchDir("/usr/local/lib", syslibRoots, true);

View File

@ -64,7 +64,7 @@ def bundle_loader : Separate<["-"], "bundle_loader">,
// library options
def grp_libs : OptionGroup<"libs">, HelpText<"LIBRARY OPTIONS">;
def L : Joined<["-"], "L">,
def L : JoinedOrSeparate<["-"], "L">,
HelpText<"Add directory to library search path">, Group<grp_libs>;
def all_load : Flag<["-"], "all_load">,
HelpText<"Forces all members of all static libraries to be loaded">,

View File

@ -2,8 +2,11 @@
# RUN: -path_exists /usr/lib \
# RUN: -path_exists /Applications/MySDK/usr/local/lib \
# RUN: -path_exists /Applications/MySDK/usr/local/lib/libSystem.a \
# RUN: -path_exists /hasFoo \
# RUN: -path_exists /hasFoo/foo.o \
# RUN: -syslibroot /Applications/MySDK \
# RUN: -lSystem \
# RUN: -L/hasFoo \
# RUN: -lSystem -lfoo.o \
# RUN: 2>&1 | FileCheck %s
# When just one -syslibroot is specified, we apparently want to skip *system*
@ -12,8 +15,11 @@
# no mention of /usr/lib.
# CHECK: Library search paths:
# CHECK: /hasFoo
# CHECK-NOT: /usr/lib
# CHECK-NOT: /usr/local/lib
# CHECK: /Applications/MySDK/usr/local/lib
# CHECK-NOT: /usr/lib
# CHECK-NOT: /usr/local/lib
# CHECK: Found library /Applications/MySDK/usr/local/lib/libSystem.a
# CHECK: Found library /hasFoo/foo.o

View File

@ -2,10 +2,20 @@
# RUN: -path_exists /usr/lib \
# RUN: -path_exists /usr/local/lib \
# RUN: -path_exists /usr/lib/libSystem.dylib \
# RUN: -lSystem \
# 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: -lSystem -lFoo -lBar \
# RUN: 2>&1 | FileCheck %s
# CHECK: Library search paths:
# CHECK: hasFoo
# CHECK: /hasBar
# CHECK: /usr/lib
# CHECK: /usr/local/lib
# CHECK: Found library /usr/lib/libSystem.dylib
# CHECK: Found library hasFoo/libFoo.dylib
# CHECK: Found library /hasBar/libBar.dylib

View File

@ -0,0 +1,20 @@
# RUN: lld -flavor darwin -arch x86_64 -r -test_libresolution \
# RUN: -path_exists hasFoo \
# RUN: -path_exists hasFoo/libFoo.dylib \
# RUN: -path_exists /hasBar \
# RUN: -path_exists /hasBar/libBar.dylib \
# RUN: -path_exists /SDK/hasFoo \
# RUN: -path_exists /SDK/hasFoo/libFoo.dylib \
# RUN: -path_exists /SDK/hasBar \
# RUN: -path_exists /SDK/hasBar/libBar.dylib \
# RUN: -syslibroot /SDK \
# RUN: -L hasFoo \
# RUN: -L /hasBar \
# RUN: -lFoo -lBar \
# RUN: 2>&1 | FileCheck %s
# CHECK: Library search paths:
# CHECK: hasFoo
# CHECK: /SDK/hasBar
# CHECK: Found library hasFoo/libFoo.dylib
# CHECK: Found library /SDK/hasBar/libBar.dylib