mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-18 19:26:45 +00:00
[ELF] Move InputSectionBase::file to SectionBase
... and add getCtx (file->ctx). This allows InputSectionBase and OutputSection to access ctx without taking an extra function argument.
This commit is contained in:
parent
15de239406
commit
c22588c7cd
@ -119,7 +119,7 @@ void EhReader::skipAugP() {
|
||||
uint8_t enc = readByte();
|
||||
if ((enc & 0xf0) == DW_EH_PE_aligned)
|
||||
failOn(d.data() - 1, "DW_EH_PE_aligned encoding is not supported");
|
||||
size_t size = getAugPSize(ctx, enc);
|
||||
size_t size = getAugPSize(isec->getCtx(), enc);
|
||||
if (size == 0)
|
||||
failOn(d.data() - 1, "unknown FDE encoding");
|
||||
if (size >= d.size())
|
||||
|
@ -48,8 +48,10 @@ void parseFiles(Ctx &, const std::vector<InputFile *> &files);
|
||||
|
||||
// The root class of input files.
|
||||
class InputFile {
|
||||
protected:
|
||||
public:
|
||||
Ctx &ctx;
|
||||
|
||||
protected:
|
||||
std::unique_ptr<Symbol *[]> symbols;
|
||||
uint32_t numSymbols = 0;
|
||||
SmallVector<InputSectionBase *, 0> sections;
|
||||
|
@ -52,9 +52,9 @@ InputSectionBase::InputSectionBase(InputFile *file, uint64_t flags,
|
||||
uint32_t link, uint32_t info,
|
||||
uint32_t addralign, ArrayRef<uint8_t> data,
|
||||
StringRef name, Kind sectionKind)
|
||||
: SectionBase(sectionKind, name, flags, entsize, addralign, type, info,
|
||||
link),
|
||||
file(file), content_(data.data()), size(data.size()) {
|
||||
: SectionBase(sectionKind, file, name, flags, entsize, addralign, type,
|
||||
info, link),
|
||||
content_(data.data()), size(data.size()) {
|
||||
// In order to reduce memory allocation, we assume that mergeable
|
||||
// sections are smaller than 4 GiB, which is not an unreasonable
|
||||
// assumption as of 2017.
|
||||
@ -88,7 +88,7 @@ template <class ELFT>
|
||||
InputSectionBase::InputSectionBase(ObjFile<ELFT> &file,
|
||||
const typename ELFT::Shdr &hdr,
|
||||
StringRef name, Kind sectionKind)
|
||||
: InputSectionBase(&file, getFlags(ctx, hdr.sh_flags), hdr.sh_type,
|
||||
: InputSectionBase(&file, getFlags(file.ctx, hdr.sh_flags), hdr.sh_type,
|
||||
hdr.sh_entsize, hdr.sh_link, hdr.sh_info,
|
||||
hdr.sh_addralign, getSectionContents(file, hdr), name,
|
||||
sectionKind) {
|
||||
@ -185,6 +185,8 @@ RelsOrRelas<ELFT> InputSectionBase::relsOrRelas(bool supportsCrel) const {
|
||||
return ret;
|
||||
}
|
||||
|
||||
Ctx &SectionBase::getCtx() const { return file->ctx; }
|
||||
|
||||
uint64_t SectionBase::getOffset(uint64_t offset) const {
|
||||
switch (kind()) {
|
||||
case Output: {
|
||||
|
@ -78,6 +78,12 @@ public:
|
||||
|
||||
uint8_t partition = 1;
|
||||
uint32_t type;
|
||||
|
||||
// The file which contains this section. For InputSectionBase, its dynamic
|
||||
// type is usually ObjFile<ELFT>, but may be an InputFile of InternalKind
|
||||
// (for a synthetic section).
|
||||
InputFile *file;
|
||||
|
||||
StringRef name;
|
||||
|
||||
// The 1-indexed partition that this section is assigned to by the garbage
|
||||
@ -92,6 +98,7 @@ public:
|
||||
uint32_t link;
|
||||
uint32_t info;
|
||||
|
||||
Ctx &getCtx() const;
|
||||
OutputSection *getOutputSection();
|
||||
const OutputSection *getOutputSection() const {
|
||||
return const_cast<SectionBase *>(this)->getOutputSection();
|
||||
@ -108,12 +115,12 @@ public:
|
||||
void markDead() { partition = 0; }
|
||||
|
||||
protected:
|
||||
constexpr SectionBase(Kind sectionKind, StringRef name, uint64_t flags,
|
||||
uint32_t entsize, uint32_t addralign, uint32_t type,
|
||||
uint32_t info, uint32_t link)
|
||||
constexpr SectionBase(Kind sectionKind, InputFile *file, StringRef name,
|
||||
uint64_t flags, uint32_t entsize, uint32_t addralign,
|
||||
uint32_t type, uint32_t info, uint32_t link)
|
||||
: sectionKind(sectionKind), bss(false), keepUnique(false), type(type),
|
||||
name(name), flags(flags), addralign(addralign), entsize(entsize),
|
||||
link(link), info(info) {}
|
||||
file(file), name(name), flags(flags), addralign(addralign),
|
||||
entsize(entsize), link(link), info(info) {}
|
||||
};
|
||||
|
||||
struct SymbolAnchor {
|
||||
@ -150,11 +157,6 @@ public:
|
||||
return s->kind() != Output && s->kind() != Class;
|
||||
}
|
||||
|
||||
// The file which contains this section. Its dynamic type is usually
|
||||
// ObjFile<ELFT>, but may be an InputFile of InternalKind (for a synthetic
|
||||
// section).
|
||||
InputFile *file;
|
||||
|
||||
// Input sections are part of an output section. Special sections
|
||||
// like .eh_frame and merge sections are first combined into a
|
||||
// synthetic section that is then added to an output section. In all
|
||||
|
@ -66,8 +66,9 @@ void OutputSection::writeHeaderTo(typename ELFT::Shdr *shdr) {
|
||||
}
|
||||
|
||||
OutputSection::OutputSection(StringRef name, uint32_t type, uint64_t flags)
|
||||
: SectionBase(Output, name, flags, /*Entsize*/ 0, /*Alignment*/ 1, type,
|
||||
/*Info*/ 0, /*Link*/ 0) {}
|
||||
: SectionBase(Output, ctx.internalFile, name, flags, /*entsize=*/0,
|
||||
/*addralign=*/1, type,
|
||||
/*info=*/0, /*link=*/0) {}
|
||||
|
||||
// We allow sections of types listed below to merged into a
|
||||
// single progbits section. This is typically done by linker
|
||||
|
@ -150,7 +150,8 @@ struct SectionClass final : public SectionBase {
|
||||
SmallVector<InputSectionDescription *, 0> commands;
|
||||
bool assigned = false;
|
||||
|
||||
SectionClass(StringRef name) : SectionBase(Class, name, 0, 0, 0, 0, 0, 0) {}
|
||||
SectionClass(StringRef name)
|
||||
: SectionBase(Class, nullptr, name, 0, 0, 0, 0, 0, 0) {}
|
||||
static bool classof(const SectionBase *s) { return s->kind() == Class; }
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user