1
1
mirror of https://github.com/rui314/mold.git synced 2024-12-28 10:54:56 +03:00

temporary

This commit is contained in:
Rui Ueyama 2020-10-27 22:08:49 +09:00
parent c195dd43b0
commit d62b6614aa
3 changed files with 44 additions and 32 deletions

View File

@ -120,7 +120,7 @@ void ObjectFile::initialize_symbols() {
const ELF64LE::Sym &esym = elf_syms[i];
StringRef name = CHECK(esym.getName(symbol_strtab), this);
local_symbols.push_back(name);
strtab_size += name.size() + 1;
local_strtab_size += name.size() + 1;
}
symbols.reserve(elf_syms.size() - first_global);
@ -342,18 +342,18 @@ void ObjectFile::fix_sym_addrs() {
}
void ObjectFile::compute_symtab() {
symtab_size = sizeof(ELF64LE::Sym) * first_global;
local_symtab_size = sizeof(ELF64LE::Sym) * first_global;
for (Symbol *sym : symbols) {
if (sym->file == this) {
strtab_size += sym->name.size() + 1;
symtab_size += sizeof(ELF64LE::Sym);
global_strtab_size += sym->name.size() + 1;
global_symtab_size += sizeof(ELF64LE::Sym);
}
}
}
std::pair<uint64_t, uint64_t>
ObjectFile::write_symtab_local(uint8_t *buf, uint64_t symtab_off, uint64_t strtab_off) {
void
ObjectFile::write_local_symtab(uint8_t *buf, uint64_t symtab_off, uint64_t strtab_off) {
uint8_t *symtab = buf + out::symtab->shdr.sh_offset;
uint8_t *strtab = buf + out::strtab->shdr.sh_offset;
@ -371,12 +371,10 @@ ObjectFile::write_symtab_local(uint8_t *buf, uint64_t symtab_off, uint64_t strta
memcpy(strtab + strtab_off, name.data(), name.size());
strtab_off += name.size() + 1;
}
return {symtab_off, strtab_off};
}
std::pair<uint64_t, uint64_t>
ObjectFile::write_symtab_global(uint8_t *buf, uint64_t symtab_off, uint64_t strtab_off) {
void
ObjectFile::write_global_symtab(uint8_t *buf, uint64_t symtab_off, uint64_t strtab_off) {
uint8_t *symtab = buf + out::symtab->shdr.sh_offset;
uint8_t *strtab = buf + out::strtab->shdr.sh_offset;
@ -397,8 +395,6 @@ ObjectFile::write_symtab_global(uint8_t *buf, uint64_t symtab_off, uint64_t strt
memcpy(strtab + strtab_off, sym.name.data(), sym.name.size());
strtab_off += sym.name.size() + 1;
}
return {symtab_off, strtab_off};
}
StringRef ObjectFile::get_filename() {

43
main.cc
View File

@ -437,8 +437,8 @@ int main(int argc, char **argv) {
for_each(files, [](ObjectFile *file) { file->compute_symtab(); });
for (ObjectFile *file : files) {
out::symtab->size += file->symtab_size;
out::strtab->size += file->strtab_size;
out::symtab->size += file->local_symtab_size + file->global_symtab_size;
out::strtab->size += file->local_strtab_size + file->global_strtab_size;
}
}
@ -509,21 +509,38 @@ int main(int argc, char **argv) {
// Fill .symtab and .strtab
{
MyTimer t("write_symtab");
uint64_t symtab_off = 0;
uint64_t strtab_off = 1;
for (ObjectFile *file : files)
std::tie(symtab_off, strtab_off) =
file->write_symtab_local(buf, symtab_off, strtab_off);
std::vector<uint64_t> symtab_off(files.size());
std::vector<uint64_t> strtab_off(files.size());
strtab_off[0] = 1;
out::symtab->shdr.sh_info = symtab_off / sizeof(ELF64LE::Sym);
for (int i = 1; i < files.size(); i++) {
symtab_off[i] = symtab_off[i - 1] + files[i - 1]->local_symtab_size;
strtab_off[i] = strtab_off[i - 1] + files[i - 1]->local_strtab_size;
}
for (ObjectFile *file : files)
std::tie(symtab_off, strtab_off) =
file->write_symtab_global(buf, symtab_off, strtab_off);
out::symtab->shdr.sh_info = strtab_off.back() / sizeof(ELF64LE::Sym);
assert(symtab_off == out::symtab->size);
assert(strtab_off == out::strtab->size);
tbb::parallel_for((size_t)0, files.size(),
[&](size_t i) {
files[i]->write_local_symtab(buf, symtab_off[i], strtab_off[i]);
});
symtab_off[0] = symtab_off.back() + files.back()->global_symtab_size;
strtab_off[0] = strtab_off.back() + files.back()->global_strtab_size;
for (int i = 1; i < files.size(); i++) {
symtab_off[i] = symtab_off[i - 1] + files[i - 1]->global_symtab_size;
strtab_off[i] = strtab_off[i - 1] + files[i - 1]->global_strtab_size;
}
assert(symtab_off.back() == out::symtab->size);
assert(strtab_off.back() == out::strtab->size);
tbb::parallel_for((size_t)0, files.size(),
[&](size_t i) {
files[i]->write_global_symtab(buf, symtab_off[i], strtab_off[i]);
});
}
// Copy input sections to the output file

13
mold.h
View File

@ -443,11 +443,8 @@ public:
void fix_sym_addrs();
void compute_symtab();
std::pair<uint64_t, uint64_t>
write_symtab_local(uint8_t *buf, uint64_t symtab_off, uint64_t strtab_off);
std::pair<uint64_t, uint64_t>
write_symtab_global(uint8_t *buf, uint64_t symtab_off, uint64_t strtab_off);
void write_local_symtab(uint8_t *buf, uint64_t symtab_off, uint64_t strtab_off);
void write_global_symtab(uint8_t *buf, uint64_t symtab_off, uint64_t strtab_off);
StringRef get_filename();
bool is_in_archive();
@ -479,8 +476,10 @@ public:
uint32_t priority;
std::atomic_bool is_alive;
uint64_t symtab_size = 0;
uint64_t strtab_size = 0;
uint64_t local_symtab_size = 0;
uint64_t local_strtab_size = 0;
uint64_t global_symtab_size = 0;
uint64_t global_strtab_size = 0;
private:
void initialize_sections();