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

Building in release mode with LTO breaks RPM build process for some code #78445

Open
gavrie opened this issue Oct 27, 2020 · 1 comment
Open
Labels
A-linkage Area: linking into static, shared libraries and binaries A-lto Area: Link Time Optimization C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@gavrie
Copy link

gavrie commented Oct 27, 2020

When building a dynamic library from my Rust code with LTO enabled, the resulting binary includes a seemingly invalid slash-terminated directory table entry, which in turn prevents building an RPM from the library on RHEL (details follow below).

The Rust code (reduced to the minimal code that reproduces the issue) in src/lib.rs:

#[no_mangle]
pub extern "C" fn on_load() {
    let _ = std::panic::take_hook();
}

The Cargo.toml:

[package]
name = "lto-bug"
version = "0.1.0"
edition = "2018"

[lib]
crate-type = ["cdylib"]
name = "lto_bug"

[profile.release]
lto = true

The build command:

cargo build --release

I expected to see this happen: Get a valid binary for the dynamic library.

Instead, this happened:

The resulting binary includes a directory table entry that ends with a slash, which in turn breaks the RPM build process.

The output of objdump -g target/release/liblto_bug.so includes:

 The Directory Table (offset 0x19d4c):
  1     /cargo/registry/src/github.com-1ecc6299db9ec823/rustc-demangle-0.1.16/src
  2     /rustc/18bf6b4f01a6feaf7259ba7cdae58031af1b7b39/library/core/src
  3     /rustc/18bf6b4f01a6feaf7259ba7cdae58031af1b7b39/library/core/src/slice
  4     /rustc/18bf6b4f01a6feaf7259ba7cdae58031af1b7b39/
  5     /rustc/18bf6b4f01a6feaf7259ba7cdae58031af1b7b39/library/core/src/ops
...

Entry 4 ends with a slash, which wreaks havoc with RPM's debugedit utility that is run while building an RPM.

Reproducing this:

$ /usr/lib/rpm/debugedit -b / -d / target/release/liblto_bug.so
/usr/lib/rpm/debugedit: canonicalization unexpectedly shrank by one character

See this Red Hat bug report that describes the problem.
It could be considered a bug in debugedit, but it's very longstanding and would be great if Rust didn't do this.

It seems to be some an unintentional side effect that the directory /rustc/18bf6b4f01a6feaf7259ba7cdae58031af1b7b39/ is added to the directory table, certainly with the terminating slash.

I tried to see if I could work around this by using --remap-path-prefix, but that seems to have no effect at all on this path.

Meta

rustc --version --verbose:

rustc 1.47.0 (18bf6b4f0 2020-10-07)
binary: rustc
commit-hash: 18bf6b4f01a6feaf7259ba7cdae58031af1b7b39
commit-date: 2020-10-07
host: x86_64-unknown-linux-gnu
release: 1.47.0
LLVM version: 11.0

Also happens with nightly:

rustc 1.49.0-nightly (ffa2e7ae8 2020-10-24)
binary: rustc
commit-hash: ffa2e7ae8fbf9badc035740db949b9dae271c29f
commit-date: 2020-10-24
host: x86_64-unknown-linux-gnu
release: 1.49.0-nightly
LLVM version: 11.0

@gavrie gavrie added the C-bug Category: This is a bug. label Oct 27, 2020
@camelid camelid added A-linkage Area: linking into static, shared libraries and binaries T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-lto Area: Link Time Optimization labels Oct 27, 2020
@Enselic
Copy link
Member

Enselic commented Dec 16, 2023

Triage: Is this still a problem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-linkage Area: linking into static, shared libraries and binaries A-lto Area: Link Time Optimization C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants