How can I enable PLT in a custom target?


I'm building a staticlib crate with a custom target using xargo for managing the sysroot (rustc 1.53.0-nightly). The generated code is PIC. The generated binary (a .a with .o inside) uses GOTPCREL instead of generating a PLT. How can I revert back to generating a PIE? See

The target I'm linking against does not support GOTPCREL relocations, this is why I need a PLT.
I tried this in the target json (unsuccesfully):

"pre-link-args": { "gcc": [ "-fplt" ] }
  • EDIT: I meant -fplt. not -fpie.

You need to use "needs-plt": false. You may also need "relro-level": "off" if relro is enabled.

1 Like

It seems that irrespective of the needs-plt option, the .o file corresponding to my crate has no GOTPCREL relocs, which is what I want. Those relocs appear in the .o files associated with libcore. Is there a way I can control xargo to compile the sysroot with PLT? Should I not use xargo and build it myself?.
Ultimately I want to extract the .o files and link them in a single ld -relocatable *.o -o final.o, the final.o should not have GOTPCREL relocations, instead, a PLT. Thanks.