Consolidate BumpPtrAllocators.

Previously, we have a lot of BumpPtrAllocators, but all these
allocators virtually have the same lifetime because they are
not freed until the linker finishes its job. This patch aggregates
them into a single allocator.

Differential revision: https://reviews.llvm.org/D26042

llvm-svn: 285452
This commit is contained in:
Rui Ueyama 2016-10-28 20:57:25 +00:00
parent 8ee6f0c30f
commit 55518e7dd8
19 changed files with 112 additions and 87 deletions

View File

@ -14,6 +14,7 @@ add_lld_library(lldELF
LTO.cpp
LinkerScript.cpp
MarkLive.cpp
Memory.cpp
Mips.cpp
OutputSections.cpp
Relocations.cpp

View File

@ -14,6 +14,7 @@
#include "InputFiles.h"
#include "InputSection.h"
#include "LinkerScript.h"
#include "Memory.h"
#include "Strings.h"
#include "SymbolListFile.h"
#include "SymbolTable.h"
@ -54,6 +55,7 @@ bool elf::link(ArrayRef<const char *> Args, bool CanExitEarly,
Driver->main(Args, CanExitEarly);
InputFile::freePool();
freeArena();
return !HasError;
}
@ -141,7 +143,7 @@ void LinkerDriver::addFile(StringRef Path) {
case file_magic::archive:
if (InWholeArchive) {
for (MemoryBufferRef MB : getArchiveMembers(MBRef))
Files.push_back(createObjectFile(Alloc, MB, Path));
Files.push_back(createObjectFile(MB, Path));
return;
}
Files.push_back(new ArchiveFile(MBRef));
@ -151,13 +153,13 @@ void LinkerDriver::addFile(StringRef Path) {
error("attempted static link of dynamic object " + Path);
return;
}
Files.push_back(createSharedFile(Alloc, MBRef));
Files.push_back(createSharedFile(MBRef));
return;
default:
if (InLib)
Files.push_back(new LazyObjectFile(MBRef));
else
Files.push_back(createObjectFile(Alloc, MBRef));
Files.push_back(createObjectFile(MBRef));
}
}

View File

@ -50,7 +50,6 @@ private:
// True if we are in -format=binary and -format=elf.
bool InBinary = false;
llvm::BumpPtrAllocator Alloc;
std::vector<InputFile *> Files;
std::vector<std::unique_ptr<MemoryBuffer>> OwningMBs;
};
@ -60,9 +59,6 @@ class ELFOptTable : public llvm::opt::OptTable {
public:
ELFOptTable();
llvm::opt::InputArgList parse(ArrayRef<const char *> Argv);
private:
llvm::BumpPtrAllocator Alloc;
};
// Create enum with OPT_xxx values for each option in Options.td

View File

