[PATCH] LinkerScript: Add evaluation of the EXTERN command
Meador Inge
meadori at gmail.com
Wed Mar 11 15:16:34 PDT 2015
This patch implements evaluation of the GNU ld EXTERN command.
The parsing part was submitted in D8271.
http://reviews.llvm.org/D8272
Files:
include/lld/ReaderWriter/LinkerScript.h
lib/Driver/GnuLdDriver.cpp
test/elf/linkerscript/Inputs/externs.ls
test/elf/linkerscript/externs.objtxt
Index: include/lld/ReaderWriter/LinkerScript.h
===================================================================
--- include/lld/ReaderWriter/LinkerScript.h
+++ include/lld/ReaderWriter/LinkerScript.h
@@ -846,6 +846,8 @@
/// 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 @@
}
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;
Index: lib/Driver/GnuLdDriver.cpp
===================================================================
--- lib/Driver/GnuLdDriver.cpp
+++ lib/Driver/GnuLdDriver.cpp
@@ -308,6 +308,11 @@
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));
Index: test/elf/linkerscript/Inputs/externs.ls
===================================================================
--- /dev/null
+++ test/elf/linkerscript/Inputs/externs.ls
@@ -0,0 +1,3 @@
+/* A simple valid linker script used for testing the EXTERN command.
+ */
+EXTERN(_foo bar __baz)
Index: test/elf/linkerscript/externs.objtxt
===================================================================
--- /dev/null
+++ test/elf/linkerscript/externs.objtxt
@@ -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
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D8272.21778.patch
Type: text/x-patch
Size: 2537 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150311/4a21ae81/attachment.bin>
More information about the llvm-commits
mailing list