From 38ae2990a0ab8e87514b4494d571b0b6c80e102d Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Sun, 5 Jan 2025 13:59:10 +0900 Subject: [PATCH] Refactor --- src/mold.h | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/mold.h b/src/mold.h index 9e387b7f49..b5b04fcbf3 100644 --- a/src/mold.h +++ b/src/mold.h @@ -264,17 +264,21 @@ struct RelocDelta { i64 delta : 26; }; +// RISC-V and LoongArch support code-shrinking linker relaxation. +// +// r_deltas is used to manage the locations where instructions are +// removed from a section. r_deltas is sorted by offset. Each +// RelocDelta indicates that the contents at and after `offset` and up +// to the next RelocDelta location need to be shifted towards the +// beginning of the section by `delta` bytes. +// +// Since code-shrinking relaxation never bloats section contents, +// `delta` increases monotonically within the vector. template requires is_riscv || is_loongarch struct InputSectionExtras { std::vector r_deltas; }; -inline i64 get_removed_bytes(std::span deltas, i64 i) { - if (i == 0) - return deltas[i].delta; - return deltas[i].delta - deltas[i - 1].delta; -} - // InputSection represents a section in an input object file. template class __attribute__((aligned(4))) InputSection { @@ -1567,6 +1571,12 @@ void lto_cleanup(Context &ctx); // shrink-sections.cc // +inline i64 get_removed_bytes(std::span deltas, i64 i) { + if (i == 0) + return deltas[i].delta; + return deltas[i].delta - deltas[i - 1].delta; +} + template void shrink_sections(Context &ctx);