Skip to content

Commit

Permalink
Accept very large input text sections
Browse files Browse the repository at this point in the history
  • Loading branch information
rui314 committed Jan 4, 2025
1 parent 3234d88 commit 3f5ece9
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 14 deletions.
6 changes: 3 additions & 3 deletions src/arch-loongarch.cc
Original file line number Diff line number Diff line change
Expand Up @@ -876,9 +876,9 @@ void shrink_section(Context<E> &ctx, InputSection<E> &isec, bool use_rvc) {
const ElfRel<E> &r = rels[i];
Symbol<E> &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
Expand Down
6 changes: 3 additions & 3 deletions src/arch-riscv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -822,9 +822,9 @@ void shrink_section(Context<E> &ctx, InputSection<E> &isec, bool use_rvc) {
const ElfRel<E> &r = rels[i];
Symbol<E> &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.
Expand Down
4 changes: 2 additions & 2 deletions src/mold.h
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,8 @@ template <typename E>
struct InputSectionExtras {};

struct RelocDelta {
u32 offset;
u32 delta;
u64 offset : 38;
u64 delta : 26;
};

template <typename E> requires is_riscv<E> || is_loongarch<E>
Expand Down
8 changes: 2 additions & 6 deletions src/shrink-sections.cc
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,9 @@ void shrink_sections(Context<E> &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<E> *file) {
for (std::unique_ptr<InputSection<E>> &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<InputSection<E>> &isec : file->sections)
if (is_resizable(isec.get()))
shrink_section(ctx, *isec, use_rvc);
}
}
});

// Fix symbol values.
Expand Down

0 comments on commit 3f5ece9

Please sign in to comment.