The fix was committed as part of rL324064. This adds an x86 testcase
Details
Diff Detail
- Repository
- rLLD LLVM Linker
- Build Status
Buildable 14503 Build 14503: arc lint + arc unit
Event Timeline
So this intruduces -relocation-format=xxx option.
Is it documented somewhere ? I did not find the description.
Looks it is for MIPS only ? I wonder why do you want to
mix .rel and .rel[a] objects and if it is really legal thing to do first of all ?
+Simon, he knows about MIPS much more than me.
I originally discovered this issue because in our CHERI fork of LLD we set Config->IsRela = false when linking MIPS64 code. We do this because the FreeBSD MIPS rtld only understands Elf_Rel relocations and does not process Elf_Rela.
The issue here is not speicific to MIPS. It only depends on an input file containing Elf_Rela for a target that has Elf_Rel as the default output format.
I added the command line flag since this makes it possible to test this issue without fabricating .o files. Additionally, it will make it possible to use LLD for operating systems where rtld doesn't use Rela and the IsRela = Config->Is64 || IsX32 || Config->MipsN32Abi || Machine == EM_PPC. check is not correct.
It sounds like FreeBSD MIPS rtld bug honestly and probably should be fixed on their side.
I guess it currently works with GNU linkers because they always write the addend to output, even when output is .rela.
We faced something like that before when worked on x64 target. And it was fixed on FreeBSD side.
I do not think we want to add command line option like that in LLD. One possible option in theory would be to have
the same behavior as gnu linkers do, but it is also unclear it is needed, because seem helps to hide an issue instead of fixing it.
Lets wait to hear what other people think.
MIPS O32 ABI uses the Elf_Rel format in object files, while N32 and N64 ABIs uses the Elf_Rela. But originally in case of all ABIs output relocations in executable files and DSO are written in the Elf_Rel format. I think the goal was to reduce a file size. In case of embedded systems with small amount of memory it can be a benefit. Maybe there are some other reasons. When I implement MIPS LLD backend I used the same format for input and output files, i.e. Elf_Rel for O32 ABI and Elf_Rela for N32 and N64 ABIs. It works for Linux because the dynamic linker accepts all formats. It looks like FreeBSD linker is more stricter.
I have been working on adding RELA support to the mips rtld but this is quite annoying and will take a while. For now I have been able to run code just by setting Config->IsRela to false.
I don't know if the MIPS specifies that Elf_Rela should to be used for n64. I believe this choice is up to the operating system but I could be wrong.
I do not think we want to add command line option like that in LLD. One possible option in theory would be to have
the same behavior as gnu linkers do, but it is also unclear it is needed, because seem helps to hide an issue instead of fixing it.
This is actually fixing an issue since compilers other than clang are not required to use the same relocation kind as LLD for the object files.
I can also add a patch to completely reject any Elf_Rel relocations if Config->IsRela is set but I don't think that is the right way forward. Right now we are producing broken object files if this is the case and I would very much like to avoid that.
So should/can we switch LLD to always emit Elf_Rel for all MIPS outputs then ?
I think I agree with George. REL/RELA is defined by the ABI and making it configurable seems odd.
I only added the flag to make the testing easier. I can try to create the various input files using yaml2obj but that will require 4 different input files instead of just one .s file.
Please add test files to test your code instead of adding a user-visible command line flag. User-visible flags shouldn't be added without careful planning.
Probably not. I could rewrite the different inputs as YAML since the llvm-mc change doesn't seem that useful.