This is an archive of the discontinued LLVM Phabricator instance.

[ELF] Make .eh_frame relro if one of the inputs is SHF_WRITE
Needs ReviewPublic

Authored by arichardson on Feb 12 2018, 6:45 AM.

Details

Summary

Previously .eh_frame was always SHF_ALLOC and read-only. However, for
MIPS64 PIC code clang emits a R_MIPS_64 relocation that will be converted
to a dynamic relocation so .eh_frame can't be read-only in that case.
Since the input section has the SHF_WRITE flag set we were adding dynamic
relocations against even though the .eh_frame output section is read-only
without requiring -z notext.
Fix this by making .eh_frame writable if one of the input sections is has
the SHF_WRITE flag.

Event Timeline

arichardson created this revision.Feb 12 2018, 6:45 AM

As I said in the D43185, probably we need to implement something like _bfd_elf_eh_frame_section_offset from BFD library to convert absolute relocations into relative ones and resolve them at the time of linking.

As I said in the D43185, probably we need to implement something like _bfd_elf_eh_frame_section_offset from BFD library to convert absolute relocations into relative ones and resolve them at the time of linking.

I agree that this is the correct way forward but this at least allows me to create non-broken .so files.

This patch prevents LLD from creating dynamic relocations against a read-only section without -z notext so I believe it is a valid bugfix and is independent of a .eh_frame format for MIPS that can be read-only.

joerg added a comment.Feb 12 2018, 7:12 AM

Please stop adding complexity to doctor around the symptoms. There are two real fixes here and this change doesn't help with either:
(1) Emit cross-section pointers as indirect. This increases the binary size, but otherwise ensures that any linker can create read-only .eh_frame on MIPS.
(2) Teach lld on MIPS to properly reassemble the DWARF instructions, similar to what GNU ld can do. The latter is a bit stupid and needs a good kick to work properly, but this is the correct approach forward.

espindola edited reviewers, added: espindola; removed: rafael.Mar 15 2018, 8:37 AM