Skip to content

relocation-model=dynamic-no-pic passes -pie to ld #35061

Closed
@jvns

Description

@jvns

I'm having trouble linking a Rust program to a non-position-independent C library. When I manually remove the -pie flag from the ld step that rustc runs, everything works correctly. I think that -C relocation-model=dynamic-no-pic should remove the -pie flag for me, but it doesn't.

Here's what I think is going on:

When I run

strace -s 300 -e execve -f rustup run nightly rustc hello.rs -v -C relocation-model=dynamic-no-pic

It runs ld with the -pie flag:

execve("/usr/bin/ld", ["/usr/bin/ld", "-pie"

But when I read the rustc code here, it seems like the intention is that -pie should only be passed to ld when relocation-model=pic. That is, if we're not compiling a position independent executable, then we should not pass the position independent executable -pie flag to ld.

I think what may be happening here is that somehow the defaults from

relocation_model: "pic".to_string(),
are overriding the command line options I'm setting.

This happens with stable and also the nightly I tried:

rustc 1.12.0-nightly (9316ae515 2016-07-24)
binary: rustc
commit-hash: 9316ae515e2f8f3f497fb4f1559910c1eef2433d
commit-date: 2016-07-24
host: x86_64-unknown-linux-gnu
release: 1.12.0-nightly

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-frontendArea: Compiler frontend (errors, parsing and HIR)C-bugCategory: This is a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions