ELF2: Implement OUTPUT() linker script directive.

llvm-svn: 249491
This commit is contained in:
Rui Ueyama 2015-10-07 00:25:09 +00:00
parent f1f36517b7
commit ee59282bfd
4 changed files with 21 additions and 1 deletions

View File

@ -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;

View File

@ -167,6 +167,9 @@ void LinkerDriver::link(ArrayRef<const char *> ArgsArr) {
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()) {

View File

@ -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("(");

View File

@ -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