Skip to content

Commit 93bf271

Browse files
committed
[MachO] Shrink reloc from 32 bytes to 24 bytes
The `r_address` field of `relocation_info` is only 4 bytes, so our offset field (which is the `r_address` field adjusted for subsection splitting) also only needs to be 4 bytes. This reduces the structure size from 32 bytes to 24 bytes. Combined with https://reviews.llvm.org/D113813, this is a minor perf improvement for linking an internal app, tested on two machines: ``` smol-relocs baseline difference (95% CI) sys_time 7.367 ± 0.138 7.543 ± 0.157 [ +0.9% .. +3.8%] user_time 21.843 ± 0.351 21.861 ± 0.450 [ -1.3% .. +1.4%] wall_time 20.301 ± 0.307 20.556 ± 0.324 [ +0.1% .. +2.4%] samples 16 16 smol-relocs baseline difference (95% CI) sys_time 2.923 ± 0.050 2.992 ± 0.018 [ +1.4% .. +3.4%] user_time 10.345 ± 0.039 10.448 ± 0.023 [ +0.8% .. +1.2%] wall_time 12.068 ± 0.071 12.229 ± 0.021 [ +1.0% .. +1.7%] samples 15 12 ``` More importantly though, this change by itself reduces our maximum resident set size by 220 MB (2.75%, from 7.85 GB to 7.64 GB) on the first machine. On the second machine, it reduces it by 125 MB (1.94%, from 6.31 GB to 6.19 GB). Reviewed By: #lld-macho, int3 Differential Revision: https://reviews.llvm.org/D113818
1 parent 3195297 commit 93bf271

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

lld/MachO/InputFiles.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,8 +355,9 @@ void ObjFile::parseSections(ArrayRef<SectionHeader> sectionHeaders) {
355355
// any subsection splitting has occurred). It will be updated to represent the
356356
// same location as an offset relative to the start of the containing
357357
// subsection.
358+
template <class T>
358359
static InputSection *findContainingSubsection(Subsections &subsections,
359-
uint64_t *offset) {
360+
T *offset) {
360361
auto it = std::prev(llvm::upper_bound(
361362
subsections, *offset,
362363
[](uint64_t value, Subsection subsec) { return value < subsec.offset; }));

lld/MachO/Relocations.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,16 @@ struct Reloc {
5656
uint8_t length = 0;
5757
// The offset from the start of the subsection that this relocation belongs
5858
// to.
59-
uint64_t offset = 0;
59+
uint32_t offset = 0;
6060
// Adding this offset to the address of the referent symbol or subsection
6161
// gives the destination that this relocation refers to.
6262
int64_t addend = 0;
6363
llvm::PointerUnion<Symbol *, InputSection *> referent = nullptr;
6464
};
6565

66+
static_assert(sizeof(void *) != 8 || sizeof(Reloc) == 24,
67+
"Try to minimize Reloc's size; we create many instances");
68+
6669
bool validateSymbolRelocation(const Symbol *, const InputSection *,
6770
const Reloc &);
6871

0 commit comments

Comments
 (0)