This is an archive of the discontinued LLVM Phabricator instance.

[mips] Make the .eh_frame writable on FreeBSD to work around issues in the old linker.
AbandonedPublic

Authored by dsanders on Nov 13 2015, 6:55 AM.

Details

Reviewers
None
Summary

The Mips port of FreeBSD is currently using an old linker (GNU ld 2.17.50 [FreeBSD]
2007-07-03) which seems to be unable to fully support read-only .eh_frame sections.
Work around this for now by making them writeable on this target.

The linker must also be patch to support R_MIPS_PC32 as discussed in PR25176.

Diff Detail

Event Timeline

dsanders updated this revision to Diff 40147.Nov 13 2015, 6:55 AM
dsanders retitled this revision from to [mips] Make the .eh_frame writable on FreeBSD to work around issues in the old linker..
dsanders updated this object.
dsanders added subscribers: emaste, seanbruno, llvm-commits.

Please don't. Just update the linker and use R_MIPS_PC32 in llvm.

I'm told that they can't update to a newer GNU Ld because FreeBSD chose to reject GPLv3. Their plan as it has been explained to me is to get any build working with clang as the system compiler, then work on making lld the default linker. I therefore see this as a stepping stone for getting to the correct place and would want to revert this patch as soon as I'm able to.

... and use R_MIPS_PC32 in llvm.

Thanks to the linker patch mentioned in PR25176, we are using R_MIPS_PC32 everywhere that Mips Linux targets use them. Unfortunately, this doesn't quite result in a working link. The remaining problem is that this:

.cfi_personality 128, DW.ref.__gxx_personality_v0

emits a R_MIPS_64 reference in .eh_frame. This is the same as what we emit for Linux and modern linkers accept it (and convert to a PC relative form) but this linker doesn't.

I was going to say that I can't change the encoding to 0x9B (indirect, pcrel, sdata4) but when I double checked this it surprised me by working. It resulted in a crash last time I tried this so maybe the linker patch fixed that as well. A FreeBSD-specific personality encoding is much better than this patch so I'll test a bit more and report back.

dsanders abandoned this revision.Nov 16 2015, 4:11 AM

Abandoned in favour of D14700

I'm told that they can't update to a newer GNU Ld because FreeBSD chose to reject GPLv3. Their plan as it has been explained to me is to get any build working with clang as the system compiler, then work on making lld the default linker. I therefore see this as a stepping stone for getting to the correct place and would want to revert this patch as soon as I'm able to.

Our plan is indeed to use Clang as the system compiler and LLD as the system linker on all of our supported platforms as they become functional. In the interim we'll use one of these options:

  1. Try to work around binutils 2.17.50 limitations
  2. Have two versions of binutils in the tree, with a build-time switch
  3. Exclude ld from the base system for MIPS, requiring the installation of a binutils port to have a usable toolchain

The third option above is what we do for arm64 today and it works well, but makes bootstrapping a system more awkward. Also upstream binutils lacks FreeBSD/MIPS support, so there's work that needs to be done just to make a newer ld available.