Page MenuHomePhabricator

[ELF] -r: allow SHT_X86_64_UNWIND to be merged into SHT_PROGBITS
ClosedPublic

Authored by MaskRay on Aug 11 2020, 2:24 PM.

Details

Summary
  • For .cfi_*, GCC/GNU as emits SHT_PROGBITS type .eh_frame sections.
  • Since 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",@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.

Diff Detail

Event Timeline

MaskRay created this revision.Aug 11 2020, 2:24 PM
MaskRay requested review of this revision.Aug 11 2020, 2:24 PM
skan added a subscriber: skan.Aug 11 2020, 6:43 PM

I think this should be ok for .ARM.exidx sections as they have a SHF_LINK_ORDER dependency which prevents them from being merged in relocatable links.

grimar added a comment.EditedAug 12 2020, 3:46 AM

There is little cost losing the "section type mismatch" diagnostic for other architectures, so we don't bother checking e_machine

Is there any reason why you don't want to check the e_machine to make the code more readable, straightforward and
don't lose the "section type mismatch" diagnostic?

There is little cost losing the "section type mismatch" diagnostic for other architectures, so we don't bother checking e_machine

Is there any reason why you don't want to check the e_machine to make the code more readable, straightforward and
don't lose the "section type mismatch" diagnostic?

Because I don't think the "section type mismatch" diagnostic is useful for any SHT_*_UNWIND.

However, given the previous comment about SHT_ARM_EXIDX, I think checking config->e_machine may be fine.

MaskRay updated this revision to Diff 285248.Aug 12 2020, 8:14 PM
MaskRay edited the summary of this revision. (Show Details)

Check emachine

grimar accepted this revision.Aug 13 2020, 1:57 AM

LGTM

This revision is now accepted and ready to land.Aug 13 2020, 1:57 AM
MaskRay retitled this revision from [ELF] -r: allow section type 0x70000001 (SHT_X86_64_UNWIND) to be merged into SHT_PROGBITS to [ELF] -r: allow SHT_X86_64_UNWIND to be merged into SHT_PROGBITS.Aug 13 2020, 8:14 AM
MaskRay added a subscriber: hans.Aug 25 2020, 3:58 PM

@hans This is a good candidate for release/11.x

hans added a comment.Aug 26 2020, 8:03 AM

@hans This is a good candidate for release/11.x

Okay, 04d70cd0f07dab371abf586627ce9ac09e04362c.