[lld] r232183 - LinkerScript: Add -T <scriptfile> option
Meador Inge
meadori at codesourcery.com
Fri Mar 13 11:15:02 PDT 2015
Author: meadori
Date: Fri Mar 13 13:15:01 2015
New Revision: 232183
URL: http://llvm.org/viewvc/llvm-project?rev=232183&view=rev
Log:
LinkerScript: Add -T <scriptfile> option
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/ld/Options.html#Options
Added:
lld/trunk/test/elf/linkerscript/Inputs/valid.ls
lld/trunk/test/elf/linkerscript/invalid-script-cli-1.test
lld/trunk/test/elf/linkerscript/invalid-script-cli-2.test
lld/trunk/test/elf/linkerscript/valid-script-cli.objtxt
Modified:
lld/trunk/lib/Driver/GnuLdDriver.cpp
lld/trunk/lib/Driver/GnuLdOptions.td
lld/trunk/lib/Driver/TODO.rst
lld/trunk/lib/ReaderWriter/ELF/ELFLinkingContext.cpp
Modified: lld/trunk/lib/Driver/GnuLdDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/GnuLdDriver.cpp?rev=232183&r1=232182&r2=232183&view=diff
==============================================================================
--- lld/trunk/lib/Driver/GnuLdDriver.cpp (original)
+++ lld/trunk/lib/Driver/GnuLdDriver.cpp Fri Mar 13 13:15:01 2015
@@ -659,7 +659,8 @@ bool GnuLdDriver::parse(int argc, const
}
case OPT_INPUT:
- case OPT_l: {
+ case OPT_l:
+ case OPT_T: {
bool dashL = (arg->getOption().getID() == OPT_l);
StringRef path = arg->getValue();
Modified: lld/trunk/lib/Driver/GnuLdOptions.td
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/GnuLdOptions.td?rev=232183&r1=232182&r2=232183&view=diff
==============================================================================
--- lld/trunk/lib/Driver/GnuLdOptions.td (original)
+++ lld/trunk/lib/Driver/GnuLdOptions.td Fri Mar 13 13:15:01 2015
@@ -253,6 +253,16 @@ defm wrap : smDash<"wrap", "wrap",
" 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
//===----------------------------------------------------------------------===//
Modified: lld/trunk/lib/Driver/TODO.rst
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/TODO.rst?rev=232183&r1=232182&r2=232183&view=diff
==============================================================================
--- lld/trunk/lib/Driver/TODO.rst (original)
+++ lld/trunk/lib/Driver/TODO.rst Fri Mar 13 13:15:01 2015
@@ -31,7 +31,6 @@ Missing Options
* -s,--strip-all
* -S,--strip-debug
* --trace
-* -T,--script
* -dT,--default-script
* -Ur
* --unique
Modified: lld/trunk/lib/ReaderWriter/ELF/ELFLinkingContext.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/ELFLinkingContext.cpp?rev=232183&r1=232182&r2=232183&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/ELFLinkingContext.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/ELFLinkingContext.cpp Fri Mar 13 13:15:01 2015
@@ -145,10 +145,10 @@ ErrorOr<StringRef> ELFLinkingContext::se
if (llvm::sys::fs::exists(path.str()))
return StringRef(*new (_allocator) std::string(path.str()));
}
- if (!llvm::sys::fs::exists(libName))
- return make_error_code(llvm::errc::no_such_file_or_directory);
+ if (hasColonPrefix && llvm::sys::fs::exists(libName.drop_front()))
+ return libName.drop_front();
- return libName;
+ return make_error_code(llvm::errc::no_such_file_or_directory);
}
ErrorOr<StringRef> ELFLinkingContext::searchFile(StringRef fileName,
Added: lld/trunk/test/elf/linkerscript/Inputs/valid.ls
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/linkerscript/Inputs/valid.ls?rev=232183&view=auto
==============================================================================
--- lld/trunk/test/elf/linkerscript/Inputs/valid.ls (added)
+++ lld/trunk/test/elf/linkerscript/Inputs/valid.ls Fri Mar 13 13:15:01 2015
@@ -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)
Added: lld/trunk/test/elf/linkerscript/invalid-script-cli-1.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/linkerscript/invalid-script-cli-1.test?rev=232183&view=auto
==============================================================================
--- lld/trunk/test/elf/linkerscript/invalid-script-cli-1.test (added)
+++ lld/trunk/test/elf/linkerscript/invalid-script-cli-1.test Fri Mar 13 13:15:01 2015
@@ -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
Added: lld/trunk/test/elf/linkerscript/invalid-script-cli-2.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/linkerscript/invalid-script-cli-2.test?rev=232183&view=auto
==============================================================================
--- lld/trunk/test/elf/linkerscript/invalid-script-cli-2.test (added)
+++ lld/trunk/test/elf/linkerscript/invalid-script-cli-2.test Fri Mar 13 13:15:01 2015
@@ -0,0 +1,6 @@
+# Check that linker script are *not* picked up with -lscript.ls.
+
+RUN: not lld -flavor gnu -target x86_64 -L%p/Inputs/ -lvalid.ls 2> %t.err
+RUN: FileCheck %s < %t.err
+
+CHECK: {{.*}}: Unable to find library -lvalid.ls
Added: lld/trunk/test/elf/linkerscript/valid-script-cli.objtxt
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/linkerscript/valid-script-cli.objtxt?rev=232183&view=auto
==============================================================================
--- lld/trunk/test/elf/linkerscript/valid-script-cli.objtxt (added)
+++ lld/trunk/test/elf/linkerscript/valid-script-cli.objtxt Fri Mar 13 13:15:01 2015
@@ -0,0 +1,23 @@
+# Check that the linker script inputs are accepted properly.
+
+# 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
+
+# RUN: lld -flavor gnu -target x86_64 -L%p/Inputs/ -l: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
More information about the llvm-commits
mailing list