From 7547f747401f37c3c035a575c679afbd73534b19 Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Sun, 8 Nov 2020 15:56:17 +0900 Subject: [PATCH] temporary --- input_sections.cc | 1 - mold.h | 4 ++-- object_file.cc | 17 +++++------------ 3 files changed, 7 insertions(+), 15 deletions(-) diff --git a/input_sections.cc b/input_sections.cc index c473064f..af9cf640 100644 --- a/input_sections.cc +++ b/input_sections.cc @@ -158,7 +158,6 @@ void InputSection::scan_relocations() { MergeableSection::MergeableSection(InputSection *isec, ArrayRef contents) : InputChunk(MERGEABLE, isec->file, isec->shdr, isec->name), - original(isec), parent(*MergedSection::get_instance(isec->name, isec->shdr.sh_flags, isec->shdr.sh_type)) { StringRef data((const char *)&contents[0], contents.size()); diff --git a/mold.h b/mold.h index 6a7303f0..e906be37 100644 --- a/mold.h +++ b/mold.h @@ -182,7 +182,7 @@ public: StringRef name; ObjectFile *file = nullptr; - InputChunk *input_section = nullptr; + InputSection *input_section = nullptr; StringPieceRef piece_ref; u64 value = 0; @@ -246,13 +246,13 @@ public: ArrayRef rels; std::vector rel_pieces; + MergeableSection *mergeable = nullptr; }; class MergeableSection : public InputChunk { public: MergeableSection(InputSection *isec, ArrayRef contents); - InputSection *original; MergedSection &parent; std::vector pieces; u32 size = 0; diff --git a/object_file.cc b/object_file.cc index 3246cafd..fb9790df 100644 --- a/object_file.cc +++ b/object_file.cc @@ -185,6 +185,7 @@ void ObjectFile::initialize_mergeable_sections() { if (isec && is_mergeable(isec->shdr)) { ArrayRef contents = CHECK(obj.getSectionContents(isec->shdr), this); mergeable_sections.emplace_back(isec, contents); + isec->mergeable = &mergeable_sections.back(); sections[i] = nullptr; } } @@ -215,21 +216,13 @@ void ObjectFile::initialize_mergeable_sections() { Symbol &sym = *symbols[sym_idx]; if (sym.type != STT_SECTION) continue; - if (!is_mergeable(sym.input_section->shdr)) + + MergeableSection *mergeable = sym.input_section->mergeable; + if (!mergeable) continue; - ArrayRef pieces; - for (MergeableSection &isec : mergeable_sections) { - if (isec.original == sym.input_section) { - pieces = isec.pieces; - break; - } - } - - assert(!pieces.empty()); - u32 offset = sym.value + rel.r_addend; - const StringPieceRef *ref = binary_search(pieces, offset); + const StringPieceRef *ref = binary_search(mergeable->pieces, offset); if (!ref) error(toString(this) + ": bad relocation at " + std::to_string(sym_idx));