Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Latest changes in nightly cause it to produce executable named "-pie" in the crate directory. #48884

Closed
berkus opened this issue Mar 9, 2018 · 12 comments · Fixed by #49329
Closed
Labels
P-high High priority regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@berkus
Copy link
Contributor

berkus commented Mar 9, 2018

Updated to rustc 1.26.0-nightly (2789b067d 2018-03-06) via rustup.

I have a custom target file and additional cargo configs which specify additional rustc arguments.

Now if I run

export RUST_TARGET_PATH=$(pwd)/targets/
xargo run --target aarch64-vesper-metta

The build will succeed but then fail to run qemu because

     Running `qemu-system-aarch64 -M raspi3 -d in_asm -serial stdio -kernel target/aarch64-vesper-metta/debug/vesper`
qemu-system-aarch64: could not load kernel 'target/aarch64-vesper-metta/debug/vesper'

Instead, there's a file named -pie in the directory where xargo was run from.

To fix this I had to change the target json file with these options:

-  "linker-is-gnu": true,
+  "linker-is-gnu": false,

I'm afraid this could subtly break my builds elsewhere, as the linker is, in fact, GNU ld.

I believe this is related to the latest -pie/-no-pie patches which somehow interfere with custom cargo linker arguments specifications (where -pie ends up landing instead of output file name).

@sfackler
Copy link
Member

sfackler commented Mar 9, 2018

Seems like #48076 is likely to be related? @canarysnort01

@berkus
Copy link
Contributor Author

berkus commented Mar 9, 2018

That's my suspicion @sfackler

@sfackler sfackler added regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 9, 2018
berkus added a commit to metta-systems/vesper that referenced this issue Mar 9, 2018
@canarysnort01
Copy link
Contributor

hmm my change shouldn't have impacted when the -pie flag was sent, only added the -no-pie flag. what version were you using before?

@canarysnort01
Copy link
Contributor

Could you please build with RUST_LOG=rustc_trans=info xargo build --target aarch64-vesper-metta and post the output related to the link step (after the preparing CrateTypeExecutable to ... line)

@nikomatsakis
Copy link
Contributor

triage: P-high

Not assigning this to anyone immediately, since @canarysnort01 seems to be on it -- @berkus, if you could take a shot at supplying that debug output it would be very helpful, thanks. =)

@rust-highfive rust-highfive added the P-high High priority label Mar 15, 2018
@berkus
Copy link
Contributor Author

berkus commented Mar 22, 2018

 INFO 2018-03-22T10:46:46Z: rustc_trans::back::link: preparing CrateTypeExecutable to "/Users/berkus/Hobby/Metta/vesper/target/aarch64-vesper-metta/release/deps/vesper-b63e9d46780781be"
 INFO 2018-03-22T10:46:46Z: rustc_trans::back::link: "aarch64-unknown-linux-musl-ld" "-nodefaultlibs" "-nostdlib" "-L" "/Users/berkus/.xargo/lib/rustlib/aarch64-vesper-metta/lib" "/Users/berkus/Hobby/Metta/vesper/target/aarch64-vesper-metta/release/deps/vesper-b63e9d46780781be.vesper2.rcgu.o" "-o" "/Users/berkus/Hobby/Metta/vesper/target/aarch64-vesper-metta/release/deps/vesper-b63e9d46780781be" "--gc-sections" "-no-pie" "-z,relro,-z,now" "-O1" "-L" "/Users/berkus/Hobby/Metta/vesper/target/aarch64-vesper-metta/release/deps" "-L" "/Users/berkus/Hobby/Metta/vesper/target/release/deps" "-L" "/Users/berkus/Hobby/Metta/vesper/target/aarch64-vesper-metta/release/build/vesper-6d63ef12987ec0c8/out/src/boot" "-L" "/Users/berkus/.xargo/lib/rustlib/aarch64-vesper-metta/lib" "-Bstatic" "--whole-archive" "-l" "aarch64" "--no-whole-archive" "/Users/berkus/Hobby/Metta/vesper/target/aarch64-vesper-metta/release/deps/librlibc-ffb0a67b04c0940a.rlib" "-static" "-Tlinker/aarch64.ld" "-Bdynamic"
 INFO 2018-03-22T10:46:46Z: rustc_trans::back::link: linker stderr:
