Ld.gold error regarding -fPIC

I have two Linux systems, one has the latest Swift (5.3-dev) and ld.gold version 2.33.1, and other other has a month-old Swift (also called 5.3-dev) and ld.gold version 2.31.1.
The older linker and Swift compiler successfully compile some code that I've written, but the newer pair does not. In particular, the linker says:

/usr/bin/ld.gold: error: myfile.o: requires unsupported dynamic reloc 11; recompile with -fPIC

I'm compiling with only one switch for importing a objc header file.

Does anyone know if this is a known bug with Swift emitting bad object code or with ld.gold no longer accepting good object code? Is there a fix for it? If I could override swiftc's choice of loader to add the -fPIC that might be a short-term fix but perhaps this should be repaired upstream.
Thanks.

This might be a linker bug. Swift should always build as PIC/PIE, but it uses some relocations that are not common in C/C++, and we've had issues with linkers in the past not handling those relocations the way we want. This class of failure might also be caused by a compiler bug where the compiler fails to emit a symbol that's referenced by Swift metadata, causing the linker to leave a relocation unresolved instead of statically resolved. Is there a way to get gold to dump more details about the relocation?

I tried that. Removing all of the Opened/Release/Locked/Unlocked stuff, there is actually nothing else to describe the reason for the error.

Also FWIW what I see in the dumped ld.gold command is these flags:
-pie --eh-frame-hdr -m elf_x86_64 -dynamic-linker

Lastly when I try to do what the error message asks, and provide -fPIC to ld.gold, which requires -shared, it says
/usr/bin/ld.gold: fatal error: -shared and -pie are incompatible

-pie implies PIC. The "recompile with -fPIC" is just nonsense advice from the generic linker error message.

1 Like
Terms of Service

Privacy Policy

Cookie Policy