1
1
mirror of https://github.com/rui314/mold.git synced 2024-12-26 18:02:30 +03:00

Separate relocate() from copy_to()

This commit is contained in:
Rui Ueyama 2020-11-08 00:15:03 +09:00
parent 80a4ecca34
commit 8986a6ad88
3 changed files with 14 additions and 0 deletions

View File

@ -21,7 +21,9 @@ void InputSection::copy_to(u8 *buf) {
ArrayRef<u8> data = check(file->obj.getSectionContents(shdr));
memcpy(buf + output_section->shdr.sh_offset + offset, &data[0], data.size());
}
void InputSection::relocate(u8 *buf) {
for (int i = 0; i < rels.size(); i++) {
const ELF64LE::Rela &rel = rels[i];
StringPieceRef &ref = rel_pieces[i];

View File

@ -957,6 +957,11 @@ int main(int argc, char **argv) {
for_each(output_chunks, [&](OutputChunk *chunk) { chunk->copy_to(buf); });
}
{
MyTimer t("relocate");
for_each(output_chunks, [&](OutputChunk *chunk) { chunk->relocate(buf); });
}
// Fill .plt, .got, got.plt and .rela.plt sections
{
MyTimer t("write_got");

7
mold.h
View File

@ -230,6 +230,7 @@ public:
InputSection(ObjectFile *file, const ELF64LE::Shdr &shdr, StringRef name);
void copy_to(u8 *buf);
void relocate(u8 *buf);
void scan_relocations();
ObjectFile *file;
@ -263,6 +264,7 @@ public:
OutputChunk() { shdr.sh_addralign = 1; }
virtual void copy_to(u8 *buf) {}
virtual void relocate(u8 *buf) {}
StringRef name;
int shndx = 0;
@ -338,6 +340,11 @@ public:
for_each(sections, [&](InputSection *isec) { isec->copy_to(buf); });
}
void relocate(u8 *buf) override {
if (shdr.sh_type != llvm::ELF::SHT_NOBITS)
for_each(sections, [&](InputSection *isec) { isec->relocate(buf); });
}
bool empty() const {
if (!sections.empty())
for (InputSection *isec : sections)