[lld] 93bf271 - [MachO] Shrink reloc from 32 bytes to 24 bytes

Shoaib Meenai via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 16 16:31:08 PST 2021


Author: Shoaib Meenai
Date: 2021-11-16T16:30:34-08:00
New Revision: 93bf271f27439d133616815266b50db4a294e118

URL: https://github.com/llvm/llvm-project/commit/93bf271f27439d133616815266b50db4a294e118
DIFF: https://github.com/llvm/llvm-project/commit/93bf271f27439d133616815266b50db4a294e118.diff

LOG: [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

Added: 
    

Modified: 
    lld/MachO/InputFiles.cpp
    lld/MachO/Relocations.h

Removed: 
    


################################################################################
diff  --git a/lld/MachO/InputFiles.cpp b/lld/MachO/InputFiles.cpp
index 893bf26775ab..9fb6cd3bf265 100644
--- a/lld/MachO/InputFiles.cpp
+++ b/lld/MachO/InputFiles.cpp
@@ -355,8 +355,9 @@ void ObjFile::parseSections(ArrayRef<SectionHeader> sectionHeaders) {
 // any subsection splitting has occurred). It will be updated to represent the
 // same location as an offset relative to the start of the containing
 // subsection.
+template <class T>
 static InputSection *findContainingSubsection(Subsections &subsections,
-                                              uint64_t *offset) {
+                                              T *offset) {
   auto it = std::prev(llvm::upper_bound(
       subsections, *offset,
       [](uint64_t value, Subsection subsec) { return value < subsec.offset; }));

diff  --git a/lld/MachO/Relocations.h b/lld/MachO/Relocations.h
index 91b2d00f26a1..57ffcf858f52 100644
--- a/lld/MachO/Relocations.h
+++ b/lld/MachO/Relocations.h
@@ -56,13 +56,16 @@ struct Reloc {
   uint8_t length = 0;
   // The offset from the start of the subsection that this relocation belongs
   // to.
-  uint64_t offset = 0;
+  uint32_t offset = 0;
   // Adding this offset to the address of the referent symbol or subsection
   // gives the destination that this relocation refers to.
   int64_t addend = 0;
   llvm::PointerUnion<Symbol *, InputSection *> referent = nullptr;
 };
 
+static_assert(sizeof(void *) != 8 || sizeof(Reloc) == 24,
+              "Try to minimize Reloc's size; we create many instances");
+
 bool validateSymbolRelocation(const Symbol *, const InputSection *,
                               const Reloc &);
 


        


More information about the llvm-commits mailing list