[PATCH] D102570: RFC: [ELF] -Bsymbolic-global-functions

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat May 15 23:02:44 PDT 2021


MaskRay created this revision.
MaskRay added reviewers: grimar, jhenderson, peter.smith, smeenai.
Herald added subscribers: dang, arichardson, emaste.
MaskRay requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

This option is a subset of -Bsymbolic-functions. It applies to STB_GLOBAL
STT_FUNC definitions.

The address of an inline function (STB_WEAK STT_FUNC) seen by a
-Bsymbolic-functions linked shared object may be different from the address seen
from outside the shared object. Such cases are rare. (Windows link.exe enables
identical COMDAT folding (/OPT:ICF) by default. ELF/Mach-O programs may use
-fvisibility-inlines-hidden. Both break such pointer equality.)

  // a.cc -> a.o -> a.so (-Bsymbolic-functions)
  inline void f() {}
  void *g() { return (void *)&f; }
  
  // b.cc -> b.o -> exe
  // The address is different!
  inline void f() {}

-Bsymbolic-global-functions is a safer (C++ conforming) subset of
-Bsymbolic-functions. I believe the option can make ELF behavior closer to
Mach-O.

binutils feature request: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100593

Longer write-up: https://maskray.me/blog/2021-05-16-elf-interposition-and-bsymbolic


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D102570

Files:
  lld/ELF/Config.h
  lld/ELF/Driver.cpp
  lld/ELF/Options.td
  lld/ELF/Symbols.cpp
  lld/ELF/SyntheticSections.cpp
  lld/docs/ReleaseNotes.rst
  lld/docs/ld.lld.1
  lld/test/ELF/bsymbolic.s

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D102570.345673.patch
Type: text/x-patch
Size: 9931 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210516/b476a1d0/attachment.bin>


More information about the llvm-commits mailing list