diff --git a/lld/lib/Driver/DarwinLdDriver.cpp b/lld/lib/Driver/DarwinLdDriver.cpp index 645a3efb6502..723b65093952 100644 --- a/lld/lib/Driver/DarwinLdDriver.cpp +++ b/lld/lib/Driver/DarwinLdDriver.cpp @@ -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); diff --git a/lld/lib/Driver/DarwinLdOptions.td b/lld/lib/Driver/DarwinLdOptions.td index d819c03aac0e..eefb2c7b92d2 100644 --- a/lld/lib/Driver/DarwinLdOptions.td +++ b/lld/lib/Driver/DarwinLdOptions.td @@ -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; +def force_load : Separate<["-"], "force_load">, + MetaVarName<"">, + HelpText<"Forces all members of specified static libraries to be loaded">, + Group; def syslibroot : Separate<["-"], "syslibroot">, MetaVarName<"">, HelpText<"Add path to SDK to all absolute library search paths">, Group; diff --git a/lld/test/mach-o/force_load-x86_64.yaml b/lld/test/mach-o/force_load-x86_64.yaml new file mode 100644 index 000000000000..35905effd2c4 --- /dev/null +++ b/lld/test/mach-o/force_load-x86_64.yaml @@ -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