@ -15,6 +15,7 @@
#include "Driver.h"
#include "Error.h"
#include "Memory.h"
#include "lld/Config/Version.h"
#include "lld/Core/Reproduce.h"
#include "llvm/ADT/STLExtras.h"
@ -23,7 +24,6 @@
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/StringSaver.h"
using namespace llvm;
using namespace llvm::sys;
@ -78,7 +78,6 @@ opt::InputArgList ELFOptTable::parse(ArrayRef<const char *> Argv) {
opt::InputArgList Args = this->ParseArgs(Vec, MissingIndex, MissingCount);
// Expand response files. '@<filename>' is replaced by the file's contents.
StringSaver Saver(Alloc);
cl::ExpandResponseFiles(Saver, getQuotingStyle(Args), Vec);
// Parse options and then do error checking.

View File

@ -12,6 +12,7 @@
#include "Error.h"
#include "InputSection.h"
#include "LinkerScript.h"
#include "Memory.h"
#include "SymbolTable.h"
#include "Symbols.h"
#include "llvm/ADT/STLExtras.h"
@ -142,8 +143,8 @@ template <class ELFT> void ELFFileBase<ELFT>::initStringTable() {
}
template <class ELFT>
elf::ObjectFile<ELFT>::ObjectFile(BumpPtrAllocator &Alloc, MemoryBufferRef M)
: ELFFileBase<ELFT>(Base::ObjectKind, M), Alloc(Alloc) {}
elf::ObjectFile<ELFT>::ObjectFile(MemoryBufferRef M)
: ELFFileBase<ELFT>(Base::ObjectKind, M) {}
template <class ELFT>
ArrayRef<SymbolBody *> elf::ObjectFile<ELFT>::getNonLocalSymbols() {
@ -482,9 +483,9 @@ SymbolBody *elf::ObjectFile<ELFT>::createSymbolBody(const Elf_Sym *Sym) {
if (Sym->getType() == STT_FILE)
SourceFile = check(Sym->getName(this->StringTable));
if (Sym->st_shndx == SHN_UNDEF)
return new (this->Alloc)
return new (BAlloc)
Undefined(Sym->st_name, Sym->st_other, Sym->getType(), this);
return new (this->Alloc) DefinedRegular<ELFT>(*Sym, Sec);
return new (BAlloc) DefinedRegular<ELFT>(*Sym, Sec);
}
StringRef Name = check(Sym->getName(this->StringTable));
@ -553,7 +554,7 @@ ArchiveFile::getMember(const Archive::Symbol *Sym) {
}
template <class ELFT>
SharedFile<ELFT>::SharedFile(BumpPtrAllocator &Alloc, MemoryBufferRef M)
SharedFile<ELFT>::SharedFile(MemoryBufferRef M)
: ELFFileBase<ELFT>(Base::SharedKind, M), AsNeeded(Config->AsNeeded) {}
template <class ELFT>
@ -745,7 +746,7 @@ static uint8_t mapVisibility(GlobalValue::VisibilityTypes GvVisibility) {
template <class ELFT>
static Symbol *createBitcodeSymbol(const std::vector<bool> &KeptComdats,
const lto::InputFile::Symbol &ObjSym,
StringSaver &Saver, BitcodeFile *F) {
BitcodeFile *F) {
StringRef NameRef = Saver.save(ObjSym.getName());
uint32_t Flags = ObjSym.getFlags();
uint32_t Binding = (Flags & BasicSymbolRef::SF_Weak) ? STB_WEAK : STB_GLOBAL;
@ -794,12 +795,11 @@ void BitcodeFile::parse(DenseSet<CachedHashStringRef> &ComdatGroups) {
}
for (const lto::InputFile::Symbol &ObjSym : Obj->symbols())
Symbols.push_back(
createBitcodeSymbol<ELFT>(KeptComdats, ObjSym, Saver, this));
Symbols.push_back(createBitcodeSymbol<ELFT>(KeptComdats, ObjSym, this));
}
template <template <class> class T>
static InputFile *createELFFile(BumpPtrAllocator &Alloc, MemoryBufferRef MB) {
static InputFile *createELFFile(MemoryBufferRef MB) {
unsigned char Size;
unsigned char Endian;
std::tie(Size, Endian) = getElfArchType(MB.getBuffer());
@ -808,13 +808,13 @@ static InputFile *createELFFile(BumpPtrAllocator &Alloc, MemoryBufferRef MB) {
InputFile *Obj;
if (Size == ELFCLASS32 && Endian == ELFDATA2LSB)
Obj = new T<ELF32LE>(Alloc, MB);
Obj = new T<ELF32LE>(MB);
else if (Size == ELFCLASS32 && Endian == ELFDATA2MSB)
Obj = new T<ELF32BE>(Alloc, MB);
Obj = new T<ELF32BE>(MB);
else if (Size == ELFCLASS64 && Endian == ELFDATA2LSB)
Obj = new T<ELF64LE>(Alloc, MB);
Obj = new T<ELF64LE>(MB);
else if (Size == ELFCLASS64 && Endian == ELFDATA2MSB)
Obj = new T<ELF64BE>(Alloc, MB);
Obj = new T<ELF64BE>(MB);
else
fatal("invalid file class: " + MB.getBufferIdentifier());
@ -853,18 +853,17 @@ static bool isBitcode(MemoryBufferRef MB) {
return identify_magic(MB.getBuffer()) == file_magic::bitcode;
}
InputFile *elf::createObjectFile(BumpPtrAllocator &Alloc, MemoryBufferRef MB,
StringRef ArchiveName,
InputFile *elf::createObjectFile(MemoryBufferRef MB, StringRef ArchiveName,
uint64_t OffsetInArchive) {
InputFile *F = isBitcode(MB) ? new BitcodeFile(MB)
: createELFFile<ObjectFile>(Alloc, MB);
InputFile *F =
isBitcode(MB) ? new BitcodeFile(MB) : createELFFile<ObjectFile>(MB);
F->ArchiveName = ArchiveName;
F->OffsetInArchive = OffsetInArchive;
return F;
}
InputFile *elf::createSharedFile(BumpPtrAllocator &Alloc, MemoryBufferRef MB) {
return createELFFile<SharedFile>(Alloc, MB);
InputFile *elf::createSharedFile(MemoryBufferRef MB) {
return createELFFile<SharedFile>(MB);
}
MemoryBufferRef LazyObjectFile::getBuffer() {

View File

@ -24,7 +24,6 @@
#include "llvm/Object/Archive.h"
#include "llvm/Object/ELF.h"
#include "llvm/Object/IRObjectFile.h"
#include "llvm/Support/StringSaver.h"
#include <map>
@ -181,7 +180,7 @@ public:
ArrayRef<SymbolBody *> getLocalSymbols();
ArrayRef<SymbolBody *> getNonLocalSymbols();
explicit ObjectFile(llvm::BumpPtrAllocator &Alloc, MemoryBufferRef M);
explicit ObjectFile(MemoryBufferRef M);
void parse(llvm::DenseSet<llvm::CachedHashStringRef> &ComdatGroups);
ArrayRef<InputSectionBase<ELFT> *> getSections() const { return Sections; }
@ -214,10 +213,6 @@ public:
// st_name of the symbol.
std::vector<std::pair<const DefinedRegular<ELFT> *, unsigned>> KeptLocalSyms;
// SymbolBodies and Thunks for sections in this file are allocated
// using this buffer.
llvm::BumpPtrAllocator &Alloc;
// Name of source file obtained from STT_FILE symbol value,
// or empty string if there is no such symbol in object file
// symbol table.
@ -273,8 +268,6 @@ private:
template <class ELFT> std::vector<StringRef> getElfSymbols();
std::vector<StringRef> getBitcodeSymbols();
llvm::BumpPtrAllocator Alloc;
llvm::StringSaver Saver{Alloc};
bool Seen = false;
};
@ -307,8 +300,6 @@ public:
private:
std::vector<Symbol *> Symbols;
llvm::BumpPtrAllocator Alloc;
llvm::StringSaver Saver{Alloc};
};
// .so file.
@ -335,7 +326,7 @@ public:
return F->kind() == Base::SharedKind;
}
explicit SharedFile(llvm::BumpPtrAllocator &Alloc, MemoryBufferRef M);
explicit SharedFile(MemoryBufferRef M);
void parseSoName();
void parseRest();
@ -367,15 +358,12 @@ public:
ArrayRef<InputSectionData *> getSections() const { return Sections; }
private:
llvm::BumpPtrAllocator Alloc;
llvm::StringSaver Saver{Alloc};
std::vector<InputSectionData *> Sections;
};
InputFile *createObjectFile(llvm::BumpPtrAllocator &Alloc, MemoryBufferRef MB,
StringRef ArchiveName = "",
InputFile *createObjectFile(MemoryBufferRef MB, StringRef ArchiveName = "",
uint64_t OffsetInArchive = 0);
InputFile *createSharedFile(llvm::BumpPtrAllocator &Alloc, MemoryBufferRef MB);
InputFile *createSharedFile(MemoryBufferRef MB);
} // namespace elf
} // namespace lld

View File

@ -137,8 +137,7 @@ std::vector<InputFile *> BitcodeCompiler::compile() {
else
saveBuffer(Buff[I], Config->OutputFile + Twine(I) + ".lto.o");
}
InputFile *Obj =
createObjectFile(Alloc, MemoryBufferRef(Buff[I], "lto.tmp"));
InputFile *Obj = createObjectFile(MemoryBufferRef(Buff[I], "lto.tmp"));
Ret.push_back(Obj);
}
return Ret;

View File

@ -49,7 +49,6 @@ public:
private:
std::unique_ptr<llvm::lto::LTO> LtoObj;
std::vector<SmallString<0>> Buff;
llvm::BumpPtrAllocator Alloc;
};
}
}

