[PATCH] D83655: [AsmPrinter] Split up .gcc_except_table

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Jul 12 22:03:00 PDT 2020


MaskRay created this revision.
MaskRay added reviewers: abidh, grimar, jhenderson, jrtc27, psmith.
Herald added subscribers: llvm-commits, luismarques, s.egerton, lenary, PkmX, simoncook, hiraditya, ki.stfu.
Herald added a project: LLVM.

MC currently produces monolithic .gcc_except_table section. GCC can split up .gcc_except_table:

- if comdat: `.section .gcc_except_table._Z6comdatv,"aG", at progbits,_Z6comdatv,comdat`
- otherwise, if -ffunction-sections: `.section .gcc_except_table._Z3fooi,"a", at progbits`

This ensures that (a) non-prevailing copies are discarded and (b)
.gcc_except_table associated to discarded text sections can be discarded by a
.gcc_except_table-aware linker (GNU ld, but not gold or LLD)

This patches matches the behavior and strengthens it by leveraging
SHF_LINK_ORDER (if integrated assembler) to make (b) work with
.gcc_except_table-unaware linkers (LLD). SHF_LINK_ORDER is a binutils
2.35 (not released yet) feature, so we don't use it for clang -fno-integrated-as.
GCC appends a suffix to ".gcc_except_table", but this just wastes .strtab space,
so we simply use the same string (i.e. as if -fno-unique-section-names
is specified).

For RISC-V -mrelax, this patch additionally fixes an assembler-linker
interaction problem: because a section is shrinkable, the length of a call-site
code range is not a constant. Relocations referencing the associated text
section (STT_SECTION) are needed. However, a STB_LOCAL relocation referencing a
discarded section group member from outside the group is disallowed by the ELF
specification (PR46675):

  // a.cc
  inline int comdat() { try { throw 1; } catch (int) { return 1; } return 0; }
  int main() { return comdat(); }
  
  // b.cc
  inline int comdat() { try { throw 1; } catch (int) { return 1; } return 0; }
  int foo() { return comdat(); }
  
  clang++ -target riscv64-linux -c a.cc b.cc -fPIC
  ld.lld -shared a.o b.o => ld.lld: error: relocation refers to a symbol in a discarded section:


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D83655

Files:
  llvm/lib/CodeGen/AsmPrinter/EHStreamer.cpp
  llvm/test/CodeGen/X86/gcc_except_table-multi.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D83655.277326.patch
Type: text/x-patch
Size: 4281 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200713/5e1161d5/attachment.bin>


More information about the llvm-commits mailing list