[PATCH] D155604: [BOLT] Calculate input to output address map using BOLTLinker

Job Noorman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 18 08:25:10 PDT 2023


jobnoorman created this revision.
jobnoorman added reviewers: rafauler, maksfb, yota9, Amir.
Herald added subscribers: asb, treapster, pmatos, ayermolo.
Herald added a project: All.
jobnoorman requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

BOLT uses MCAsmLayout to calculate the output values of basic blocks.
This means output values are calculated based on a pre-linking state and
any changes to symbol values during linking will cause incorrect values
to be used.

This issue was first addressed in D154604 <https://reviews.llvm.org/D154604> by adding all basic block
symbols to the symbol table for the linker to resolve them. However, the
runtime overhead of handling this huge symbol table turned out to be
prohibitively large.

This patch solves the issue in a different way. First, a temporary
section containing [input address, output symbol] pairs is emitted to the
intermediary object file. The linker will resolve all these references
so we end up with a section of [input address, output address] pairs.
This section is then parsed and used to:

- Replace BinaryBasicBlock::OffsetTranslationTable
- Replace BinaryFunction::InputOffsetToAddressMap
- Update BinaryBasicBlock::OutputAddressRange

Note that the reason this is more performant than the previous attempt
is that these symbol references do not cause entries to be added to the
symbol table. Instead, section-relative references are used for the
relocations.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D155604

Files:
  bolt/include/bolt/Core/AddressMap.h
  bolt/include/bolt/Core/BinaryBasicBlock.h
  bolt/include/bolt/Core/BinaryContext.h
  bolt/include/bolt/Core/BinaryFunction.h
  bolt/include/bolt/Profile/BoltAddressTranslation.h
  bolt/include/bolt/Rewrite/RewriteInstance.h
  bolt/lib/Core/AddressMap.cpp
  bolt/lib/Core/BinaryBasicBlock.cpp
  bolt/lib/Core/BinaryFunction.cpp
  bolt/lib/Core/CMakeLists.txt
  bolt/lib/Profile/BoltAddressTranslation.cpp
  bolt/lib/Rewrite/PseudoProbeRewriter.cpp
  bolt/lib/Rewrite/RewriteInstance.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D155604.541549.patch
Type: text/x-patch
Size: 17428 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230718/d934d870/attachment.bin>


More information about the llvm-commits mailing list