1
1
mirror of https://github.com/rui314/mold.git synced 2024-11-11 16:58:12 +03:00

temporary

This commit is contained in:
Rui Ueyama 2020-10-25 09:29:03 +09:00
parent 40acdc7892
commit 3cb7b5b0d1
4 changed files with 12 additions and 12 deletions

View File

@ -87,7 +87,7 @@ void ObjectFile::initialize_sections() {
}
StringRef name = CHECK(obj.getSectionName(shdr, section_strtab), this);
this->sections[i] = new InputSection(this, &shdr, name);
this->sections[i] = new InputSection(this, shdr, name);
break;
}
}
@ -105,7 +105,7 @@ void ObjectFile::initialize_sections() {
InputSection *target = sections[shdr.sh_info];
if (target) {
target->rels = CHECK(obj.relas(shdr), this);
if (target->hdr->sh_flags & SHF_ALLOC)
if (target->hdr.sh_flags & SHF_ALLOC)
num_relocs_alloc += target->rels.size();
}
}

View File

@ -4,12 +4,12 @@ using namespace llvm::ELF;
std::atomic_int num_relocs;
InputSection::InputSection(ObjectFile *file, const ELF64LE::Shdr *hdr, StringRef name)
InputSection::InputSection(ObjectFile *file, const ELF64LE::Shdr &hdr, StringRef name)
: file(file), hdr(hdr) {
this->name = name;
this->output_section = OutputSection::get_instance(this);
uint64_t align = (hdr->sh_addralign == 0) ? 1 : hdr->sh_addralign;
uint64_t align = (hdr.sh_addralign == 0) ? 1 : hdr.sh_addralign;
if (align > UINT32_MAX)
error(toString(file) + ": section sh_addralign is too large");
if (__builtin_popcount(align) != 1)
@ -18,13 +18,13 @@ InputSection::InputSection(ObjectFile *file, const ELF64LE::Shdr *hdr, StringRef
}
uint64_t InputSection::get_size() const {
return hdr->sh_size;
return hdr.sh_size;
}
void InputSection::copy_to(uint8_t *buf) {
if (hdr->sh_type == SHT_NOBITS || hdr->sh_size == 0)
if (hdr.sh_type == SHT_NOBITS || hdr.sh_size == 0)
return;
ArrayRef<uint8_t> data = check(file->obj.getSectionContents(*hdr));
ArrayRef<uint8_t> data = check(file->obj.getSectionContents(hdr));
memcpy(buf + offset, &data[0], data.size());
}

4
mold.h
View File

@ -181,7 +181,7 @@ inline std::string toString(Symbol sym) {
class InputSection {
public:
InputSection(ObjectFile *file, const ELF64LE::Shdr *hdr, StringRef name);
InputSection(ObjectFile *file, const ELF64LE::Shdr &hdr, StringRef name);
void copy_to(uint8_t *buf);
void relocate(uint8_t *buf);
@ -191,7 +191,7 @@ public:
ObjectFile *file;
OutputSection *output_section;
ArrayRef<ELF64LE::Rela> rels;
const ELF64LE::Shdr *hdr;
const ELF64LE::Shdr &hdr;
StringRef name;
uint64_t addr;

View File

@ -56,12 +56,12 @@ static StringRef get_output_name(StringRef name) {
OutputSection *OutputSection::get_instance(InputSection *isec) {
StringRef iname = get_output_name(isec->name);
uint64_t iflags = isec->hdr->sh_flags & ~SHF_GROUP;
uint64_t iflags = isec->hdr.sh_flags & ~SHF_GROUP;
auto find = [&]() -> OutputSection * {
for (OutputSection *osec : OutputSection::all_instances)
if (iname == osec->name && iflags == (osec->hdr.sh_flags & ~SHF_GROUP) &&
isec->hdr->sh_type == osec->hdr.sh_type)
isec->hdr.sh_type == osec->hdr.sh_type)
return osec;
return nullptr;
};
@ -77,5 +77,5 @@ OutputSection *OutputSection::get_instance(InputSection *isec) {
std::unique_lock unique_lock(mu);
if (OutputSection *osec = find())
return osec;
return new OutputSection(iname, iflags, isec->hdr->sh_type);
return new OutputSection(iname, iflags, isec->hdr.sh_type);
}