llvm-project/llvm/lib/CodeGen/AsmPrinter
Fangrui Song ee5d1a0449 [AsmPrinter] Split up .gcc_except_table
MC currently produces monolithic .gcc_except_table section. GCC can split up .gcc_except_table:

* if comdat: `.section .gcc_except_table._Z6comdatv,"aG",@progbits,_Z6comdatv,comdat`
* otherwise, if -ffunction-sections: `.section .gcc_except_table._Z3fooi,"a",@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 GCC behavior. If -fno-unique-section-names is
specified, we don't append the suffix. If -ffunction-sections is additionally specified,
use `.section ...,unique`.

Note, if clang driver communicates that the linker is LLD and we know it
is new (11.0.0 or later) we can use SHF_LINK_ORDER to avoid string table
costs, at least in the -fno-unique-section-names case. We cannot use it on GNU
ld because as of binutils 2.35 it does not support mixed SHF_LINK_ORDER &
non-SHF_LINK_ORDER components in an output section
https://sourceware.org/bugzilla/show_bug.cgi?id=26256

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 -mno-relax
ld.lld -shared a.o b.o => ld.lld: error: relocation refers to a symbol in a discarded section:
```

-fbasic-block-sections= is similar to RISC-V -mrelax: there are outstanding relocations.

Reviewed By: jrtc27, rahmanl

Differential Revision: https://reviews.llvm.org/D83655
2020-11-02 14:36:25 -08:00
..
ARMException.cpp [MC] De-capitalize another set of MCStreamer::Emit* functions 2020-02-14 19:26:52 -08:00
AccelTable.cpp [DebugInfo] Make offsets of dwarf units 64-bit (19/19). 2020-09-15 12:23:32 +07:00
AddressPool.cpp [DebugInfo] Fix emitting DWARF64 .debug_addr sections (15/19). 2020-09-15 12:23:31 +07:00
AddressPool.h Recommit "PR44685: DebugInfo: Handle address-use-invalid type units referencing non-type units" 2020-08-18 13:43:28 -07:00
AsmPrinter.cpp Explicitly check for entry basic block, rather than relying on MachineBasicBlock::pred_empty. 2020-10-26 16:15:56 -07:00
AsmPrinterDwarf.cpp [DebugInfo] Add new emitting methods for values which depend on the DWARF format (3/19). 2020-09-15 11:30:10 +07:00
AsmPrinterInlineAsm.cpp Reduce the number of memory allocations when displaying 2020-09-07 17:04:00 +01:00
ByteStreamer.h [AsmPrinter] De-capitalize some AsmPrinter::Emit* functions 2020-02-13 13:38:33 -08:00
CMakeLists.txt [cmake] Explicitly mark libraries defined in lib/ as "Component Libraries" 2019-11-21 10:48:08 -08:00
CodeViewDebug.cpp [CodeView] Encode signed int values correctly when emitting S_CONSTANTs 2020-10-30 09:28:41 -07:00
CodeViewDebug.h Recommit "[CodeView] Emit static data members as S_CONSTANTs." 2020-10-28 16:35:59 -07:00
DIE.cpp [DebugInfo] Simplify DIEInteger::SizeOf(). 2020-09-17 12:47:38 +07:00
DIEHash.cpp DebugInfo: Hash DIE referevences (DW_OP_convert) when computing Split DWARF signatures 2020-10-22 20:09:33 -07:00
DIEHash.h DebugInfo: Hash DIE referevences (DW_OP_convert) when computing Split DWARF signatures 2020-10-22 20:09:33 -07:00
DIEHashAttributes.def
DbgEntityHistoryCalculator.cpp [NFC] Set return type of getStackPointerRegisterToSaveRestore to Register 2020-10-21 16:19:38 -07:00
DebugHandlerBase.cpp Recommit "[CodeView] Emit static data members as S_CONSTANTs." 2020-10-28 16:35:59 -07:00
DebugLocEntry.h [NFCI] Removed an un-used declaration got accidentally introduced in f91d18eaa9 2020-09-01 15:59:04 +05:30
DebugLocStream.cpp hwasan: add tag_offset DWARF attribute to optimized debug info 2019-12-12 16:18:54 -08:00
DebugLocStream.h hwasan: add tag_offset DWARF attribute to optimized debug info 2019-12-12 16:18:54 -08:00
DwarfCFIException.cpp Exception support for basic block sections 2020-09-30 11:05:55 -07:00
DwarfCompileUnit.cpp [DebugInfo] Support for DW_TAG_generic_subrange 2020-10-29 01:34:15 +05:30
DwarfCompileUnit.h [DebugInfo] Fix emitting DWARF64 compilation units (5/19). 2020-09-15 11:30:30 +07:00
DwarfDebug.cpp [WebAssembly] Add support for DWARF type units 2020-10-28 17:41:22 -07:00
DwarfDebug.h DWARFv5: Disable DW_OP_convert for configurations that don't yet support it 2020-10-22 12:02:33 -07:00
DwarfException.h Call Frame Information (CFI) Handling for Basic Block Sections 2020-07-14 12:54:12 -07:00
DwarfExpression.cpp [DebugInfo] [NFCI] Adding a missed out line in support for DW_TAG_generic_subrange. 2020-10-29 16:18:20 +05:30
DwarfExpression.h Revert "[DebugInfo] Fix legacy ZExt emission when FromBits >= 64 (PR47927)" 2020-10-28 18:57:17 -07:00
DwarfFile.cpp DwarfFile.h - remove unnecessary includes. NFCI. 2020-09-17 12:12:18 +01:00
DwarfFile.h DwarfFile.h - remove unnecessary includes. NFCI. 2020-09-17 12:12:18 +01:00
DwarfStringPool.cpp DwarfStringPool.cpp - remove unnecessary StringRef include. NFCI. 2020-09-17 12:18:27 +01:00
DwarfStringPool.h [DebugInfo] Make the offset of string pool entries 64-bit (18/19). 2020-09-15 12:23:32 +07:00
DwarfUnit.cpp Recommit "[CodeView] Emit static data members as S_CONSTANTs." 2020-10-28 16:35:59 -07:00
DwarfUnit.h [DebugInfo] Support for DW_TAG_generic_subrange 2020-10-29 01:34:15 +05:30
EHStreamer.cpp [AsmPrinter] Split up .gcc_except_table 2020-11-02 14:36:25 -08:00
EHStreamer.h Exception support for basic block sections 2020-09-30 11:05:55 -07:00
ErlangGCPrinter.cpp [AsmPrinter] De-capitalize all AsmPrinter::Emit* but EmitInstruction 2020-02-13 17:06:24 -08:00
LLVMBuild.txt
OcamlGCPrinter.cpp [MCStreamer] De-capitalize EmitValue EmitIntValue{,InHex} 2020-02-14 23:08:40 -08:00
WasmException.cpp Exception support for basic block sections 2020-09-30 11:05:55 -07:00
WasmException.h Exception support for basic block sections 2020-09-30 11:05:55 -07:00
WinCFGuard.cpp Reland [CFGuard] Add address-taken IAT tables and delay-load support 2020-10-13 13:20:52 -07:00
WinCFGuard.h Add Windows Control Flow Guard checks (/guard:cf). 2019-10-28 15:19:39 +00:00
WinException.cpp Rename EHPersonality::MSVC_Win64SEH to EHPersonality::MSVC_TableSEH. NFC. 2020-10-27 23:22:13 -07:00
WinException.h [AsmPrinter] Remove unused forward declarations. NFC. 2020-04-22 14:01:52 +01:00