From 3f5ece9f65256a5c141ae6fdfa50094d88f0dc1d Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Sat, 4 Jan 2025 21:17:39 +0900 Subject: [PATCH] Accept very large input text sections --- src/arch-loongarch.cc | 6 +++--- src/arch-riscv.cc | 6 +++--- src/mold.h | 4 ++-- src/shrink-sections.cc | 8 ++------ 4 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/arch-loongarch.cc b/src/arch-loongarch.cc index e878b0b7a2..e918b30ab7 100644 --- a/src/arch-loongarch.cc +++ b/src/arch-loongarch.cc @@ -876,9 +876,9 @@ void shrink_section(Context &ctx, InputSection &isec, bool use_rvc) { const ElfRel &r = rels[i]; Symbol &sym = *isec.file.symbols[r.r_sym]; - auto remove = [&](u32 d) { - u32 sum = deltas.empty() ? 0 : deltas.back().delta; - deltas.emplace_back((u32)r.r_offset, sum + d); + auto remove = [&](i64 d) { + i64 sum = deltas.empty() ? 0 : deltas.back().delta; + deltas.emplace_back(r.r_offset, sum + d); }; // A R_LARCH_ALIGN relocation refers to the beginning of a nop diff --git a/src/arch-riscv.cc b/src/arch-riscv.cc index a6a2452652..a44b3c8c1b 100644 --- a/src/arch-riscv.cc +++ b/src/arch-riscv.cc @@ -822,9 +822,9 @@ void shrink_section(Context &ctx, InputSection &isec, bool use_rvc) { const ElfRel &r = rels[i]; Symbol &sym = *isec.file.symbols[r.r_sym]; - auto remove = [&](u32 d) { - u32 sum = deltas.empty() ? 0 : deltas.back().delta; - deltas.emplace_back((u32)r.r_offset, sum + d); + auto remove = [&](i64 d) { + i64 sum = deltas.empty() ? 0 : deltas.back().delta; + deltas.emplace_back(r.r_offset, sum + d); }; // Handling R_RISCV_ALIGN is mandatory. diff --git a/src/mold.h b/src/mold.h index 9de6c68e0e..8042dede27 100644 --- a/src/mold.h +++ b/src/mold.h @@ -260,8 +260,8 @@ template struct InputSectionExtras {}; struct RelocDelta { - u32 offset; - u32 delta; + u64 offset : 38; + u64 delta : 26; }; template requires is_riscv || is_loongarch diff --git a/src/shrink-sections.cc b/src/shrink-sections.cc index 48d87bced9..cf16cd966a 100644 --- a/src/shrink-sections.cc +++ b/src/shrink-sections.cc @@ -108,13 +108,9 @@ void shrink_sections(Context &ctx) { // only ~0.04% larger than that of GNU ld), so we don't bother to handle // them. We scan relocations only once here. tbb::parallel_for_each(ctx.objs, [&](ObjectFile *file) { - for (std::unique_ptr> &isec : file->sections) { - if (is_resizable(isec.get())) { - if (isec->sh_size > UINT32_MAX) - Fatal(ctx) << *isec << ": input section too large"; + for (std::unique_ptr> &isec : file->sections) + if (is_resizable(isec.get())) shrink_section(ctx, *isec, use_rvc); - } - } }); // Fix symbol values.