1
1
mirror of https://github.com/rui314/mold.git synced 2024-12-27 18:34:15 +03:00

temporary

This commit is contained in:
Rui Ueyama 2020-11-06 08:49:41 +09:00
parent 851415fdc9
commit bed207a4ec
5 changed files with 52 additions and 36 deletions

View File

@ -7,7 +7,7 @@ LLVM_LIBS=$(wildcard llvm-project/build/lib/libLLVM*.a)
CURRENT_DIR=$(shell pwd) CURRENT_DIR=$(shell pwd)
TBB_LIBDIR=$(wildcard $(CURRENT_DIR)/oneTBB/build/linux_intel64_*_release/) TBB_LIBDIR=$(wildcard $(CURRENT_DIR)/oneTBB/build/linux_intel64_*_release/)
CPPFLAGS=-g $(shell $(LLVM_CONFIG) --cxxflags) -IoneTBB/include -pthread -std=c++17 CPPFLAGS=-g $(shell $(LLVM_CONFIG) --cxxflags) -IoneTBB/include -pthread -std=c++17 -O2
LDFLAGS=$(shell $(LLVM_CONFIG) --ldflags) -L$(TBB_LIBDIR) -Wl,-rpath=$(TBB_LIBDIR) -fuse-ld=lld LDFLAGS=$(shell $(LLVM_CONFIG) --ldflags) -L$(TBB_LIBDIR) -Wl,-rpath=$(TBB_LIBDIR) -fuse-ld=lld
LIBS=-pthread -ltbb -lcurses -Wl,--start-group $(LLVM_LIBS) -Wl,--end-group LIBS=-pthread -ltbb -lcurses -Wl,--start-group $(LLVM_LIBS) -Wl,--end-group
OBJS=main.o object_file.o input_sections.o output_chunks.o mapfile.o perf.o OBJS=main.o object_file.o input_sections.o output_chunks.o mapfile.o perf.o

View File

