[PATCH] D135494: [BOLT] Section-handling refactoring/overhaul

Maksim Panchenko via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 7 14:49:29 PDT 2022


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

Simplify the logic of handling sections in BOLT. This change brings more
direct and predictable mapping of BinarySection instances to sections in
the input and output files.

- Only sections from the input binary will have a non-null SectionRef. When a new section is created as a copy of the input section, its SectionRef is reset to null.

- RewriteInstance::getOutputSectionName() is removed as the section name in the output file is now defined by BinarySection::getOutputName().

- Querying BinaryContext for sections by name uses their original name. E.g., getUniqueSectionByName(".rodata") will return the original section even if the new .rodata section was created.

- Input file sections (with relocations applied) are emitted via MC with ".bolt.org" prefix. However, their name in the output binary is unchanged unless a new section with the same name is created.

- New sections are emitted internally with ".bolt.new" prefix if there's a name conflict with an input file section. Their original name is preserved in the output file.

- Section header string table is properly populated with section names that are actually used. Previously we used to include discarded section names as well.

- Fix the problem when dynamic relocations were propagated to a new section with a name that matched a section in the input binary. E.g., the new .rodata with jump tables had dynamic relocations from the original .rodata.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D135494

Files:
  bolt/include/bolt/Core/BinaryContext.h
  bolt/include/bolt/Core/BinarySection.h
  bolt/include/bolt/Rewrite/ExecutableFileMemoryManager.h
  bolt/include/bolt/Rewrite/MachORewriteInstance.h
  bolt/include/bolt/Rewrite/RewriteInstance.h
  bolt/lib/Core/BinaryContext.cpp
  bolt/lib/Core/BinaryEmitter.cpp
  bolt/lib/Core/BinarySection.cpp
  bolt/lib/Passes/ReorderData.cpp
  bolt/lib/Rewrite/ExecutableFileMemoryManager.cpp
  bolt/lib/Rewrite/MachORewriteInstance.cpp
  bolt/lib/Rewrite/RewriteInstance.cpp
  bolt/test/X86/dynrelocs.s

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D135494.466192.patch
Type: text/x-patch
Size: 55318 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221007/c0803f97/attachment-0001.bin>


More information about the llvm-commits mailing list