[lld] r221477 - [mach-o] Add support for -force_load option
Nick Kledzik
kledzik at apple.com
Thu Nov 6 11:33:57 PST 2014
Author: kledzik
Date: Thu Nov 6 13:33:57 2014
New Revision: 221477
URL: http://llvm.org/viewvc/llvm-project?rev=221477&view=rev
Log:
[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.
Added:
lld/trunk/test/mach-o/force_load-x86_64.yaml
Modified:
lld/trunk/lib/Driver/DarwinLdDriver.cpp
lld/trunk/lib/Driver/DarwinLdOptions.td
Modified: lld/trunk/lib/Driver/DarwinLdDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/DarwinLdDriver.cpp?rev=221477&r1=221476&r2=221477&view=diff
==============================================================================
--- lld/trunk/lib/Driver/DarwinLdDriver.cpp (original)
+++ lld/trunk/lib/Driver/DarwinLdDriver.cpp Thu Nov 6 13:33:57 2014
@@ -658,6 +658,9 @@ bool DarwinLdDriver::parse(int argc, con
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);
Modified: lld/trunk/lib/Driver/DarwinLdOptions.td
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/DarwinLdOptions.td?rev=221477&r1=221476&r2=221477&view=diff
==============================================================================
--- lld/trunk/lib/Driver/DarwinLdOptions.td (original)
+++ lld/trunk/lib/Driver/DarwinLdOptions.td Thu Nov 6 13:33:57 2014
@@ -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>;
Added: lld/trunk/test/mach-o/force_load-x86_64.yaml
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/mach-o/force_load-x86_64.yaml?rev=221477&view=auto
==============================================================================
--- lld/trunk/test/mach-o/force_load-x86_64.yaml (added)
+++ lld/trunk/test/mach-o/force_load-x86_64.yaml Thu Nov 6 13:33:57 2014
@@ -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
More information about the llvm-commits
mailing list