This is an archive of the discontinued LLVM Phabricator instance.

[MIPS][ELF] Use PC-relative relocations in .eh_frame when possible
ClosedPublic

Authored by arichardson on Jan 5 2020, 7:16 AM.

Details

Summary

When compiling position-independent executables, we now use
DW_EH_PE_pcrel | DW_EH_PE_sdata4. However, the MIPS ABI does not define a
64-bit PC-relative ELF relocation so we cannot use sdata8 for the large
code model case. When using the large code model, we fall back to the
previous behaviour of generating absolute relocations.

With this change clang-generated .o files can be linked by LLD without
having to pass -Wl,-z,notext (which creates text relocations).
This is simpler than the approach used by ld.bfd, which rewrites the
.eh_frame section to convert absolute relocations into relative references.

I saw in D13104 that apparently ld.bfd did not accept pc-relative relocations
for MIPS ouput at some point. However, I also checked that recent ld.bfd
can process the clang-generated .o files so this no longer seems true.

Diff Detail

Event Timeline

arichardson created this revision.Jan 5 2020, 7:16 AM

Unit tests: pass. 61249 tests passed, 0 failed and 736 were skipped.

clang-tidy: pass.

clang-format: pass.

Build artifacts: diff.json, clang-tidy.txt, clang-format.patch, CMakeCache.txt, console-log.txt, test-results.xml

joerg added a comment.Jan 5 2020, 7:52 AM

What's the fixup behavior of the linker here, e.g. does it make sense to just use absolute encoding here and let the linker fix it up?

What's the fixup behavior of the linker here, e.g. does it make sense to just use absolute encoding here and let the linker fix it up?

Currently LLD will not convert the encoding. This change allows me to build and link MIPS64 FreeBSD using clang+lld without having to fix up things in the linker.
I think this is a much simpler approach than making LLD reassemble the eh_frame with relative values.

ld.bfd also accepts these clang generated input files and generates the same eh_frame output as lld.

We could still add the eh_frame rewriting support in the future.

kevans added a subscriber: kevans.Jan 5 2020, 12:12 PM

ping? I believe this is the last blocker before FreeBSD can move to using Clang+LLD for MIPS64 by default. It would be really nice to get this in for LLVM 10.

arichardson edited the summary of this revision. (Show Details)Jan 10 2020, 7:53 AM
arichardson edited reviewers, added: bsdjhb, dsanders, logan, danalbert; removed: espindola.
MaskRay added inline comments.Jan 10 2020, 10:21 AM
llvm/test/MC/Mips/eh-frame.s
21

llvm-readobj -r may have a nicer output than llvm-objdump -r

dsanders added a comment.EditedJan 10 2020, 10:47 AM

I see you've added me as a reviewer but I haven't worked on MIPS for a few years so I'm not really familiar with the current state of their linkers and binaries. AFAIK @atanasyan is still actively working on MIPS so hopefully he can take a look or bring in a colleague who can.
FWIW, this sounds like a good change and the code looks good to me but I think you should get another LGTM from someone more up to date on MIPS.

atanasyan accepted this revision.Jan 11 2020, 1:46 PM

I'm sorry for the delay. The patch is LGTM.
Thanks.

This revision is now accepted and ready to land.Jan 11 2020, 1:46 PM
This revision was automatically updated to reflect the committed changes.