rust-lang / rust-lang/rust

`rustc` successfully compiles PIE for target without support for PIE

Open
#117,943 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-diagnostics A-linkage T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Code

With the following target spec:

{
  "arch": "x86_64",
  "data-layout": "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128",
  "linker": "rust-lld",
  "linker-flavor": "ld.lld",
  "llvm-target": "x86_64-unknown-none-elf",
  "panic-strategy": "abort",
  "target-pointer-width": "64"
}

(note that position-independent-executables is implicitly set to false)

The following command successfully compiles:

RUSTFLAGS="-Crelocation-model=pie" cargo b --target x86_64-unknown-custom.json -Zbuild-std=core
Current output

rustc successfully compiles, but the output executable is not position-independent:

$ file target/x86_64-unknown-custom/debug/pie
target/x86_64-unknown-custom/debug/pie: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, with debug_info, not stripped
Desired output

A similar error to when a crate type isn't supported e.g.

error: cannot produce position-independent executable for `pie v0.1.0 (/path/to/pie)` as the target `x86_64-unknown-custom` does not support them
Rationale and extra context

No response

Other cases

No response

Anything else?

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with rustc handling of -Crelocation-model=pie for the supplied custom target spec and reproduce the command with -Zbuild-std=core. Trace where target support is checked or missed, then verify that an unsupported target produces the requested diagnostic instead of a non-position-independent executable.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.