1
1
mirror of https://github.com/rui314/mold.git synced 2024-12-26 01:44:29 +03:00

temporary

This commit is contained in:
Rui Ueyama 2020-11-03 14:53:32 +09:00
parent 5491d651b0
commit 9d7371add9
2 changed files with 18 additions and 19 deletions

8
mold.h
View File

@ -546,7 +546,7 @@ public:
Symbol *get_symbol(u32 idx) const {
if (idx < first_global)
return nullptr;
return symbols[idx - first_global];
return symbols[idx];
}
u64 get_symbol_addr(u32 idx) const {
@ -561,7 +561,7 @@ public:
return isec->output_section->shdr.sh_addr + isec->offset + sym.st_value;
return 0;
}
return symbols[idx - first_global]->addr;
return symbols[idx]->addr;
}
std::vector<InputSection *> sections;
@ -585,9 +585,6 @@ public:
i32 num_plt = 0;
i32 num_relplt = 0;
// For .strtab construction
std::vector<StringRef> local_symbols;
private:
void initialize_sections();
void initialize_symbols();
@ -599,6 +596,7 @@ private:
std::vector<StringPiece *> merged_strings_alloc;
std::vector<StringPiece *> merged_strings_noalloc;
std::vector<Symbol> local_symbols;
int first_global = 0;
bool has_common_symbol;

View File

@ -114,12 +114,14 @@ void ObjectFile::initialize_sections() {
}
void ObjectFile::initialize_symbols() {
symbols.reserve(elf_syms.size());
local_symbols.reserve(first_global);
for (int i = 0; i < first_global; i++) {
const ELF64LE::Sym &esym = elf_syms[i];
StringRef name = CHECK(esym.getName(symbol_strtab), this);
local_symbols.push_back(name);
local_symbols.emplace_back(name);
symbols.push_back(&local_symbols.back());
if (esym.getType() != STT_SECTION) {
local_strtab_size += name.size() + 1;
@ -197,8 +199,8 @@ void ObjectFile::parse() {
}
void ObjectFile::register_defined_symbols() {
for (int i = 0; i < symbols.size(); i++) {
const ELF64LE::Sym &esym = elf_syms[first_global + i];
for (int i = first_global; i < symbols.size(); i++) {
const ELF64LE::Sym &esym = elf_syms[i];
Symbol &sym = *symbols[i];
if (esym.isDefined()) {
@ -234,8 +236,8 @@ ObjectFile::register_undefined_symbols(tbb::parallel_do_feeder<ObjectFile *> &fe
if (is_alive.exchange(true))
return;
for (int i = 0; i < symbols.size(); i++) {
const ELF64LE::Sym &esym = elf_syms[first_global + i];
for (int i = first_global; i < symbols.size(); i++) {
const ELF64LE::Sym &esym = elf_syms[i];
Symbol &sym = *symbols[i];
if (esym.isUndefined() && esym.getBinding() != STB_WEAK &&
@ -254,8 +256,8 @@ void ObjectFile::hanlde_undefined_weak_symbols() {
if (!is_alive)
return;
for (int i = 0; i < symbols.size(); i++) {
const ELF64LE::Sym &esym = elf_syms[first_global + i];
for (int i = first_global; i < symbols.size(); i++) {
const ELF64LE::Sym &esym = elf_syms[i];
Symbol &sym = *symbols[i];
if (esym.isUndefined() && esym.getBinding() == STB_WEAK) {
@ -324,7 +326,7 @@ void ObjectFile::convert_common_symbols() {
if (elf_syms[i].st_shndx != SHN_COMMON)
continue;
Symbol *sym = symbols[i - first_global];
Symbol *sym = symbols[i];
if (sym->file != this)
continue;
@ -359,7 +361,7 @@ void ObjectFile::fix_sym_addrs() {
void ObjectFile::compute_symtab() {
for (int i = first_global; i < elf_syms.size(); i++) {
const ELF64LE::Sym &esym = elf_syms[i];
Symbol &sym = *symbols[i - first_global];
Symbol &sym = *symbols[i];
if (esym.getType() != STT_SECTION && sym.file == this) {
global_strtab_size += sym.name.size() + 1;
@ -378,8 +380,6 @@ ObjectFile::write_local_symtab(u8 *buf, u64 symtab_off, u64 strtab_off) {
if (esym.getType() == STT_SECTION)
continue;
StringRef name = local_symbols[i];
auto *ent = (ELF64LE::Sym *)(symtab + symtab_off);
*ent = esym;
if (esym.st_shndx != SHN_ABS && esym.st_shndx != SHN_COMMON)
@ -390,7 +390,8 @@ ObjectFile::write_local_symtab(u8 *buf, u64 symtab_off, u64 strtab_off) {
ent->st_value = get_symbol_addr(i);
symtab_off += sizeof(ELF64LE::Sym);
memcpy_nontemporal(strtab + strtab_off, name.data(), name.size());
StringRef name = symbols[i]->name;
memcpy(strtab + strtab_off, name.data(), name.size());
strtab_off += name.size() + 1;
}
}
@ -402,7 +403,7 @@ ObjectFile::write_global_symtab(u8 *buf, u64 symtab_off, u64 strtab_off) {
for (int i = first_global; i < elf_syms.size(); i++) {
const ELF64LE::Sym &esym = elf_syms[i];
Symbol &sym = *symbols[i - first_global];
Symbol &sym = *symbols[i];
if (esym.getType() == STT_SECTION || sym.file != this)
continue;
@ -417,7 +418,7 @@ ObjectFile::write_global_symtab(u8 *buf, u64 symtab_off, u64 strtab_off) {
ent->st_value = sym.addr;
symtab_off += sizeof(ELF64LE::Sym);
memcpy_nontemporal(strtab + strtab_off, sym.name.data(), sym.name.size());
memcpy(strtab + strtab_off, sym.name.data(), sym.name.size());
strtab_off += sym.name.size() + 1;
}
}