Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
rui314 committed Jan 5, 2025
1 parent e6345d5 commit 38ae299
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/mold.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <typename E> requires is_riscv<E> || is_loongarch<E>
struct InputSectionExtras<E> {
std::vector<RelocDelta> r_deltas;
};

inline i64 get_removed_bytes(std::span<RelocDelta> 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 <typename E>
class __attribute__((aligned(4))) InputSection {
Expand Down Expand Up @@ -1567,6 +1571,12 @@ void lto_cleanup(Context<E> &ctx);
// shrink-sections.cc
//

inline i64 get_removed_bytes(std::span<RelocDelta> deltas, i64 i) {
if (i == 0)
return deltas[i].delta;
return deltas[i].delta - deltas[i - 1].delta;
}

template <typename E>
void shrink_sections(Context<E> &ctx);

Expand Down

0 comments on commit 38ae299

Please sign in to comment.