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

Unused symbol breaks Profiled Guided Optimization (PGO) #57258

Open
robsmith11 opened this issue Jan 2, 2019 · 0 comments
Open

Unused symbol breaks Profiled Guided Optimization (PGO) #57258

robsmith11 opened this issue Jan 2, 2019 · 0 comments
Labels
A-linkage Area: linking into static, shared libraries and binaries C-bug Category: This is a bug.

Comments

@robsmith11
Copy link

robsmith11 commented Jan 2, 2019

My crate is structured to build both a bin and a dylib that is loaded by a 3rd-party program. The stand-alone bin part doesn't actually use any of the external symbols, so despite it sharing code with the lib part, it runs fine without the symbols being defined.

However, when I turn on PGO, these undefined symbols cause linking errors. My expectation is that if my crate works without PGO, it should work with PGO enabled, but maybe that's incorrect?

My actual crate gets these undefined symbols from here:
https://github.com/robsmith11/krust/blob/master/src/kbindings.rs#L483

But this minimal example reproduces the problem:

fn main() {
}

extern "C" {
    pub fn f();
}

#[no_mangle]
pub extern fn g() {
    unsafe { f(); }
}
$ RUSTFLAGS="-Z pgo-gen=/tmp/prof.data" cargo run --release 
    Compiling play v0.1.0 (/home/me/e/code/play)
error: linking with `cc` failed: exit code: 1
  |
  = note: "cc" "-Wl,--as-needed" "-Wl,-z,noexecstack" "-m64" "-L" "/home/me/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "/tmp/target_play/release/deps/play-e890b10933e5432f.play.1uu11z5v-cgu.0.rcgu.o" "-o" "/tmp/target_play/release/deps/play-e890b10933e5432f" "-Wl,--gc-sections" "-pie" "-Wl,-zrelro" "-Wl,-znow" "-Wl,-O1" "-nodefaultlibs" "-L" "/tmp/target_play/release/deps" "-L" "/home/me/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,-Bstatic" "/tmp/rustcvLfVyu/libprofiler_builtins-4ecfbf392fb1b2b9.rlib" "-Wl,--start-group" "/tmp/rustcvLfVyu/libstd-4f6a41fe25da1d4f.rlib" "-Wl,--end-group" "/home/me/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-cd088bc8787919ee.rlib" "-Wl,-Bdynamic" "-ldl" "-lrt" "-lpthread" "-lgcc_s" "-lc" "-lm" "-lrt" "-lpthread" "-lutil" "-lutil" "-u" "__llvm_profile_runtime"
  = note: /usr/bin/ld: /tmp/target_play/release/deps/play-e890b10933e5432f.play.1uu11z5v-cgu.0.rcgu.o: in function `g':
          play.1uu11z5v-cgu.0:(.text.g+0xa): undefined reference to `f'
          collect2: error: ld returned 1 exit status

EDIT:
Not sure whether it's relevant, but removing the #[no_mangle] makes it work with PGO.

@jonas-schievink jonas-schievink added A-linkage Area: linking into static, shared libraries and binaries O-Arm Target: 32-bit Arm processors (armv6, armv7, thumb...), including 64-bit Arm in AArch32 state labels Jan 26, 2019
@michaelwoerister michaelwoerister added the C-bug Category: This is a bug. label Apr 12, 2019
@workingjubilee workingjubilee removed the O-Arm Target: 32-bit Arm processors (armv6, armv7, thumb...), including 64-bit Arm in AArch32 state label Mar 23, 2022
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 C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

4 participants