LLVM generates wrong reloc type for global_ctors (section .init_array) for ARM target
| Bugzilla Link | 10833 |
| Resolution | INVALID |
| Resolved on | Jan 19, 2016 08:09 |
| Version | trunk |
| OS | Windows XP |
| Reporter | LLVM Bugzilla Contributor |
| CC | @asl,@jmolloy,@rengolin |
Extended Description
Hi, I'm trying to get my LLVM generated .obj file (ELF) to link with the official ARM linker together with a project that is C++ code compiled with ARMCC. The file contains llvm.global_ctors that are emitted (correctly) to the .init_array section. However LLVM emits a R_ARM_ABS32(2) relocation for the entries in the .init_array section. A comparison with a .cpp file compiled with ARMCC showed that it uses a R_ARM_TARGET1(38) relocation. (see also http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0474c/CHDECJAJ.html) As a consequence, the linked project crashes in __cpp_initialize__aeabi as the relocation (from the LLVM compiled module) is wrong.
I tried for myself to find where to change code in LLVM to make LLVM emit the correct relocation, but was unfortunately stuck.
Is there an easy way for LLVM to generate R_ARM_TARGET1 instead of R_ARM_ABS32 for .init_array?
My exact target configuration when generating the .obj file using LLVM is: std::string triple = "armv6-unknown-unknown-eabi"; cpu = "mpcore"; // (ARM) needed for VFP // all these options needed for the ARM linker to use fz (fpmode=fast) library instead of f or g (fpmode=ieee_full) llvm::FloatABIType = llvm::FloatABI::Hard; llvm::UnsafeFPMath = true; llvm::NoInfsFPMath = true; llvm::NoNaNsFPMath = true;
ARM is now using LLVM technology for their tools, so this feature is likely already fixed. If not, contacting ARM customer support is probably the best way to go from here.
As I have access to RVCT, I'm probably best placed to try and replicate this.
Thanks for your reply. I have now made a workaround where I just patch the relocs of the .init_array section in the resulting elf file. Just thought this might get fixed eventually in a future version.
ARM ELF direct code emission might be broken / incomplete. Please generate the assembler and use GNU as to produce final object file.