Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"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
Labels
bugzilla Issues migrated from bugzilla lld:ELF

Comments

@emaste
Copy link
Member

emaste commented Sep 16, 2016

Bugzilla Link 30406
Resolution FIXED
Resolved on Oct 31, 2016 16:37
Version unspecified
OS FreeBSD
Blocks #23588
CC @petrhosek,@rui314

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 :
{
...

@llvmbot
Copy link
Collaborator

llvmbot commented Sep 26, 2016

It is because you use --fatal-warnings,
I prepared a patch: D24908

@llvmbot
Copy link
Collaborator

llvmbot commented Sep 26, 2016

Sorry posted to wrong bug page.

@petrhosek
Copy link
Member

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.

@rui314
Copy link
Member

rui314 commented Oct 27, 2016

Petr,

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?

@llvmbot
Copy link
Collaborator

llvmbot commented Oct 31, 2016

Fixed in r285641

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 10, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla lld:ELF
Projects
None yet
Development

No branches or pull requests

4 participants