1
1
mirror of https://github.com/rui314/mold.git synced 2024-09-22 10:27:48 +03:00

temporary

This commit is contained in:
Rui Ueyama 2020-10-30 17:42:39 +09:00
parent bea3252d2c
commit 381da6dfaa
4 changed files with 35 additions and 12 deletions

View File

@ -44,10 +44,12 @@ std::tuple<u64, u64> InputSection::scan_relocations() {
case R_X86_64_GOTPC64:
case R_X86_64_GOTPCREL:
case R_X86_64_GOTPCRELX:
case R_X86_64_GOTTPOFF:
case R_X86_64_REX_GOTPCRELX:
num_got += !sym->needs_got.exchange(true);
break;
case R_X86_64_GOTTPOFF:
num_got += !sym->needs_gottp.exchange(true);
break;
#if 0
case R_X86_64_PLT32:
num_got += !sym->needs_got.exchange(true);
@ -109,7 +111,9 @@ void InputSection::relocate(u8 *buf) {
case R_X86_64_TLSGD:
case R_X86_64_TLSLD:
case R_X86_64_DTPOFF32:
break;
case R_X86_64_GOTTPOFF:
*(u32 *)loc = GOT + A - P;
break;
case R_X86_64_TPOFF32:
*(u32 *)loc = S - out::tls_end;

11
main.cc
View File

@ -527,10 +527,17 @@ int main(int argc, char **argv) {
for (ObjectFile *file : files) {
for (Symbol *sym : file->symbols) {
if (sym->file == file && sym->needs_got) {
out::got->symbols.push_back(sym);
if (sym->file != file)
continue;
if (sym->needs_got) {
out::got->symbols.push_back({GotSection::REGULAR, sym});
sym->got_addr = offset;
offset += 8;
} else if (sym->needs_gottp) {
out::got->symbols.push_back({GotSection::TP, sym});
sym->gottp_addr = offset;
offset += 8;
}
}
}

15
mold.h
View File

@ -186,6 +186,7 @@ public:
u64 addr = 0;
u64 got_addr = 0;
u64 gottp_addr = 0;
u64 plt_addr = 0;
u64 value;
@ -194,6 +195,7 @@ public:
bool is_undef_weak = false;
std::atomic_bool needs_got = ATOMIC_VAR_INIT(false);
std::atomic_bool needs_gottp = ATOMIC_VAR_INIT(false);
std::atomic_bool needs_plt = ATOMIC_VAR_INIT(false);
};
@ -365,6 +367,8 @@ private:
class GotSection : public OutputChunk {
public:
typedef enum : u8 { REGULAR, TP } GotType;
GotSection() {
name = ".got";
shdr.sh_flags = llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE;
@ -373,19 +377,12 @@ public:
}
void copy_to(u8 *buf) override {}
void relocate(u8 *buf) override {
buf += shdr.sh_offset;
for (Symbol *sym : symbols) {
*(u64 *)buf = sym->addr;
buf += 8;
}
}
void relocate(u8 *buf) override;
u64 get_size() const override { return size; }
u64 size = 0;
std::vector<Symbol *> symbols;
std::vector<std::pair<GotType, Symbol *>> symbols;
};
class ShstrtabSection : public OutputChunk {

View File

@ -166,3 +166,18 @@ OutputSection::get_instance(StringRef name, u64 flags, u32 type) {
return osec;
return new OutputSection(name, flags, type);
}
void GotSection::relocate(u8 *buf) {
buf += shdr.sh_offset;
for (auto pair : symbols) {
GotType type = pair.first;
Symbol *sym = pair.second;
if (type == REGULAR)
*(u64 *)buf = sym->addr;
else
*(u64 *)buf = sym->addr - out::tls_end;
buf += 8;
}
}