[PATCH] D85785: [ELF] -r: allow section type 0x70000001 (SHT_X86_64_UNWIND) to be merged into SHT_PROGBITS

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 11 14:24:12 PDT 2020


MaskRay created this revision.
MaskRay added reviewers: craig.topper, grimar, psmith.
Herald added subscribers: llvm-commits, fedor.sergeev, kristof.beyls, arichardson, emaste.
Herald added a reviewer: espindola.
Herald added a project: LLVM.
MaskRay requested review of this revision.

- For .cfi_*, GCC/GNU as emits SHT_PROGBITS type .eh_frame sections.
- Since rL252300 <https://reviews.llvm.org/rL252300>, clang emits SHT_X86_64_UNWIND type .eh_frame sections (originated from Solaris, documented in the x86-64 psABI).
- Some assembly use `.section .eh_frame,"a", at unwind` to generate SHT_X86_64_UNWIND .eh_frame sections.

In a non-relocatable link, input .eh_frame are combined and there is
only one SyntheticSection .eh_frame in the output section, so the
"section type mismatch" diagnostic does not fire.

In a relocatable link, there is no SyntheticSection .eh_frame. .eh_frame of
mixed types can trigger the diagnostic. This patch fixes it by adding another
special case 0x70000001 (= SHT_X86_64_UNWIND) to canMergeToProgbits().

  ld.lld -r gcc.o clang.o => error: section type mismatch for .eh_frame

There was a discussion "RFC: Usefulness of SHT_X86_64_UNWIND" on the x86-64-abi
mailing list. Folks are not wild about making the psABI value 0x70000001 into
gABI, but a few think defining 0x70000001 for .eh_frame may be a good idea for a
new architecture. There is little cost losing the "section type mismatch"
diagnostic for other architectures, so we don't bother checking e_machine.

NOTE: ARM (SHT_ARM_EXIDX) is the only other architecture LLD supports
sharing the psABI value 0x70000001.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D85785

Files:
  lld/ELF/OutputSections.cpp
  lld/test/ELF/eh-frame-type.test


Index: lld/test/ELF/eh-frame-type.test
===================================================================
--- lld/test/ELF/eh-frame-type.test
+++ lld/test/ELF/eh-frame-type.test
@@ -11,6 +11,9 @@
 # RUN: ld.lld %t1.o %t2.o -o %tboth
 # RUN: llvm-readobj -S %tboth | FileCheck %s
 
+# RUN: ld.lld -r %t1.o %t2.o -o %tboth.ro
+# RUN: llvm-readobj -S %tboth.ro | FileCheck %s
+
 # CHECK:      Name: .eh_frame
 # CHECK-NEXT: Type: SHT_PROGBITS
 
Index: lld/ELF/OutputSections.cpp
===================================================================
--- lld/ELF/OutputSections.cpp
+++ lld/ELF/OutputSections.cpp
@@ -78,10 +78,16 @@
 // to be allocated for nobits sections. Other ones don't require
 // any special treatment on top of progbits, so there doesn't
 // seem to be a harm in merging them.
+//
+// NOTE: The 0x70000001 condition allows SHT_X86_64_UNWIND .eh_frame (clang
+// since rL252300) to be merged into SHT_PROGBITS .eh_frame (GNU as .cfi_).
+// While SHT_ARM_EXIDX = SHT_X86_64_UNWIND = SHT_IA_64_UNWIND, some
+// architectures may define 0x70000001 for other purposes. The loose condition
+// just drops a diagnostic in an edge case.
 static bool canMergeToProgbits(unsigned type) {
   return type == SHT_NOBITS || type == SHT_PROGBITS || type == SHT_INIT_ARRAY ||
          type == SHT_PREINIT_ARRAY || type == SHT_FINI_ARRAY ||
-         type == SHT_NOTE;
+         type == SHT_NOTE || type == 0x70000001;
 }
 
 // Record that isec will be placed in the OutputSection. isec does not become


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D85785.284895.patch
Type: text/x-patch
Size: 1505 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200811/26f77f73/attachment.bin>


More information about the llvm-commits mailing list