[lld] r249491 - ELF2: Implement OUTPUT() linker script directive.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 6 17:25:09 PDT 2015
Author: ruiu
Date: Tue Oct 6 19:25:09 2015
New Revision: 249491
URL: http://llvm.org/viewvc/llvm-project?rev=249491&view=rev
Log:
ELF2: Implement OUTPUT() linker script directive.
Modified:
lld/trunk/ELF/Config.h
lld/trunk/ELF/Driver.cpp
lld/trunk/ELF/LinkerScript.cpp
lld/trunk/test/elf2/linkerscript.s
Modified: lld/trunk/ELF/Config.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Config.h?rev=249491&r1=249490&r2=249491&view=diff
==============================================================================
--- lld/trunk/ELF/Config.h (original)
+++ lld/trunk/ELF/Config.h Tue Oct 6 19:25:09 2015
@@ -22,7 +22,7 @@ struct Configuration {
llvm::StringRef Entry;
llvm::StringRef Fini = "_fini";
llvm::StringRef Init = "_init";
- llvm::StringRef OutputFile = "a.out";
+ llvm::StringRef OutputFile;
llvm::StringRef SoName;
llvm::StringRef Sysroot;
std::string RPath;
Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=249491&r1=249490&r2=249491&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Tue Oct 6 19:25:09 2015
@@ -167,6 +167,9 @@ void LinkerDriver::link(ArrayRef<const c
for (auto *Arg : Args.filtered(OPT_undefined))
Symtab.addUndefinedSym(Arg->getValue());
+ if (Config->OutputFile.empty())
+ Config->OutputFile = "a.out";
+
// Write the result.
const ELFFileBase *FirstObj = Symtab.getFirstELF();
switch (FirstObj->getELFKind()) {
Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=249491&r1=249490&r2=249491&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Tue Oct 6 19:25:09 2015
@@ -38,6 +38,7 @@ private:
void readAsNeeded();
void readGroup();
+ void readOutput();
void readOutputFormat();
std::vector<StringRef> Tokens;
@@ -50,6 +51,8 @@ void LinkerScript::run() {
StringRef Tok = next();
if (Tok == "GROUP") {
readGroup();
+ } else if (Tok == "OUTPUT") {
+ readOutput();
} else if (Tok == "OUTPUT_FORMAT") {
readOutputFormat();
} else {
@@ -142,6 +145,15 @@ void LinkerScript::readGroup() {
}
}
+void LinkerScript::readOutput() {
+ // -o <file> takes predecence over OUTPUT(<file>).
+ expect("(");
+ StringRef Tok = next();
+ if (Config->OutputFile.empty())
+ Config->OutputFile = Tok;
+ expect(")");
+}
+
void LinkerScript::readOutputFormat() {
// Error checking only for now.
expect("(");
Modified: lld/trunk/test/elf2/linkerscript.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/linkerscript.s?rev=249491&r1=249490&r2=249491&view=diff
==============================================================================
--- lld/trunk/test/elf2/linkerscript.s (original)
+++ lld/trunk/test/elf2/linkerscript.s Tue Oct 6 19:25:09 2015
@@ -18,6 +18,11 @@
# RUN: lld -flavor gnu2 -o %t2 %t.script
# RUN: llvm-readobj %t2 > /dev/null
+# RUN: rm -f %t.out
+# RUN: echo "OUTPUT(" %t.out ")" > %t.script
+# RUN: lld -flavor gnu2 %t.script %t
+# RUN: llvm-readobj %t.out > /dev/null
+
# RUN: echo "FOO(BAR)" > %t.script
# RUN: not lld -flavor gnu2 -o foo %t.script > %t.log 2>&1
# RUN: FileCheck -check-prefix=ERR1 %s < %t.log
More information about the llvm-commits
mailing list