@ -24,7 +24,9 @@ void InputSection::copy_to(u8 *buf) {
memcpy(buf, &data[0], data.size()); memcpy(buf, &data[0], data.size());
} }
void InputSection::scan_relocations() { ScanRelResult InputSection::scan_relocations() {
ScanRelResult res;
for (const ELF64LE::Rela &rel : rels) { for (const ELF64LE::Rela &rel : rels) {
Symbol *sym = file->symbols[rel.getSymbol(false)]; Symbol *sym = file->symbols[rel.getSymbol(false)];
if (!sym->file || !sym->file->is_alive) if (!sym->file || !sym->file->is_alive)
@ -43,7 +45,7 @@ void InputSection::scan_relocations() {
std::lock_guard lock(sym->mu); std::lock_guard lock(sym->mu);
if (!sym->needs_got) { if (!sym->needs_got) {
sym->needs_got = true; sym->needs_got = true;
file->num_got++; res.num_got++;
} }
break; break;
} }
@ -51,7 +53,7 @@ void InputSection::scan_relocations() {
std::lock_guard lock(sym->mu); std::lock_guard lock(sym->mu);
if (!sym->needs_gottp) { if (!sym->needs_gottp) {
sym->needs_gottp = true; sym->needs_gottp = true;
file->num_got++; res.num_got++;
} }
break; break;
} }
@ -62,14 +64,15 @@ void InputSection::scan_relocations() {
std::lock_guard lock(sym->mu); std::lock_guard lock(sym->mu);
if (!sym->needs_plt) { if (!sym->needs_plt) {
sym->needs_plt = true; sym->needs_plt = true;
file->num_plt++; res.num_plt++;
file->num_gotplt++; res.num_gotplt++;
file->num_relplt++; res.num_relplt++;
} }
break; break;
} }
} }
} }
return res;
} }
void InputSection::relocate(u8 *buf) { void InputSection::relocate(u8 *buf) {

34
main.cc
View File

@ -232,26 +232,22 @@ static void set_isec_offsets() {
} }
static void scan_rels(ArrayRef<ObjectFile *> files) { static void scan_rels(ArrayRef<ObjectFile *> files) {
std::atomic_int32_t num_got = 0; ScanRelResult res =
std::atomic_int32_t num_gotplt = 0; tbb::parallel_reduce(tbb::blocked_range<int>(0, files.size()),
std::atomic_int32_t num_plt = 0; ScanRelResult(),
std::atomic_int32_t num_relplt = 0; [&](const tbb::blocked_range<int> &r, ScanRelResult res) {
for (int i = r.begin(); i != r.end(); i++)
res = res.add(files[i]->scan_relocations());
return res;
},
[](const ScanRelResult &x, const ScanRelResult &y) {
return x.add(y);
});
for_each(files, [&](ObjectFile *file) { out::got->shdr.sh_size = res.num_got * 8;
for (InputSection *isec : file->sections) out::gotplt->shdr.sh_size = res.num_gotplt * 8;
if (isec) out::plt->shdr.sh_size = res.num_plt * 16;
isec->scan_relocations(); out::relplt->shdr.sh_size = res.num_relplt * sizeof(ELF64LE::Rela);
num_got += file->num_got;
num_gotplt += file->num_gotplt;
num_plt += file->num_plt;
num_relplt += file->num_relplt;
});
out::got->shdr.sh_size = num_got * 8;
out::gotplt->shdr.sh_size = num_gotplt * 8;
out::plt->shdr.sh_size = num_plt * 16;
out::relplt->shdr.sh_size = num_relplt * sizeof(ELF64LE::Rela);
} }
static void assign_got_offsets(u8 *buf, ArrayRef<ObjectFile *> files) { static void assign_got_offsets(u8 *buf, ArrayRef<ObjectFile *> files) {

27
mold.h
View File

@ -12,6 +12,7 @@
#include "tbb/concurrent_hash_map.h" #include "tbb/concurrent_hash_map.h"
#include "tbb/global_control.h" #include "tbb/global_control.h"
#include "tbb/parallel_for_each.h" #include "tbb/parallel_for_each.h"
#include "tbb/parallel_reduce.h"
#include "tbb/spin_mutex.h" #include "tbb/spin_mutex.h"
#include "tbb/task_group.h" #include "tbb/task_group.h"
@ -193,16 +194,30 @@ inline std::string toString(Symbol sym) {
} }
// //
// input_chunks.cc // input_sections.cc
// //
struct ScanRelResult {
ScanRelResult add(const ScanRelResult &other) const {
return {num_got + other.num_got,
num_gotplt + other.num_gotplt,
num_plt + other.num_plt,
num_relplt + other.num_relplt};
}
u32 num_got = 0;
u32 num_gotplt = 0;
u32 num_plt = 0;
u32 num_relplt = 0;
};
class InputSection { class InputSection {
public: public:
InputSection(ObjectFile *file, const ELF64LE::Shdr &shdr, StringRef name); InputSection(ObjectFile *file, const ELF64LE::Shdr &shdr, StringRef name);
void copy_to(u8 *buf); void copy_to(u8 *buf);
void relocate(u8 *buf); void relocate(u8 *buf);
void scan_relocations(); ScanRelResult scan_relocations();
ObjectFile *file; ObjectFile *file;
OutputSection *output_section; OutputSection *output_section;
@ -498,6 +513,7 @@ public:
void hanlde_undefined_weak_symbols(); void hanlde_undefined_weak_symbols();
void eliminate_duplicate_comdat_groups(); void eliminate_duplicate_comdat_groups();
void convert_common_symbols(); void convert_common_symbols();
ScanRelResult scan_relocations();
void fix_sym_addrs(); void fix_sym_addrs();
void compute_symtab(); void compute_symtab();
@ -522,13 +538,6 @@ public:
u64 global_symtab_size = 0; u64 global_symtab_size = 0;
u64 global_strtab_size = 0; u64 global_strtab_size = 0;
// Number of .got, .got.plt, .plt and .rel.plt entries
// needed for this file.
i32 num_got = 0;
i32 num_gotplt = 0;
i32 num_plt = 0;
i32 num_relplt = 0;
private: private:
void initialize_sections(); void initialize_sections();
void initialize_symbols(); void initialize_symbols();

View File

@ -401,6 +401,14 @@ void ObjectFile::convert_common_symbols() {
} }
} }
ScanRelResult ObjectFile::scan_relocations() {
ScanRelResult res;
for (InputSection *isec : sections)
if (isec)
res = res.add(isec->scan_relocations());
return res;
}
void ObjectFile::fix_sym_addrs() { void ObjectFile::fix_sym_addrs() {
for (Symbol *sym : symbols) { for (Symbol *sym : symbols) {
if (sym->file != this) if (sym->file != this)