xargo icon indicating copy to clipboard operation
xargo copied to clipboard

Can't deactivate PIE through custom target specification

Open roblabla opened this issue 7 years ago • 4 comments

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 ?

roblabla avatar Jun 21 '17 15:06 roblabla

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.

Others avatar Jul 23 '17 19:07 Others

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.

Others avatar Jul 26 '17 17:07 Others

@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 avatar Aug 22 '17 19:08 japaric

@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 :)

Others avatar Aug 22 '17 20:08 Others