View File

@ -21,11 +21,12 @@
#include "Config.h"
#include "Driver.h"
#include "InputSection.h"
#include "Memory.h"
#include "OutputSections.h"
#include "ScriptParser.h"
#include "Strings.h"
#include "Symbols.h"
#include "SymbolTable.h"
#include "Symbols.h"
#include "Target.h"
#include "Writer.h"
#include "llvm/ADT/StringSwitch.h"
@ -33,7 +34,6 @@
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/StringSaver.h"
using namespace llvm;
using namespace llvm::ELF;
@ -351,7 +351,7 @@ void LinkerScript<ELFT>::createSections(OutputSectionFactory<ELFT> &Factory) {
for (ObjectFile<ELFT> *F : Symtab<ELFT>::X->getObjectFiles())
for (InputSectionBase<ELFT> *S : F->getSections())
if (!isDiscarded(S) && !S->OutSec)
addSection(Factory, S, getOutputSectionName(S->Name, Opt.Alloc));
addSection(Factory, S, getOutputSectionName(S->Name));
}
// Sets value of a section-defined symbol. Two kinds of
@ -954,7 +954,6 @@ private:
void readLocal();
ScriptConfiguration &Opt = *ScriptConfig;
StringSaver Saver = {ScriptConfig->Alloc};
bool IsUnderSysroot;
};

