[mach-o] Add support for -force_load option

The darwin linker has two ways to force all members of an archive to be loaded.
The -all_load option applies to all static libraries.  The -force_load takes
a path to a library and just that library's members are force loaded.

llvm-svn: 221477
This commit is contained in:
Nick Kledzik 2014-11-06 19:33:57 +00:00
parent 4c508df925
commit 24f504001d
3 changed files with 45 additions and 0 deletions

View File

@ -658,6 +658,9 @@ bool DarwinLdDriver::parse(int argc, const char *argv[],
case OPT_upward_library:
addFile(arg->getValue(), inputGraph, ctx, false, true);
break;
case OPT_force_load:
addFile(arg->getValue(), inputGraph, ctx, true, false);
break;
case OPT_l:
case OPT_upward_l:
upward = (arg->getOption().getID() == OPT_upward_l);

View File

@ -107,6 +107,10 @@ def Z : Flag<["-"], "Z">,
def all_load : Flag<["-"], "all_load">,
HelpText<"Forces all members of all static libraries to be loaded">,
Group<grp_libs>;
def force_load : Separate<["-"], "force_load">,
MetaVarName<"<library-path>">,
HelpText<"Forces all members of specified static libraries to be loaded">,
Group<grp_libs>;
def syslibroot : Separate<["-"], "syslibroot">, MetaVarName<"<dir>">,
HelpText<"Add path to SDK to all absolute library search paths">,
Group<grp_libs>;

View File

@ -0,0 +1,38 @@
# RUN: lld -flavor darwin -arch x86_64 %s %p/Inputs/libSystem.yaml \
# RUN: %p/Inputs/libfoo.a %p/Inputs/libbar.a -o %t1
# RUN: llvm-nm -m -n %t1 | FileCheck %s
#
# RUN: lld -flavor darwin -arch x86_64 %s %p/Inputs/libSystem.yaml \
# RUN: -force_load %p/Inputs/libfoo.a %p/Inputs/libbar.a -o %t2
# RUN: llvm-nm -m -n %t2 | FileCheck --check-prefix=CHECKF %s
#
# Test that -force_load causes members of static library to be loaded.
#
--- !mach-o
arch: x86_64
file-type: MH_OBJECT
flags: [ MH_SUBSECTIONS_VIA_SYMBOLS ]
has-UUID: false
OS: unknown
sections:
- segment: __TEXT
section: __text
type: S_REGULAR
attributes: [ S_ATTR_PURE_INSTRUCTIONS, S_ATTR_SOME_INSTRUCTIONS ]
address: 0x0000000000000000
content: [ 0xC3 ]
global-symbols:
- name: _main
type: N_SECT
scope: [ N_EXT ]
sect: 1
value: 0x0000000000000000
...
# CHECK: {{[0-9a-f]+}} (__TEXT,__text) external _main
# CHECK-NOT: {{[0-9a-f]+}} (__TEXT,__text) external _main
# CHECKF: {{[0-9a-f]+}} (__TEXT,__text) external _main
# CHECKF: {{[0-9a-f]+}} (__TEXT,__text) external _foo
# CHECKF-NOT: {{[0-9a-f]+}} (__TEXT,__text) external _bar