[lld] r232111 - LinkerScript: Add evaluation of the EXTERN command
Meador Inge
meadori at codesourcery.com
Thu Mar 12 14:55:55 PDT 2015
Author: meadori
Date: Thu Mar 12 16:55:55 2015
New Revision: 232111
URL: http://llvm.org/viewvc/llvm-project?rev=232111&view=rev
Log:
LinkerScript: Add evaluation of the EXTERN command
This patch implements evaluation of the GNU ld EXTERN command.
Added:
lld/trunk/test/elf/linkerscript/Inputs/externs.ls
lld/trunk/test/elf/linkerscript/externs.objtxt
Modified:
lld/trunk/include/lld/ReaderWriter/LinkerScript.h
lld/trunk/lib/Driver/GnuLdDriver.cpp
Modified: lld/trunk/include/lld/ReaderWriter/LinkerScript.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/ReaderWriter/LinkerScript.h?rev=232111&r1=232110&r2=232111&view=diff
==============================================================================
--- lld/trunk/include/lld/ReaderWriter/LinkerScript.h (original)
+++ lld/trunk/include/lld/ReaderWriter/LinkerScript.h Thu Mar 12 16:55:55 2015
@@ -846,6 +846,8 @@ private:
/// Represents an extern command.
class Extern : public Command {
public:
+ typedef llvm::ArrayRef<StringRef>::const_iterator const_iterator;
+
Extern(Parser &ctx,
const SmallVectorImpl<StringRef> &symbols)
: Command(ctx, Kind::Extern) {
@@ -861,6 +863,8 @@ public:
}
void dump(raw_ostream &os) const override;
+ const_iterator begin() const { return _symbols.begin(); }
+ const_iterator end() const { return _symbols.end(); }
private:
llvm::ArrayRef<StringRef> _symbols;
Modified: lld/trunk/lib/Driver/GnuLdDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/GnuLdDriver.cpp?rev=232111&r1=232110&r2=232111&view=diff
==============================================================================
--- lld/trunk/lib/Driver/GnuLdDriver.cpp (original)
+++ lld/trunk/lib/Driver/GnuLdDriver.cpp Thu Mar 12 16:55:55 2015
@@ -308,6 +308,11 @@ std::error_code GnuLdDriver::evalLinkerS
ctx.setEntrySymbolName(entry->getEntryName());
if (auto *output = dyn_cast<script::Output>(c))
ctx.setOutputPath(output->getOutputFileName());
+ if (auto *externs = dyn_cast<script::Extern>(c)) {
+ for (auto symbol : *externs) {
+ ctx.addInitialUndefinedSymbol(symbol);
+ }
+ }
}
// Transfer ownership of the script to the linking context
ctx.addLinkerScript(std::move(parser));
Added: lld/trunk/test/elf/linkerscript/Inputs/externs.ls
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/linkerscript/Inputs/externs.ls?rev=232111&view=auto
==============================================================================
--- lld/trunk/test/elf/linkerscript/Inputs/externs.ls (added)
+++ lld/trunk/test/elf/linkerscript/Inputs/externs.ls Thu Mar 12 16:55:55 2015
@@ -0,0 +1,3 @@
+/* A simple valid linker script used for testing the EXTERN command.
+ */
+EXTERN(_foo bar __baz)
Added: lld/trunk/test/elf/linkerscript/externs.objtxt
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/linkerscript/externs.objtxt?rev=232111&view=auto
==============================================================================
--- lld/trunk/test/elf/linkerscript/externs.objtxt (added)
+++ lld/trunk/test/elf/linkerscript/externs.objtxt Thu Mar 12 16:55:55 2015
@@ -0,0 +1,21 @@
+# Check symbols defined with the EXTERN command are added as undefined
+# symbols.
+
+# RUN: lld -flavor gnu -target x86_64 -T %p/Inputs/externs.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: undefined-atoms:
+# CHECK: - name: _foo
+# CHECK: can-be-null: at-buildtime
+# CHECK: - name: bar
+# CHECK: can-be-null: at-buildtime
+# CHECK: - name: __baz
+# CHECK: can-be-null: at-buildtime
More information about the llvm-commits
mailing list