[PATCH] D104177: [lld-macho] Remove InputSection::outSecFileOff

Jez Ng via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 11 23:38:12 PDT 2021


int3 created this revision.
int3 added a reviewer: lld-macho.
Herald added a reviewer: gkm.
Herald added a project: lld-macho.
int3 requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

`outSecFileOff` and the associated `getFileOffset()` accessors were
unnecessary.

For all the cases we care about, `outSecFileOff` is the same as
`outSecOff`. The only time they deviate is if there are zerofill
sections within a given segment. But since zerofill sections are always
at the end of a segment, the only sections where the two values deviate
are zerofill sections themselves. And we never actually query the
outSecFileOff of zerofill sections.

As for `getFileOffset()`, the only place it was being used was to
calculate the offset of the entry symbol. However, we can compute that
value by just taking the difference between the address of the entry
symbol and the address of the Mach-O header. In fact, this appears to be
what ld64 itself does. This difference is the same as the file offset as
long as there are no intervening zerofill sections, but since `__text`
is the first section in `__TEXT`, this never happens, so our previous
use of `getFileOffset()` was not wrong -- just inefficient.

In addition to simplifying the code, it's a decent perf win. Numbers for
linking chromium_framework on my 3.2 GHz 16-Core Intel Xeon W:

      N           Min           Max        Median           Avg        Stddev
  x  20          4.89          5.03          4.92        4.9365     0.0405586
  +  20          4.83          4.97          4.88        4.8825   0.039851699
  Difference at 95.0% confidence
          -0.054 +/- 0.0257341
          -1.09389% +/- 0.521303%
          (Student's t, pooled s = 0.0402067)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D104177

Files:
  lld/MachO/ConcatOutputSection.cpp
  lld/MachO/InputSection.cpp
  lld/MachO/InputSection.h
  lld/MachO/Symbols.cpp
  lld/MachO/Symbols.h
  lld/MachO/UnwindInfoSection.cpp
  lld/MachO/Writer.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D104177.351641.patch
Type: text/x-patch
Size: 6538 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210612/9bc63eab/attachment.bin>


More information about the llvm-commits mailing list