diff options
author | Denis Protivensky <dprotivensky@accesssoftek.com> | 2015-11-12 09:52:08 +0000 |
---|---|---|
committer | Denis Protivensky <dprotivensky@accesssoftek.com> | 2015-11-12 09:52:08 +0000 |
commit | 8e3b38aba16c286d0cfa9e7b544438bea6acb83b (patch) | |
tree | f358426f134d7f49be66597bbef59ed62aa116d1 /lld/ELF/LinkerScript.cpp | |
parent | de8332257b9c170c5ca5ed5063e43278bf86d2dd (diff) | |
download | bcm5719-llvm-8e3b38aba16c286d0cfa9e7b544438bea6acb83b.tar.gz bcm5719-llvm-8e3b38aba16c286d0cfa9e7b544438bea6acb83b.zip |
[ELF2] SECTIONS command basic support
* determine output section by input section name
* discard input sections
* order output sections accordingly
Differential Revision: http://reviews.llvm.org/D14140
llvm-svn: 252868
Diffstat (limited to 'lld/ELF/LinkerScript.cpp')
-rw-r--r-- | lld/ELF/LinkerScript.cpp | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp index 1607247aa98..03c5fc4fca7 100644 --- a/lld/ELF/LinkerScript.cpp +++ b/lld/ELF/LinkerScript.cpp @@ -36,6 +36,7 @@ private: static std::vector<StringRef> tokenize(StringRef S); static StringRef skipSpace(StringRef S); StringRef next(); + bool skip(StringRef Tok); bool atEOF() { return Tokens.size() == Pos; } void expect(StringRef Expect); @@ -50,6 +51,9 @@ private: void readOutputArch(); void readOutputFormat(); void readSearchDir(); + void readSections(); + + void readOutputSectionDescription(); StringSaver Saver; std::vector<StringRef> Tokens; @@ -78,6 +82,8 @@ void LinkerScript::run() { readOutputFormat(); } else if (Tok == "SEARCH_DIR") { readSearchDir(); + } else if (Tok == "SECTIONS") { + readSections(); } else { error("unknown directive: " + Tok); } @@ -133,11 +139,20 @@ StringRef LinkerScript::skipSpace(StringRef S) { } StringRef LinkerScript::next() { - if (Pos == Tokens.size()) + if (atEOF()) error("unexpected EOF"); return Tokens[Pos++]; } +bool LinkerScript::skip(StringRef Tok) { + if (atEOF()) + error("unexpected EOF"); + if (Tok != Tokens[Pos]) + return false; + ++Pos; + return true; +} + void LinkerScript::expect(StringRef Expect) { StringRef Tok = next(); if (Tok != Expect) @@ -255,6 +270,26 @@ void LinkerScript::readSearchDir() { expect(")"); } +void LinkerScript::readSections() { + expect("{"); + while (!skip("}")) + readOutputSectionDescription(); +} + +void LinkerScript::readOutputSectionDescription() { + StringRef Name = next(); + std::vector<StringRef> &InputSections = Config->OutputSections[Name]; + + expect(":"); + expect("{"); + while (!skip("}")) { + next(); // Skip input file name. + expect("("); + while (!skip(")")) + InputSections.push_back(next()); + } +} + // Entry point. The other functions or classes are private to this file. void lld::elf2::readLinkerScript(BumpPtrAllocator *A, MemoryBufferRef MB) { LinkerScript(A, MB.getBuffer()).run(); |