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

temporary

This commit is contained in:
Rui Ueyama 2020-11-17 13:51:44 +09:00
parent 3606fd30a7
commit 5cec0d477b
3 changed files with 21 additions and 18 deletions

View File

@ -982,7 +982,7 @@ int main(int argc, char **argv) {
{
MyTimer t("copy", copy_timer);
tbb::parallel_for_each(out::chunks, [&](OutputChunk *chunk) {
chunk->initialize(out::buf);
chunk->initialize_buf();
});
}

17
mold.h
View File

@ -311,7 +311,7 @@ public:
OutputChunk(Kind kind) : kind(kind) { shdr.sh_addralign = 1; }
virtual void update_shdr() {}
virtual void initialize(u8 *buf) {}
virtual void initialize_buf() {}
virtual void copy_to(u8 *buf) {}
StringRef name;
@ -411,7 +411,7 @@ public:
shdr.sh_size = GOT_SIZE * 3;
}
void initialize(u8 *buf) override;
void initialize_buf() override;
};
class PltSection : public OutputChunk {
@ -424,7 +424,7 @@ public:
shdr.sh_size = PLT_SIZE;
}
void initialize(u8 *buf) override;
void initialize_buf() override;
void write_entry(u8 *buf, Symbol *sym);
};
@ -464,9 +464,7 @@ public:
shdr.sh_size = 1;
}
void initialize(u8 *buf) override {
buf[shdr.sh_offset] = '\0';
}
void initialize_buf() override;
};
class ShstrtabSection : public OutputChunk {
@ -524,10 +522,7 @@ public:
}
void update_shdr() override;
void initialize(u8 *buf) override {
memset(buf + shdr.sh_offset, 0, sizeof(ELF64LE::Sym));
}
void initialize_buf() override;
private:
std::vector<ELF64LE::Sym> contents;
@ -547,7 +542,7 @@ public:
void add_symbols(ArrayRef<Symbol *> syms);
void update_shdr() override;
void initialize(u8 *buf) override;
void initialize_buf() override;
void copy_to(u8 *buf) override;
std::vector<Symbol *> symbols;

View File

@ -187,6 +187,10 @@ void RelDynSection::update_shdr() {
shdr.sh_link = out::dynsym->shndx;
}
void StrtabSection::initialize_buf() {
out::buf[shdr.sh_offset] = '\0';
}
void ShstrtabSection::update_shdr() {
shdr.sh_size = 1;
for (OutputChunk *chunk : out::chunks) {
@ -232,6 +236,10 @@ void SymtabSection::update_shdr() {
shdr.sh_link = out::strtab->shndx;
}
void SymtabSection::initialize_buf() {
memset(out::buf + shdr.sh_offset, 0, sizeof(ELF64LE::Sym));
}
void DynamicSection::update_shdr() {
shdr.sh_size = create_dynamic_section().size() * 8;
shdr.sh_link = out::dynstr->shndx;
@ -308,21 +316,21 @@ bool OutputSection::empty() const {
return true;
}
void GotPltSection::initialize(u8 *buf) {
u8 *base = buf + shdr.sh_offset;
void GotPltSection::initialize_buf() {
u8 *base = out::buf + shdr.sh_offset;
memset(base, 0, shdr.sh_size);
if (out::dynamic)
*(u64 *)base = out::dynamic->shdr.sh_addr;
}
void PltSection::initialize(u8 *buf) {
void PltSection::initialize_buf() {
const u8 data[] = {
0xff, 0x35, 0, 0, 0, 0, // pushq GOTPLT+8(%rip)
0xff, 0x25, 0, 0, 0, 0, // jmp *GOTPLT+16(%rip)
0x0f, 0x1f, 0x40, 0x00, // nop
};
u8 *base = buf + shdr.sh_offset;
u8 *base = out::buf + shdr.sh_offset;
memcpy(base, data, sizeof(data));
*(u32 *)(base + 2) = out::gotplt->shdr.sh_addr - shdr.sh_addr + 2;
*(u32 *)(base + 8) = out::gotplt->shdr.sh_addr - shdr.sh_addr + 4;
@ -368,8 +376,8 @@ void DynsymSection::update_shdr() {
shdr.sh_link = out::dynstr->shndx;
}
void DynsymSection::initialize(u8 *buf) {
memset(buf + shdr.sh_offset, 0, sizeof(ELF64LE::Sym));
void DynsymSection::initialize_buf() {
memset(out::buf + shdr.sh_offset, 0, sizeof(ELF64LE::Sym));
}
void DynsymSection::copy_to(u8 *buf) {