diff --git a/Makefile b/Makefile index f00121fe..867001c6 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ TBB_LIBDIR=$(wildcard $(CURRENT_DIR)/oneTBB/build/linux_intel64_*_release/) CPPFLAGS=-g -IoneTBB/include -pthread -std=c++20 -Wno-deprecated-volatile -O2 LDFLAGS=-L$(TBB_LIBDIR) -Wl,-rpath=$(TBB_LIBDIR) -fuse-ld=lld -pthread -LIBS=-ltbb +LIBS=-ltbb -ltbbmalloc -ltbbmalloc_proxy OBJS=main.o object_file.o input_sections.o output_chunks.o mapfile.o perf.o \ linker_script.o archive_file.o diff --git a/input_sections.cc b/input_sections.cc index 15c7440e..14f5ad7b 100644 --- a/input_sections.cc +++ b/input_sections.cc @@ -49,6 +49,7 @@ void InputSection::copy_buf() { // Apply relocations u8 *base = out::buf + output_section->shdr.sh_offset + offset; + int ref_idx = 0; ElfRela *dynrel = nullptr; if (out::reldyn) @@ -57,10 +58,13 @@ void InputSection::copy_buf() { for (int i = 0; i < rels.size(); i++) { const ElfRela &rel = rels[i]; - StringPieceRef &ref = rel_pieces[i]; Symbol &sym = *file->symbols[rel.r_sym]; u8 *loc = base + rel.r_offset; + const StringPieceRef *ref = nullptr; + if (has_rel_piece[i]) + ref = &rel_pieces[ref_idx++]; + auto write = [&](u64 val) { switch (get_rel_size(rel.r_type)) { case 1: *loc = val; return; @@ -71,8 +75,8 @@ void InputSection::copy_buf() { unreachable(); }; -#define S (ref.piece ? ref.piece->get_addr() : sym.get_addr()) -#define A (ref.piece ? ref.addend : rel.r_addend) +#define S (ref ? ref->piece->get_addr() : sym.get_addr()) +#define A (ref ? ref->addend : rel.r_addend) #define P (output_section->shdr.sh_addr + offset + rel.r_offset) #define L sym.get_plt_addr() #define G (sym.get_got_addr() - out::got->shdr.sh_addr) diff --git a/mold.h b/mold.h index 05d27a19..da01af78 100644 --- a/mold.h +++ b/mold.h @@ -262,6 +262,7 @@ public: void report_undefined_symbols(); std::span rels; + std::vector has_rel_piece; std::vector rel_pieces; std::vector rel_types; u64 reldyn_offset = 0; diff --git a/object_file.cc b/object_file.cc index 5ba7aba2..a393f0b4 100644 --- a/object_file.cc +++ b/object_file.cc @@ -128,7 +128,7 @@ void ObjectFile::initialize_sections() { if (target) { target->rels = get_data(shdr); target->rel_types.resize(target->rels.size()); - target->rel_pieces.resize(target->rels.size()); + target->has_rel_piece.resize(target->rels.size()); if (target->shdr.sh_flags & SHF_ALLOC) { static Counter counter("relocs_alloc"); @@ -270,8 +270,9 @@ void ObjectFile::initialize_mergeable_sections() { if (!ref) error(to_string(this) + ": bad relocation at " + std::to_string(rel.r_sym)); - isec->rel_pieces[i].piece = ref->piece; - isec->rel_pieces[i].addend = offset - ref->input_offset; + isec->rel_pieces.push_back( + {.piece = ref->piece, .addend = (i32)(offset - ref->input_offset)}); + isec->has_rel_piece[i] = true; } } }