summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lld/ELF/Driver.cpp2
-rw-r--r--lld/ELF/Driver.h3
-rw-r--r--lld/ELF/LinkerScript.cpp16
3 files changed, 11 insertions, 10 deletions
diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp
index 74c6ecf0f0e..7c1509303b2 100644
--- a/lld/ELF/Driver.cpp
+++ b/lld/ELF/Driver.cpp
@@ -136,7 +136,7 @@ void LinkerDriver::addFile(StringRef Path) {
switch (identify_magic(MBRef.getBuffer())) {
case file_magic::unknown:
- readLinkerScript(MBRef);
+ readLinkerScript(&Alloc, MBRef);
return;
case file_magic::archive:
if (WholeArchive) {
diff --git a/lld/ELF/Driver.h b/lld/ELF/Driver.h
index c961c82fd28..91169d5356a 100644
--- a/lld/ELF/Driver.h
+++ b/lld/ELF/Driver.h
@@ -44,6 +44,7 @@ private:
template <template <class> class T>
std::unique_ptr<ELFFileBase> createELFInputFile(MemoryBufferRef MB);
+ llvm::BumpPtrAllocator Alloc;
ArgParser Parser;
bool WholeArchive = false;
std::vector<std::unique_ptr<InputFile>> Files;
@@ -60,7 +61,7 @@ enum {
};
// Parses a linker script. Calling this function updates the Symtab and Config.
-void readLinkerScript(MemoryBufferRef MB);
+void readLinkerScript(llvm::BumpPtrAllocator *A, MemoryBufferRef MB);
} // namespace elf2
} // namespace lld
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp
index e29c717d43e..9162a44cadc 100644
--- a/lld/ELF/LinkerScript.cpp
+++ b/lld/ELF/LinkerScript.cpp
@@ -18,6 +18,7 @@
#include "SymbolTable.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/StringSaver.h"
using namespace llvm;
using namespace lld;
@@ -26,7 +27,8 @@ using namespace lld::elf2;
namespace {
class LinkerScript {
public:
- LinkerScript(StringRef S) : Tokens(tokenize(S)) {}
+ LinkerScript(BumpPtrAllocator *A, StringRef S)
+ : Saver(*A), Tokens(tokenize(S)) {}
void run();
private:
@@ -44,9 +46,9 @@ private:
void readOutputFormat();
void readSearchDir();
+ StringSaver Saver;
std::vector<StringRef> Tokens;
size_t Pos = 0;
- static std::vector<std::unique_ptr<MemoryBuffer>> OwningMBs;
};
}
@@ -169,9 +171,9 @@ void LinkerScript::readInclude() {
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());
+ StringRef S = Saver.save(MB->getMemBufferRef().getBuffer());
+ std::vector<StringRef> V = tokenize(S);
Tokens.insert(Tokens.begin() + Pos, V.begin(), V.end());
- OwningMBs.push_back(std::move(MB)); // keep ownership of MB
}
void LinkerScript::readOutput() {
@@ -196,9 +198,7 @@ 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();
+void lld::elf2::readLinkerScript(BumpPtrAllocator *A, MemoryBufferRef MB) {
+ LinkerScript(A, MB.getBuffer()).run();
}
OpenPOWER on IntegriCloud