aarch64-unknown-linux-musl-ld: warning: -z ,relro,-z,now ignored.

 INFO 2018-03-22T10:46:46Z: rustc_trans::back::link: linker stdout:

    Finished release [optimized + debuginfo] target(s) in 1.69 secs
     Running `/Users/berkus/Hobby/Metta/vesper/.cargo/runscript.sh target/aarch64-vesper-metta/release/vesper`
aarch64-unknown-linux-musl-objcopy: 'target/aarch64-vesper-metta/release/vesper': No such file

@nikomatsakis
Copy link
Contributor

@canarysnort01 does that contain the info you needed?

@berkus
Copy link
Contributor Author

berkus commented Mar 22, 2018

It does look weird as I don't see any standalone -pie in the command line.

@canarysnort01
Copy link
Contributor

Yes, that helps. I think this is what is happening:

  • Even though you have set in your target file to produce position-independent-executables (pass the "-pie" flag), the code overrides this because it sees "-static" on the linker's command line and decides not to generate PIE.
  • My PR made it pass "-no-pie" in this case, and fall back to removing -no-pie if the link fails
  • For some reason this seems to be confusing ld instead of causing it to generate an error

@berkus Can you confirm this by manually running:

"aarch64-unknown-linux-musl-ld" "-nodefaultlibs" "-nostdlib" "-L" "/Users/berkus/.xargo/lib/rustlib/aarch64-vesper-metta/lib" "/Users/berkus/Hobby/Metta/vesper/target/aarch64-vesper-metta/release/deps/vesper-b63e9d46780781be.vesper2.rcgu.o" "-o" "/Users/berkus/Hobby/Metta/vesper/target/aarch64-vesper-metta/release/deps/vesper-b63e9d46780781be" "--gc-sections" "-z,relro,-z,now" "-O1" "-L" "/Users/berkus/Hobby/Metta/vesper/target/aarch64-vesper-metta/release/deps" "-L" "/Users/berkus/Hobby/Metta/vesper/target/release/deps" "-L" "/Users/berkus/Hobby/Metta/vesper/target/aarch64-vesper-metta/release/build/vesper-6d63ef12987ec0c8/out/src/boot" "-L" "/Users/berkus/.xargo/lib/rustlib/aarch64-vesper-metta/lib" "-Bstatic" "--whole-archive" "-l" "aarch64" "--no-whole-archive" "/Users/berkus/Hobby/Metta/vesper/target/aarch64-vesper-metta/release/deps/librlibc-ffb0a67b04c0940a.rlib" "-static" "-Tlinker/aarch64.ld" "-Bdynamic"

(same command line without -no-pie) to see if it works correctly, and also a aarch64-unknown-linux-musl-ld --version?

I need to look more into ld to see if -no-pie is even necessary for it, I think maybe the default pie stuff might only be applicable with the gcc front-end. If so, I think the fix would be to change the code not to generate -no-pie if linking with ld.

@canarysnort01
Copy link
Contributor

nm, I think I was able to reproduce this. I don't see -no-pie documented for ld so I think that is the problem. I'll work on a fix.

canarysnort01 added a commit to canarysnort01/rust that referenced this issue Mar 24, 2018
kennytm added a commit to kennytm/rust that referenced this issue Mar 28, 2018
@berkus
Copy link
Contributor Author

berkus commented Apr 2, 2018

Thanks, I will test this asap!

@berkus
Copy link
Contributor Author

berkus commented Apr 2, 2018

Works! Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P-high High priority regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants