mirror of
https://github.com/rui314/mold.git
synced 2024-09-21 18:08:01 +03:00
wip
This commit is contained in:
parent
fc21d22b1b
commit
b83b32e15b
75
mold.h
75
mold.h
@ -90,7 +90,6 @@ struct SymbolAux {
|
||||
i32 tlsdesc_idx = -1;
|
||||
i32 plt_idx = -1;
|
||||
i32 pltgot_idx = -1;
|
||||
i32 iplt_idx = -1;
|
||||
i32 dynsym_idx = -1;
|
||||
};
|
||||
|
||||
@ -401,19 +400,6 @@ public:
|
||||
void copy_buf(Context<E> &ctx) override;
|
||||
};
|
||||
|
||||
template <typename E>
|
||||
class GotIpltSection : public OutputChunk<E> {
|
||||
public:
|
||||
GotIpltSection() : OutputChunk<E>(this->SYNTHETIC) {
|
||||
this->name = ".got.iplt";
|
||||
this->shdr.sh_type = SHT_PROGBITS;
|
||||
this->shdr.sh_flags = SHF_ALLOC | SHF_WRITE;
|
||||
this->shdr.sh_addralign = E::got_size;
|
||||
}
|
||||
|
||||
void copy_buf(Context<E> &ctx) override;
|
||||
};
|
||||
|
||||
template <typename E>
|
||||
class PltSection : public OutputChunk<E> {
|
||||
public:
|
||||
@ -430,22 +416,6 @@ public:
|
||||
std::vector<Symbol<E> *> symbols;
|
||||
};
|
||||
|
||||
template <typename E>
|
||||
class IpltSection : public OutputChunk<E> {
|
||||
public:
|
||||
IpltSection() : OutputChunk<E>(this->SYNTHETIC) {
|
||||
this->name = ".iplt";
|
||||
this->shdr.sh_type = SHT_PROGBITS;
|
||||
this->shdr.sh_flags = SHF_ALLOC | SHF_EXECINSTR;
|
||||
this->shdr.sh_addralign = 16;
|
||||
}
|
||||
|
||||
void add_symbol(Context<E> &ctx, Symbol<E> *sym);
|
||||
void copy_buf(Context<E> &ctx) override;
|
||||
|
||||
std::vector<Symbol<E> *> symbols;
|
||||
};
|
||||
|
||||
template <typename E>
|
||||
class PltGotSection : public OutputChunk<E> {
|
||||
public:
|
||||
@ -492,21 +462,6 @@ public:
|
||||
void sort(Context<E> &ctx);
|
||||
};
|
||||
|
||||
template <typename E>
|
||||
class RelIpltSection : public OutputChunk<E> {
|
||||
public:
|
||||
RelIpltSection() : OutputChunk<E>(this->SYNTHETIC) {
|
||||
this->name = (E::rel_type == SHT_REL) ? ".rel.iplt" : ".rela.iplt";
|
||||
this->shdr.sh_type = E::rel_type;
|
||||
this->shdr.sh_flags = SHF_ALLOC;
|
||||
this->shdr.sh_entsize = sizeof(ElfRel<E>);
|
||||
this->shdr.sh_addralign = E::wordsize;
|
||||
}
|
||||
|
||||
void update_shdr(Context<E> &ctx) override;
|
||||
void copy_buf(Context<E> &ctx) override;
|
||||
};
|
||||
|
||||
template <typename E>
|
||||
class StrtabSection : public OutputChunk<E> {
|
||||
public:
|
||||
@ -1293,9 +1248,7 @@ struct Context {
|
||||
InterpSection<E> *interp = nullptr;
|
||||
GotSection<E> *got = nullptr;
|
||||
GotPltSection<E> *gotplt = nullptr;
|
||||
GotIpltSection<E> *gotiplt = nullptr;
|
||||
RelPltSection<E> *relplt = nullptr;
|
||||
RelIpltSection<E> *reliplt = nullptr;
|
||||
RelDynSection<E> *reldyn = nullptr;
|
||||
DynamicSection<E> *dynamic = nullptr;
|
||||
StrtabSection<E> *strtab = nullptr;
|
||||
@ -1304,7 +1257,6 @@ struct Context {
|
||||
GnuHashSection<E> *gnu_hash = nullptr;
|
||||
ShstrtabSection<E> *shstrtab = nullptr;
|
||||
PltSection<E> *plt = nullptr;
|
||||
IpltSection<E> *iplt = nullptr;
|
||||
PltGotSection<E> *pltgot = nullptr;
|
||||
SymtabSection<E> *symtab = nullptr;
|
||||
DynsymSection<E> *dynsym = nullptr;
|
||||
@ -1353,13 +1305,12 @@ void read_file(Context<E> &ctx, MemoryMappedFile<E> *mb);
|
||||
enum {
|
||||
NEEDS_GOT = 1 << 0,
|
||||
NEEDS_PLT = 1 << 1,
|
||||
NEEDS_IPLT = 1 << 2,
|
||||
NEEDS_GOTTP = 1 << 3,
|
||||
NEEDS_TLSGD = 1 << 4,
|
||||
NEEDS_TLSLD = 1 << 5,
|
||||
NEEDS_COPYREL = 1 << 6,
|
||||
NEEDS_DYNSYM = 1 << 7,
|
||||
NEEDS_TLSDESC = 1 << 8,
|
||||
NEEDS_GOTTP = 1 << 2,
|
||||
NEEDS_TLSGD = 1 << 3,
|
||||
NEEDS_TLSLD = 1 << 4,
|
||||
NEEDS_COPYREL = 1 << 5,
|
||||
NEEDS_DYNSYM = 1 << 6,
|
||||
NEEDS_TLSDESC = 1 << 7,
|
||||
};
|
||||
|
||||
template <typename E>
|
||||
@ -1415,7 +1366,6 @@ public:
|
||||
}
|
||||
|
||||
u64 get_got_addr(Context<E> &ctx) const {
|
||||
assert(get_got_idx(ctx) != -1);
|
||||
return ctx.got->shdr.sh_addr + get_got_idx(ctx) * E::got_size;
|
||||
}
|
||||
|
||||
@ -1442,7 +1392,6 @@ public:
|
||||
u64 get_plt_addr(Context<E> &ctx) const {
|
||||
if (i32 idx = get_plt_idx(ctx); idx != -1)
|
||||
return ctx.plt->shdr.sh_addr + idx * E::plt_size;
|
||||
assert(get_pltgot_idx(ctx) != -1);
|
||||
return ctx.pltgot->shdr.sh_addr + get_pltgot_idx(ctx) * E::pltgot_size;
|
||||
}
|
||||
|
||||
@ -1488,12 +1437,6 @@ public:
|
||||
ctx.symbol_aux[aux_idx].pltgot_idx = idx;
|
||||
}
|
||||
|
||||
void set_iplt_idx(Context<E> &ctx, i32 idx) const {
|
||||
assert(aux_idx != -1);
|
||||
assert(ctx.symbol_aux[aux_idx].iplt_idx < 0);
|
||||
ctx.symbol_aux[aux_idx].iplt_idx = idx;
|
||||
}
|
||||
|
||||
void set_dynsym_idx(Context<E> &ctx, i32 idx) const {
|
||||
assert(aux_idx != -1);
|
||||
assert(ctx.symbol_aux[aux_idx].dynsym_idx < 0);
|
||||
@ -1528,10 +1471,6 @@ public:
|
||||
return (aux_idx == -1) ? -1 : ctx.symbol_aux[aux_idx].pltgot_idx;
|
||||
}
|
||||
|
||||
i32 get_iplt_idx(Context<E> &ctx) const {
|
||||
return (aux_idx == -1) ? -1 : ctx.symbol_aux[aux_idx].iplt_idx;
|
||||
}
|
||||
|
||||
i32 get_dynsym_idx(Context<E> &ctx) const {
|
||||
return (aux_idx == -1) ? -1 : ctx.symbol_aux[aux_idx].dynsym_idx;
|
||||
}
|
||||
@ -1606,7 +1545,7 @@ public:
|
||||
u16 shndx = 0;
|
||||
u16 ver_idx = 0;
|
||||
|
||||
std::atomic_uint16_t flags = 0;
|
||||
std::atomic_uint8_t flags = 0;
|
||||
tbb::spin_mutex mu;
|
||||
std::atomic_uint8_t visibility = STV_DEFAULT;
|
||||
|
||||
|
@ -743,17 +743,6 @@ void GotPltSection<E>::copy_buf(Context<E> &ctx) {
|
||||
}
|
||||
}
|
||||
|
||||
template <typename E>
|
||||
void GotIpltSection<E>::copy_buf(Context<E> &ctx) {
|
||||
typename E::word *buf = (typename E::word *)(ctx.buf + this->shdr.sh_offset);
|
||||
|
||||
if (E::rel_type == SHT_REL) {
|
||||
std::span<Symbol<E> *> syms = ctx.iplt->symbols;
|
||||
for (i64 i = 0; i < syms.size(); i++)
|
||||
buf[i] = syms[i]->input_section->get_addr() + syms[i]->value;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename E>
|
||||
void PltSection<E>::add_symbol(Context<E> &ctx, Symbol<E> *sym) {
|
||||
assert(!sym->has_plt(ctx));
|
||||
@ -774,31 +763,6 @@ void PltSection<E>::add_symbol(Context<E> &ctx, Symbol<E> *sym) {
|
||||
ctx.dynsym->add_symbol(ctx, sym);
|
||||
}
|
||||
|
||||
template <typename E>
|
||||
void IpltSection<E>::add_symbol(Context<E> &ctx, Symbol<E> *sym) {
|
||||
sym->set_iplt_idx(ctx, this->shdr.sh_size / E::pltgot_size);
|
||||
this->shdr.sh_size += E::pltgot_size;
|
||||
symbols.push_back(sym);
|
||||
|
||||
ctx.gotiplt->shdr.sh_size += E::got_size;
|
||||
}
|
||||
|
||||
template <typename E>
|
||||
void IpltSection<E>::copy_buf(Context<E> &ctx) {
|
||||
u8 *buf = ctx.buf + this->shdr.sh_offset;
|
||||
|
||||
static const u8 data[] = {
|
||||
0xff, 0x25, 0, 0, 0, 0, // jmp *foo@IGOT
|
||||
0x66, 0x90, // nop
|
||||
};
|
||||
|
||||
for (i64 i = 0; i < symbols.size(); i++) {
|
||||
u8 *ent = buf + i * E::pltgot_size;
|
||||
memcpy(ent, data, sizeof(data));
|
||||
*(u32 *)(ent + 2) = ctx.gotiplt->shdr.sh_addr + i * E::got_size - 6;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename E>
|
||||
void PltGotSection<E>::add_symbol(Context<E> &ctx, Symbol<E> *sym) {
|
||||
assert(!sym->has_plt(ctx));
|
||||
@ -857,16 +821,6 @@ void RelPltSection<E>::copy_buf(Context<E> &ctx) {
|
||||
}
|
||||
}
|
||||
|
||||
template <typename E>
|
||||
void RelIpltSection<E>::update_shdr(Context<E> &ctx) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
template <typename E>
|
||||
void RelIpltSection<E>::copy_buf(Context<E> &ctx) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
template <typename E>
|
||||
void DynsymSection<E>::add_symbol(Context<E> &ctx, Symbol<E> *sym) {
|
||||
if (symbols.empty())
|
||||
@ -1526,12 +1480,9 @@ void BuildIdSection<E>::write_buildid(Context<E> &ctx, i64 filesize) {
|
||||
template class OutputSection<E>; \
|
||||
template class GotSection<E>; \
|
||||
template class GotPltSection<E>; \
|
||||
template class GotIpltSection<E>; \
|
||||
template class PltSection<E>; \
|
||||
template class IpltSection<E>; \
|
||||
template class PltGotSection<E>; \
|
||||
template class RelPltSection<E>; \
|
||||
template class RelIpltSection<E>; \
|
||||
template class RelDynSection<E>; \
|
||||
template class StrtabSection<E>; \
|
||||
template class ShstrtabSection<E>; \
|
||||
|
@ -33,13 +33,10 @@ void create_synthetic_sections(Context<E> &ctx) {
|
||||
add(ctx.shdr = new OutputShdr<E>);
|
||||
add(ctx.got = new GotSection<E>);
|
||||
add(ctx.gotplt = new GotPltSection<E>);
|
||||
add(ctx.gotiplt = new GotIpltSection<E>);
|
||||
add(ctx.relplt = new RelPltSection<E>);
|
||||
add(ctx.reliplt = new RelIpltSection<E>);
|
||||
add(ctx.strtab = new StrtabSection<E>);
|
||||
add(ctx.shstrtab = new ShstrtabSection<E>);
|
||||
add(ctx.plt = new PltSection<E>);
|
||||
add(ctx.iplt = new IpltSection<E>);
|
||||
add(ctx.pltgot = new PltGotSection<E>);
|
||||
add(ctx.symtab = new SymtabSection<E>);
|
||||
add(ctx.dynsym = new DynsymSection<E>);
|
||||
|
Loading…
Reference in New Issue
Block a user