How can I enable PLT in a custom target?

HI,

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 https://internals.rust-lang.org/t/function-calls-plt-vs-gotpcrel/8909

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.
    Thanks.

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.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.