xargo
xargo copied to clipboard
Can't deactivate PIE through custom target specification
In an attempt at getting backtraces to show up on Android (CF rust-lang/rust#17520), I've attempted to build a simple rust binary without PIE (position independent executable). The idea is to run this executable on a debug phone that has PIE-protection disabled, so I can get the backtrace I need.
To do this, I've created a custom target spec for arm-linux-androideabi
that disables position-independent-executables
. You can see it there, with the whole setup I'm using.
Unfortunately, after compiling it with xargo, rustc still passed -pie
to the linker, resulting in PIE executables. I was wondering if maybe there was a bug in xargo ?
Have you tried setting RUSTFLAGS to disable pie, like:
RUSTFLAGS='-C relocation-model=dynamic-no-pic -C link-args=-no-pie'
I'm not sure if this will work, but it's worth a try.
Okay I literally had to resolve this exact same problem. All I had to do was add -no-pie
to the pre-link-args
in my target specification. YMMV.
@roblabla
To do this, I've created a custom target spec for arm-linux-androideabi that disables position-independent-executables. You can see it there, with the whole setup I'm using.
Note that if there's a custom target with the same name as a built-in target, as in your case, then rustc (*) will prefer the built-in target. I think this is what you don't get the behavior you want; try renaming the android target to something that doesn't match the name of one of the built-in targets (cf. rustc --print target-list
).
(*) So there's nothing that Xargo can do in this case.
@Others
Alternatively you can use something like RUSTFLAGS="-Z pre-link-arg=-no-pie
and the built-in android target. And if that works then you don't even need Xargo because linker arguments don't affect how the sysroot is compiled thus you can use the normal rust-std
component: that is you can just use cargo build
with the RUSTFLAGS mentioned before.
@japaric Yeah, that's not a great solution for me since my target is so exotic (I compile Rust to run on a research operating system.) However it's probably a good solution if your target is only a little weird :)