[PATCH] D97755: [IRSymTab] Set FB_used on llvm.compiler.used symbols

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 2 00:39:54 PST 2021


MaskRay created this revision.
MaskRay added a reviewer: tejohnson.
Herald added subscribers: steven_wu, hiraditya.
MaskRay requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

LTO IR symbol table does not track references in inline asm, so we may
not know that a symbol defined in another translation unit is
referenced. That definition may have `__attribute__((used))` (which lowers to
`llvm.compiler.used` on ELF targets since D97446 <https://reviews.llvm.org/D97446>) to communicate to the compiler that it
may be used by inline asm.

  // cabac.c
  __attribute__((used)) const uint8_t ff_h264_cabac_tables[...] = {...};
  
  // h264_cabac.c
    asm("lea ff_h264_cabac_tables(%rip), %0" : ...);

`__attribute__((used))` is the recommended way for inline asm "hidden"
references, so the usage is perfectly fine. This patch conservatively
sets the `FB_used` bit on `llvm.compiler.used` symbols to work around
our own limitation. Note: before D97446 <https://reviews.llvm.org/D97446>, Clang never emitted symbols in
the `llvm.compiler.used` list, so this change does not punish any Clang
emitted global object.

Without the patch, `ff_h264_cabac_tables` may be assigned to a
non-external partition and get internalized. Then we will get a linker
error because the `cabac.c` definition is not exposed.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D97755

Files:
  llvm/lib/LTO/LTO.cpp
  llvm/lib/Object/IRSymtab.cpp
  llvm/test/ThinLTO/X86/asm.ll
  llvm/test/tools/gold/X86/emit-llvm.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D97755.327375.patch
Type: text/x-patch
Size: 4569 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210302/45b84503/attachment.bin>


More information about the llvm-commits mailing list