[all-commits] [llvm/llvm-project] 3c357a: [BOLT] Add support for safe-icf (#116275)

Alexander Yermolovich via All-commits all-commits at lists.llvm.org
Mon Dec 16 21:50:14 PST 2024


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 3c357a49d61e4c81a1ac016502ee504521bc8dda
      https://github.com/llvm/llvm-project/commit/3c357a49d61e4c81a1ac016502ee504521bc8dda
  Author: Alexander Yermolovich <43973793+ayermolo at users.noreply.github.com>
  Date:   2024-12-16 (Mon, 16 Dec 2024)

  Changed paths:
    M bolt/docs/CommandLineArgumentReference.md
    M bolt/include/bolt/Core/BinaryFunction.h
    M bolt/include/bolt/Passes/IdenticalCodeFolding.h
    M bolt/lib/Core/BinaryFunction.cpp
    M bolt/lib/Passes/IdenticalCodeFolding.cpp
    M bolt/lib/Rewrite/BinaryPassManager.cpp
    M bolt/lib/Rewrite/BoltDiff.cpp
    M bolt/lib/Rewrite/RewriteInstance.cpp
    A bolt/test/X86/icf-safe-icp.test
    A bolt/test/X86/icf-safe-process-rela-data.test
    A bolt/test/X86/icf-safe-test1-no-relocs.test
    A bolt/test/X86/icf-safe-test1.test
    A bolt/test/X86/icf-safe-test2GlobalConstPtrNoPic.test

  Log Message:
  -----------
  [BOLT] Add support for safe-icf (#116275)

Identical Code Folding (ICF) folds functions that are identical into one
function, and updates symbol addresses to the new address. This reduces
the size of a binary, but can lead to problems. For example when
function pointers are compared. This can be done either explicitly in
the code or generated IR by optimization passes like Indirect Call
Promotion (ICP). After ICF what used to be two different addresses
become the same address. This can lead to a different code path being
taken.

This is where safe ICF comes in. Linker (LLD) does it using address
significant section generated by clang. If symbol is in it, or an object
doesn't have this section symbols are not folded.

BOLT does not have the information regarding which objects do not have
this section, so can't re-use this mechanism.

This implementation scans code section and conservatively marks
functions symbols as unsafe. It treats symbols as unsafe if they are
used in non-control flow instruction. It also scans through the data
relocation sections and does the same for relocations that reference a
function symbol. The latter handles the case when function pointer is
stored in a local or global variable, etc. If a relocation address
points within a vtable these symbols are skipped.



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list