[lld] r249960 - ELF2: LinkerScript: Implement INCLUDE directive.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Sat Oct 10 18:31:55 PDT 2015
Author: ruiu
Date: Sat Oct 10 20:31:55 2015
New Revision: 249960
URL: http://llvm.org/viewvc/llvm-project?rev=249960&view=rev
Log:
ELF2: LinkerScript: Implement INCLUDE directive.
Modified:
lld/trunk/ELF/LinkerScript.cpp
lld/trunk/test/elf2/linkerscript.s
Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=249960&r1=249959&r2=249960&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Sat Oct 10 20:31:55 2015
@@ -39,12 +39,14 @@ private:
void readAsNeeded();
void readEntry();
void readGroup();
+ void readInclude();
void readOutput();
void readOutputFormat();
void readSearchDir();
std::vector<StringRef> Tokens;
size_t Pos = 0;
+ static std::vector<std::unique_ptr<MemoryBuffer>> OwningMBs;
};
}
@@ -55,6 +57,8 @@ void LinkerScript::run() {
readEntry();
} else if (Tok == "GROUP") {
readGroup();
+ } else if (Tok == "INCLUDE") {
+ readInclude();
} else if (Tok == "OUTPUT") {
readOutput();
} else if (Tok == "OUTPUT_FORMAT") {
@@ -160,6 +164,16 @@ void LinkerScript::readGroup() {
}
}
+void LinkerScript::readInclude() {
+ StringRef Tok = next();
+ auto MBOrErr = MemoryBuffer::getFile(Tok);
+ error(MBOrErr, Twine("cannot open ") + Tok);
+ std::unique_ptr<MemoryBuffer> &MB = *MBOrErr;
+ std::vector<StringRef> V = tokenize(MB->getMemBufferRef().getBuffer());
+ Tokens.insert(Tokens.begin() + Pos, V.begin(), V.end());
+ OwningMBs.push_back(std::move(MB)); // keep ownership of MB
+}
+
void LinkerScript::readOutput() {
// -o <file> takes predecence over OUTPUT(<file>).
expect("(");
@@ -182,6 +196,8 @@ void LinkerScript::readSearchDir() {
expect(")");
}
+std::vector<std::unique_ptr<MemoryBuffer>> LinkerScript::OwningMBs;
+
// Entry point. The other functions or classes are private to this file.
void lld::elf2::readLinkerScript(MemoryBufferRef MB) {
LinkerScript(MB.getBuffer()).run();
Modified: lld/trunk/test/elf2/linkerscript.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/linkerscript.s?rev=249960&r1=249959&r2=249960&view=diff
==============================================================================
--- lld/trunk/test/elf2/linkerscript.s (original)
+++ lld/trunk/test/elf2/linkerscript.s Sat Oct 10 20:31:55 2015
@@ -47,6 +47,11 @@
# RUN: ld.lld2 %t.script %t
# RUN: llvm-readobj %t.out > /dev/null
+# RUN: echo "INCLUDE " %t.script2 "OUTPUT(" %t.out ")" > %t.script1
+# RUN: echo "GROUP(" %t ")" > %t.script2
+# RUN: ld.lld2 %t.script1
+# RUN: llvm-readobj %t2 > /dev/null
+
# RUN: echo "FOO(BAR)" > %t.script
# RUN: not ld.lld2 -o foo %t.script > %t.log 2>&1
# RUN: FileCheck -check-prefix=ERR1 %s < %t.log
More information about the llvm-commits
mailing list