View File

@ -188,8 +188,6 @@ struct ScriptConfiguration {
bool HasSections = false;
llvm::BumpPtrAllocator Alloc;
// List of section patterns specified with KEEP commands. They will
// be kept even if they are unused and --gc-sections is specified.
std::vector<InputSectionDescription *> KeptSections;

15
lld/ELF/Memory.cpp Normal file
View File

@ -0,0 +1,15 @@
//===- Memory.cpp -----------------------------------------------*- C++ -*-===//
//
// The LLVM Linker
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "Memory.h"
llvm::BumpPtrAllocator lld::elf::BAlloc;
llvm::StringSaver lld::elf::Saver{BAlloc};
void lld::elf::freeArena() { BAlloc.Reset(); }

37
lld/ELF/Memory.h Normal file
View File

@ -0,0 +1,37 @@
//===- Memory.h -------------------------------------------------*- C++ -*-===//
//
// The LLVM Linker
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file defines arena allocators.
//
// Almost all large objects, such as files, sections or symbols, are
// used for the entire lifetime of the linker once they are created.
// This usage characteristic makes arena allocator an attractive choice
// where the entire linker is one arena. With an arena, newly created
// objects belong to the arena and freed all at once when everything is done.
// Arena allocators are efficient and easy to understand.
// Most objects are allocated using the arena allocators defined by this file.
//
//===----------------------------------------------------------------------===//
#ifndef LLD_ELF_MEMORY_H
#define LLD_ELF_MEMORY_H
#include "llvm/Support/Allocator.h"
#include "llvm/Support/StringSaver.h"
namespace lld {
namespace elf {
extern llvm::BumpPtrAllocator BAlloc;
extern llvm::StringSaver Saver;
void freeArena();
}
}
#endif

View File

@ -18,10 +18,10 @@
#include "Config.h"
#include "Error.h"
#include "LinkerScript.h"
#include "Memory.h"
#include "SymbolListFile.h"
#include "Symbols.h"
#include "llvm/Bitcode/ReaderWriter.h"
#include "llvm/Support/StringSaver.h"
using namespace llvm;
using namespace llvm::object;
@ -150,7 +150,6 @@ template <class ELFT> void SymbolTable<ELFT>::wrap(StringRef Name) {
SymbolBody *B = find(Name);
if (!B)
return;
StringSaver Saver(Alloc);
Symbol *Sym = B->symbol();
Symbol *Real = addUndefined(Saver.save("__real_" + Name));
Symbol *Wrap = addUndefined(Saver.save("__wrap_" + Name));
@ -214,7 +213,7 @@ std::pair<Symbol *, bool> SymbolTable<ELFT>::insert(StringRef &Name) {
Symbol *Sym;
if (IsNew) {
Sym = new (Alloc) Symbol;
Sym = new (BAlloc) Symbol;
Sym->Binding = STB_WEAK;
Sym->Visibility = STV_DEFAULT;
Sym->IsUsedInRegularObj = false;
@ -289,7 +288,7 @@ Symbol *SymbolTable<ELFT>::addUndefined(StringRef Name, uint8_t Binding,
// its type. See also comment in addLazyArchive.
if (S->isWeak())
L->Type = Type;
else if (InputFile *F = L->fetch(Alloc))
else if (InputFile *F = L->fetch())
addFile(F);
}
return S;
@ -509,7 +508,7 @@ void SymbolTable<ELFT>::addLazyArchive(ArchiveFile *F,
}
std::pair<MemoryBufferRef, uint64_t> MBInfo = F->getMember(&Sym);
if (!MBInfo.first.getBuffer().empty())
addFile(createObjectFile(Alloc, MBInfo.first, F->getName(), MBInfo.second));
addFile(createObjectFile(MBInfo.first, F->getName(), MBInfo.second));
}
template <class ELFT>
@ -530,7 +529,7 @@ void SymbolTable<ELFT>::addLazyObject(StringRef Name, LazyObjectFile &Obj) {
} else {
MemoryBufferRef MBRef = Obj.getBuffer();
if (!MBRef.getBuffer().empty())
addFile(createObjectFile(Alloc, MBRef));
addFile(createObjectFile(MBRef));
}
}
@ -538,7 +537,7 @@ void SymbolTable<ELFT>::addLazyObject(StringRef Name, LazyObjectFile &Obj) {
template <class ELFT> void SymbolTable<ELFT>::scanUndefinedFlags() {
for (StringRef S : Config->Undefined)
if (auto *L = dyn_cast_or_null<Lazy>(find(S)))
if (InputFile *File = L->fetch(Alloc))
if (InputFile *File = L->fetch())
addFile(File);
}

View File

@ -127,7 +127,6 @@ private:
// once symbol resolution is finished.
llvm::DenseMap<SymName, SymIndex> Symtab;
std::vector<Symbol *> SymVector;
llvm::BumpPtrAllocator Alloc;
// Comdat groups define "link once" sections. If two comdat groups have the
// same name, only one of them is linked, and the other is ignored. This set

View File

@ -227,10 +227,10 @@ DefinedCommon::DefinedCommon(StringRef N, uint64_t Size, uint64_t Alignment,
this->File = File;
}
InputFile *Lazy::fetch(BumpPtrAllocator &Alloc) {
InputFile *Lazy::fetch() {
if (auto *S = dyn_cast<LazyArchive>(this))
return S->fetch(Alloc);
return cast<LazyObject>(this)->fetch(Alloc);
return S->fetch();
return cast<LazyObject>(this)->fetch();
}
LazyArchive::LazyArchive(ArchiveFile &File,
@ -244,22 +244,21 @@ LazyObject::LazyObject(StringRef Name, LazyObjectFile &File, uint8_t Type)
this->File = &File;
}
InputFile *LazyArchive::fetch(BumpPtrAllocator &Alloc) {
InputFile *LazyArchive::fetch() {
std::pair<MemoryBufferRef, uint64_t> MBInfo = file()->getMember(&Sym);
// getMember returns an empty buffer if the member was already
// read from the library.
if (MBInfo.first.getBuffer().empty())
return nullptr;
return createObjectFile(Alloc, MBInfo.first, file()->getName(),
MBInfo.second);
return createObjectFile(MBInfo.first, file()->getName(), MBInfo.second);
}
InputFile *LazyObject::fetch(BumpPtrAllocator &Alloc) {
InputFile *LazyObject::fetch() {
MemoryBufferRef MBRef = file()->getBuffer();
if (MBRef.getBuffer().empty())
return nullptr;
return createObjectFile(Alloc, MBRef);
return createObjectFile(MBRef);
}
bool Symbol::includeInDynsym() const {

View File

@ -323,7 +323,7 @@ public:
// Returns an object file for this symbol, or a nullptr if the file
// was already returned.
InputFile *fetch(llvm::BumpPtrAllocator &Alloc);
InputFile *fetch();
protected:
Lazy(SymbolBody::Kind K, StringRef Name, uint8_t Type)
@ -341,7 +341,7 @@ public:
}
ArchiveFile *file() { return (ArchiveFile *)this->File; }
InputFile *fetch(llvm::BumpPtrAllocator &Alloc);
InputFile *fetch();
private:
const llvm::object::Archive::Symbol Sym;
@ -358,7 +358,7 @@ public:
}
LazyObjectFile *file() { return (LazyObjectFile *)this->File; }
InputFile *fetch(llvm::BumpPtrAllocator &Alloc);
InputFile *fetch();
};
// Some linker-generated symbols need to be created as

View File

@ -25,6 +25,7 @@
#include "Error.h"
#include "InputFiles.h"
#include "InputSection.h"
#include "Memory.h"
#include "OutputSections.h"
#include "Symbols.h"
#include "Target.h"
@ -190,19 +191,18 @@ static Thunk<ELFT> *createThunkArm(uint32_t Reloc, SymbolBody &S,
// ARM relocations need ARM to Thumb interworking Thunks.
// Thumb relocations need Thumb to ARM relocations.
// Use position independent Thunks if we require position independent code.
BumpPtrAllocator &Alloc = IS.getFile()->Alloc;
switch (Reloc) {
case R_ARM_PC24:
case R_ARM_PLT32:
case R_ARM_JUMP24:
if (Config->Pic)
return new (Alloc) ARMToThumbV7PILongThunk<ELFT>(S, IS);
return new (Alloc) ARMToThumbV7ABSLongThunk<ELFT>(S, IS);
return new (BAlloc) ARMToThumbV7PILongThunk<ELFT>(S, IS);
return new (BAlloc) ARMToThumbV7ABSLongThunk<ELFT>(S, IS);
case R_ARM_THM_JUMP19:
case R_ARM_THM_JUMP24:
if (Config->Pic)
return new (Alloc) ThumbToARMV7PILongThunk<ELFT>(S, IS);
return new (Alloc) ThumbToARMV7ABSLongThunk<ELFT>(S, IS);
return new (BAlloc) ThumbToARMV7PILongThunk<ELFT>(S, IS);
return new (BAlloc) ThumbToARMV7ABSLongThunk<ELFT>(S, IS);
}
fatal("unrecognized relocation type");
}
@ -236,7 +236,7 @@ static void addThunkMips(uint32_t RelocType, SymbolBody &S,
// Mips Thunks are added to the InputSection defining S.
auto *R = cast<DefinedRegular<ELFT>>(&S);
auto *Sec = cast<InputSection<ELFT>>(R->Section);
auto *T = new (IS.getFile()->Alloc) MipsThunk<ELFT>(S, *Sec);
auto *T = new (BAlloc) MipsThunk<ELFT>(S, *Sec);
Sec->addThunk(T);
R->ThunkData = T;
}

View File

@ -10,6 +10,7 @@
#include "Writer.h"
#include "Config.h"
#include "LinkerScript.h"
#include "Memory.h"
#include "OutputSections.h"
#include "Relocations.h"
#include "Strings.h"
@ -19,7 +20,6 @@
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/Support/FileOutputBuffer.h"
#include "llvm/Support/StringSaver.h"
#include "llvm/Support/raw_ostream.h"
#include <climits>
@ -74,7 +74,6 @@ private:
std::unique_ptr<FileOutputBuffer> Buffer;
BumpPtrAllocator Alloc;
std::vector<OutputSectionBase<ELFT> *> OutputSections;
OutputSectionFactory<ELFT> Factory;
@ -90,7 +89,7 @@ private:
};
} // anonymous namespace
StringRef elf::getOutputSectionName(StringRef Name, BumpPtrAllocator &Alloc) {
StringRef elf::getOutputSectionName(StringRef Name) {
if (Config->Relocatable)
return Name;
@ -106,7 +105,7 @@ StringRef elf::getOutputSectionName(StringRef Name, BumpPtrAllocator &Alloc) {
// ".zdebug_" is a prefix for ZLIB-compressed sections.
// Because we decompressed input sections, we want to remove 'z'.
if (Name.startswith(".zdebug_"))
return StringSaver(Alloc).save(Twine(".") + Name.substr(2));
return Saver.save(Twine(".") + Name.substr(2));
return Name;
}
@ -705,7 +704,7 @@ template <class ELFT> void Writer<ELFT>::createSections() {
}
OutputSectionBase<ELFT> *Sec;
bool IsNew;
StringRef OutsecName = getOutputSectionName(IS->Name, Alloc);
StringRef OutsecName = getOutputSectionName(IS->Name);
std::tie(Sec, IsNew) = Factory.create(IS, OutsecName);
if (IsNew)
OutputSections.push_back(Sec);
@ -983,7 +982,6 @@ void Writer<ELFT>::addStartStopSymbols(OutputSectionBase<ELFT> *Sec) {
StringRef S = Sec->getName();
if (!isValidCIdentifier(S))
return;
StringSaver Saver(Alloc);
addOptionalSynthetic(Saver.save("__start_" + S), Sec, 0, STV_DEFAULT);
addOptionalSynthetic(Saver.save("__stop_" + S), Sec,
DefinedSynthetic<ELFT>::SectionEnd, STV_DEFAULT);

View File

@ -11,7 +11,6 @@
#define LLD_ELF_WRITER_H
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Allocator.h"
#include <cstdint>
#include <memory>
@ -38,8 +37,7 @@ template <class ELFT> struct PhdrEntry {
bool HasLMA = false;
};
llvm::StringRef getOutputSectionName(llvm::StringRef Name,
llvm::BumpPtrAllocator &Alloc);
llvm::StringRef getOutputSectionName(llvm::StringRef Name);
template <class ELFT> void reportDiscarded(InputSectionBase<ELFT> *IS);