You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"relocation R_X86_64_PC32 cannot refer to absolute symbol ImageBase" (symbol from linker script) error linking FreeBSD/amd64 EFI loader with lld
#29754
Closed
emaste opened this issue
Sep 16, 2016
· 5 comments
We ran into the same issue so I did the analysis and I believe I found the source of the bug. There are actually several aspects at play here.
Symbols provided by linker scripts are created by DefinedRegular with the input section being null, as a consequence isAbsolute predicate at ELF/Relocations.cpp#283 treats them as absolute symbols and returns an error at ELF/Relocations.cpp#337 which is incorrect.
A possible solution to that issue is to define symbols provided by linker script as synthetic which is possibly a correct thing to do since these don't have an input file or input section anyway.
However, this also uncovered a more general issue: the condition at ELF/Relocations.cpp#335 is very likely incorrect. Symbol can be either undefined or absolute, that fact that this logic convoluted those cases implies that it's wrong. In fact, I tried to link the test case for this logic in ELF/relocation-relative-absolute.s with both BFD ld and gold, and they both handle it just fine emitting a symbol with SHN_ABS section index. The confusion might come from the fact that absolute symbol doesn't necessarily mean non-relocatable symbol here.
Therefore, we should also probably remove this special case which also resolves the error with symbols in the linker script without having to change their type (although we might still want to do that in either case). Also removing that check makes LLD behave the same way as BFD ld and gold.
Do you any opinion/preferences regarding these solutions? I'd be happy to send out a patch once we agree on the solution we want to take here.
Sorry for the belated response. I'm not sure if I understand what you said correctly. Probably it is easy to discuss if we have code. Could you sent me (and llvm-commits) a patch so that we can discuss based on that?
Extended Description
Reproduction cpio at https://people.freebsd.org/~emaste/lld/loader.cpio
./ld.lld --trace-symbol=ImageBase $(cat response.txt )
tank/emaste/obj/tank/emaste/src/freebsd-xlld/sys/boot/efi/loader/start.o: reference to ImageBase
(internal): definition of ImageBase
relocation R_X86_64_PC32 cannot refer to absolute symbol ImageBase
ImageBase comes from the linker script:
...
SECTIONS
{
/* Read-only sections, merged into text segment: */
. = 0;
ImageBase = .;
.hash : { (.hash) } / this MUST come first! */
. = ALIGN(4096);
.eh_frame :
{
...
The text was updated successfully, but these errors were encountered: