This is an archive of the discontinued LLVM Phabricator instance.

[lld-macho] Support EH frames under arm64
ClosedPublic

Authored by int3 on Apr 27 2022, 3:05 PM.

Details

Summary

For arm64, llvm-mc emits relocations for the target function
address like so:

ltmp:
  <CIE start>
  ...
  <CIE end>
  ... multiple FDEs ...
  <FDE start>
  <target function address - (ltmp + pcrel offset)>
  ...

If any of the FDEs in multiple FDEs get dead-stripped, then FDE start
will move to an earlier address, and ltmp + pcrel offset will no longer
reflect an accurate pcrel value. To avoid this problem, we "canonicalize"
our relocation by adding an EH_Frame symbol at FDE start, and updating
the reloc to be target function address - (EH_Frame + new pcrel offset).

Diff Detail

Event Timeline

int3 created this revision.Apr 27 2022, 3:05 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptApr 27 2022, 3:05 PM
int3 requested review of this revision.Apr 27 2022, 3:05 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 27 2022, 3:05 PM
Roger accepted this revision.May 4 2022, 10:10 AM
This revision is now accepted and ready to land.May 4 2022, 10:10 AM
This revision was landed with ongoing or failed builds.Jun 8 2022, 8:41 PM
This revision was automatically updated to reflect the committed changes.

Hello,

When I run tests (check-all) on this commit I get the follwoing two failures:

Failed Tests (2):
  lld :: MachO/eh-frame.s
  lld :: MachO/icf-safe.s

They crash with

Command Output (stderr):
--
ld64.lld: ../../lld/MachO/UnwindInfoSection.cpp:216: void lld::macho::UnwindInfoSection::addSymbol(const lld::macho::Defined *): Assertion `!p.first->second->unwindEntry' failed.
/repo/uabelho/main-github/llvm/build-all/tools/lld/test/MachO/Output/eh-frame.s.script: line 17: 123869 Aborted                 ld64.lld -arch x86_64 -platform_version macos 11.0 11.0 -syslibroot /repo/uabelho/main-github/lld/test/MachO/Inputs/MacOSX.sdk -fatal_warnings -arch arm64 -lSystem -lc++ /repo/uabelho/main-github/llvm/build-all/tools/lld/test/MachO/Output/eh-frame.s.tmp/eh-frame-arm64.o -o /repo/uabelho/main-github/llvm/build-all/tools/lld/test/MachO/Output/eh-frame.s.tmp/eh-frame-arm64

and

Command Output (stderr):
--
ld64.lld: ../../lld/MachO/ICF.cpp:451: auto lld::macho::foldIdenticalSections()::(anonymous class)::operator()(lld::macho::ConcatInputSection *) const: Assertion `isec->icfEqClass[0] == 0' failed.
ld64.lld: ../../lld/MachO/ICF.cpp:451: auto lld::macho::foldIdenticalSections()::(anonymous class)::operator()(lld::macho::ConcatInputSection *) const: Assertion `isec->icfEqClass[0] == 0' failed.
/repo/uabelho/main-github/llvm/build-all/tools/lld/test/MachO/Output/icf-safe.s.script: line 6: 45777 Aborted                 ld64.lld -arch x86_64 -platform_version macos 11.0 11.0 -syslibroot /repo/uabelho/main-github/lld/test/MachO/Inputs/MacOSX.sdk -fatal_warnings -arch arm64 -lSystem --icf=safe -dylib -o /repo/uabelho/main-github/llvm/build-all/tools/lld/test/MachO/Output/icf-safe.s.tmp/icf-safe.dylib /repo/uabelho/main-github/llvm/build-all/tools/lld/test/MachO/Output/icf-safe.s.tmp/icf-obj.o

Any idea what's happening?

dyung added a subscriber: dyung.Jun 9 2022, 1:46 AM

The test you changed is failing on the PS4 Windows/Linux bots due to the arm64 triple not being available. Can you please fix the test?

https://lab.llvm.org/buildbot/#/builders/139/builds/23051
https://lab.llvm.org/buildbot/#/builders/216/builds/5579

Command Output (stderr):
--
/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/llvm-mc: error: unable to get target for 'arm64-apple-macos11.0', see --version and --triple.
dyung added a comment.Jun 9 2022, 5:25 AM

Hello,

When I run tests (check-all) on this commit I get the follwoing two failures:

Failed Tests (2):
  lld :: MachO/eh-frame.s
  lld :: MachO/icf-safe.s

They crash with

Command Output (stderr):
--
ld64.lld: ../../lld/MachO/UnwindInfoSection.cpp:216: void lld::macho::UnwindInfoSection::addSymbol(const lld::macho::Defined *): Assertion `!p.first->second->unwindEntry' failed.
/repo/uabelho/main-github/llvm/build-all/tools/lld/test/MachO/Output/eh-frame.s.script: line 17: 123869 Aborted                 ld64.lld -arch x86_64 -platform_version macos 11.0 11.0 -syslibroot /repo/uabelho/main-github/lld/test/MachO/Inputs/MacOSX.sdk -fatal_warnings -arch arm64 -lSystem -lc++ /repo/uabelho/main-github/llvm/build-all/tools/lld/test/MachO/Output/eh-frame.s.tmp/eh-frame-arm64.o -o /repo/uabelho/main-github/llvm/build-all/tools/lld/test/MachO/Output/eh-frame.s.tmp/eh-frame-arm64

and

Command Output (stderr):
--
ld64.lld: ../../lld/MachO/ICF.cpp:451: auto lld::macho::foldIdenticalSections()::(anonymous class)::operator()(lld::macho::ConcatInputSection *) const: Assertion `isec->icfEqClass[0] == 0' failed.
ld64.lld: ../../lld/MachO/ICF.cpp:451: auto lld::macho::foldIdenticalSections()::(anonymous class)::operator()(lld::macho::ConcatInputSection *) const: Assertion `isec->icfEqClass[0] == 0' failed.
/repo/uabelho/main-github/llvm/build-all/tools/lld/test/MachO/Output/icf-safe.s.script: line 6: 45777 Aborted                 ld64.lld -arch x86_64 -platform_version macos 11.0 11.0 -syslibroot /repo/uabelho/main-github/lld/test/MachO/Inputs/MacOSX.sdk -fatal_warnings -arch arm64 -lSystem --icf=safe -dylib -o /repo/uabelho/main-github/llvm/build-all/tools/lld/test/MachO/Output/icf-safe.s.tmp/icf-safe.dylib /repo/uabelho/main-github/llvm/build-all/tools/lld/test/MachO/Output/icf-safe.s.tmp/icf-obj.o

Any idea what's happening?

We are also seeing the same failure on our internal linux build bot, and upstream build bots as well:

Hi, your recommit of your changes are causing a test failure on the PS4 bots because the newly added test target arm64 is not present, can you either fixup the test to not require that or add a REQUIRES line?

https://lab.llvm.org/buildbot/#/builders/139/builds/23146

/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/llvm-mc: error: unable to get target for 'arm64-apple-macos11.0', see --version and --triple.
int3 added a comment.Jun 13 2022, 11:07 AM

My bad, I now see you pointed it out in an earlier comment as well. Sorry about the churn.