[PATCH] LinkerScript: Add -T <scriptfile> option
Meador Inge
meadori at gmail.com
Sat Mar 7 10:59:55 PST 2015
GNU LD has an option named -T/--script which allows a user to specify
a linker script to be used [1]. LLD already accepts linker scripts
without this option, but the option is widely used. Therefore it is
best to support it in LLD as well.
[1] https://sourceware.org/binutils/docs-2.25/ld/Options.html#Options
http://reviews.llvm.org/D8138
Files:
lib/Driver/GnuLdDriver.cpp
lib/Driver/GnuLdOptions.td
lib/Driver/TODO.rst
test/elf/linkerscript/Inputs/valid.ls
test/elf/linkerscript/invalid-T-option.test
test/elf/linkerscript/valid-T-option.objtxt
Index: lib/Driver/GnuLdDriver.cpp
===================================================================
--- lib/Driver/GnuLdDriver.cpp
+++ lib/Driver/GnuLdDriver.cpp
@@ -654,7 +654,8 @@
}
case OPT_INPUT:
- case OPT_l: {
+ case OPT_l:
+ case OPT_T: {
bool dashL = (arg->getOption().getID() == OPT_l);
StringRef path = arg->getValue();
Index: lib/Driver/GnuLdOptions.td
===================================================================
--- lib/Driver/GnuLdOptions.td
+++ lib/Driver/GnuLdOptions.td
@@ -253,6 +253,16 @@
" will be resolved to symbol.">,
MetaVarName<"<symbol>">,
Group<grp_symbolopts>;
+
+//===----------------------------------------------------------------------===//
+/// Script Options
+//===----------------------------------------------------------------------===//
+def grp_scriptopts : OptionGroup<"opts">,
+ HelpText<"SCRIPT OPTIONS">;
+defm T : smDash<"T", "script",
+ "Use the given linker script in place of the default script.">,
+ Group<grp_scriptopts>;
+
//===----------------------------------------------------------------------===//
/// Optimization Options
//===----------------------------------------------------------------------===//
Index: lib/Driver/TODO.rst
===================================================================
--- lib/Driver/TODO.rst
+++ lib/Driver/TODO.rst
@@ -31,7 +31,6 @@
* -s,--strip-all
* -S,--strip-debug
* --trace
-* -T,--script
* -dT,--default-script
* -Ur
* --unique
Index: test/elf/linkerscript/Inputs/valid.ls
===================================================================
--- /dev/null
+++ test/elf/linkerscript/Inputs/valid.ls
@@ -0,0 +1,6 @@
+/* A simple valid linker script used for testing the -T/--script options.
+ *
+ * An unresolved symbol named '_entry_point' can be scanned for by the tests
+ * to determine that the linker script was processed.
+ */
+ENTRY(_entry_point)
Index: test/elf/linkerscript/invalid-T-option.test
===================================================================
--- /dev/null
+++ test/elf/linkerscript/invalid-T-option.test
@@ -0,0 +1,10 @@
+# Check that the -T/--script options issue an error when passed
+# filenames for files that do not exist.
+
+RUN: not lld -flavor gnu -target x86_64 -T idonotexist.ls 2> %t.err
+RUN: FileCheck %s < %t.err
+
+RUN: not lld -flavor gnu -target x86_64 --script=idonotexist.ls 2> %t.err
+RUN: FileCheck %s < %t.err
+
+CHECK: {{.*}}lld: cannot find file {{.*}}idonotexist.ls
Index: test/elf/linkerscript/valid-T-option.objtxt
===================================================================
--- /dev/null
+++ test/elf/linkerscript/valid-T-option.objtxt
@@ -0,0 +1,20 @@
+# Check that the -T/--script options are accepted.
+
+# RUN: lld -flavor gnu -target x86_64 %p/Inputs/valid.ls -r %s \
+# RUN: --output-filetype=yaml | FileCheck %s
+
+# RUN: lld -flavor gnu -target x86_64 -T %p/Inputs/valid.ls -r %s \
+# RUN: --output-filetype=yaml | FileCheck %s
+
+# RUN: lld -flavor gnu -target x86_64 --script=%p/Inputs/valid.ls -r %s \
+# RUN: --output-filetype=yaml | FileCheck %s
+
+defined-atoms:
+ - name: main
+ scope: global
+ content: [ B8, 00, 00, 00, 00, C7, 44, 24, FC, 00, 00, 00, 00, C3 ]
+ alignment: 2^4
+ section-choice: custom-required
+ section-name: .text
+
+# CHECK: _entry_point
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D8138.21424.patch
Type: text/x-patch
Size: 3409 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150307/cdbde9be/attachment.bin>
More information about the llvm-commits
mailing list