Skip to content

Run name-anon-globals after LTO passes as well #55609

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

Merged
merged 1 commit into from
Nov 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/librustc_codegen_llvm/back/lto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,13 @@ fn run_pass_manager(cgcx: &CodegenContext,
}
});

// We always generate bitcode through ThinLTOBuffers,
// which do not support anonymous globals
if config.bitcode_needed() {
let pass = llvm::LLVMRustFindAndCreatePass("name-anon-globals\0".as_ptr() as *const _);
llvm::LLVMRustAddPass(pm, pass.unwrap());
}

if config.verify_llvm_ir {
let pass = llvm::LLVMRustFindAndCreatePass("verify\0".as_ptr() as *const _);
llvm::LLVMRustAddPass(pm, pass.unwrap());
Expand Down
8 changes: 6 additions & 2 deletions src/librustc_codegen_llvm/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,11 @@ impl ModuleConfig {
self.merge_functions = sess.opts.optimize == config::OptLevel::Default ||
sess.opts.optimize == config::OptLevel::Aggressive;
}

pub fn bitcode_needed(&self) -> bool {
self.emit_bc || self.obj_is_bitcode
|| self.emit_bc_compressed || self.embed_bitcode
}
}

/// Assembler name and command used by codegen when no_integrated_as is enabled
Expand Down Expand Up @@ -564,8 +569,7 @@ unsafe fn optimize(cgcx: &CodegenContext,
// Some options cause LLVM bitcode to be emitted, which uses ThinLTOBuffers, so we need
// to make sure we run LLVM's NameAnonGlobals pass when emitting bitcode; otherwise
// we'll get errors in LLVM.
let using_thin_buffers = config.emit_bc || config.obj_is_bitcode
|| config.emit_bc_compressed || config.embed_bitcode;
let using_thin_buffers = config.bitcode_needed();
let mut have_name_anon_globals_pass = false;
if !config.no_prepopulate_passes {
llvm::LLVMRustAddAnalysisPasses(tm, fpm, llmod);
Expand Down
17 changes: 17 additions & 0 deletions src/test/ui/issue-51947.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// compile-pass

#![crate_type = "lib"]
#![feature(linkage)]

// MergeFunctions will merge these via an anonymous internal
// backing function, which must be named if ThinLTO buffers are used

#[linkage = "weak"]
pub fn fn1(a: u32, b: u32, c: u32) -> u32 {
a + b + c
}

#[linkage = "weak"]
pub fn fn2(a: u32, b: u32, c: u32) -> u32 {
a + b + c
}