Skip to content

mark glue functions with unnamed_addr #6787

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

Closed
wants to merge 2 commits into from
Closed
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
14 changes: 14 additions & 0 deletions src/librustc/lib/llvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1903,6 +1903,10 @@ pub mod llvm {
Constraints: *c_char, SideEffects: Bool,
AlignStack: Bool, Dialect: c_uint)
-> ValueRef;

#[fast_ffi]
pub unsafe fn LLVMSetUnnamedAddr(Global: ValueRef, value: Bool);

}
}

Expand All @@ -1911,27 +1915,37 @@ pub fn SetInstructionCallConv(Instr: ValueRef, CC: CallConv) {
llvm::LLVMSetInstructionCallConv(Instr, CC as c_uint);
}
}

pub fn SetFunctionCallConv(Fn: ValueRef, CC: CallConv) {
unsafe {
llvm::LLVMSetFunctionCallConv(Fn, CC as c_uint);
}
}

pub fn SetLinkage(Global: ValueRef, Link: Linkage) {
unsafe {
llvm::LLVMSetLinkage(Global, Link as c_uint);
}
}

pub fn set_unnamed_addr(global: ValueRef, value: bool) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this follow the same convention as all the other bindings? That is SetUnnamedAddr

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, that seems like a legacy wart since we're using that convention for types now. I'm open to changing it though if we really want to be using that convention.

unsafe {
llvm::LLVMSetUnnamedAddr(global, value as Bool)
}
}

pub fn ConstICmp(Pred: IntPredicate, V1: ValueRef, V2: ValueRef) -> ValueRef {
unsafe {
llvm::LLVMConstICmp(Pred as c_ushort, V1, V2)
}
}

pub fn ConstFCmp(Pred: RealPredicate, V1: ValueRef, V2: ValueRef) -> ValueRef {
unsafe {
llvm::LLVMConstFCmp(Pred as c_ushort, V1, V2)
}
}

/* Memory-managed object interface to type handles. */

pub struct TypeNames {
Expand Down
7 changes: 6 additions & 1 deletion src/librustc/middle/trans/glue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,12 @@ pub fn declare_generic_glue(ccx: @CrateContext, t: ty::t, llfnty: TypeRef,
note_unique_llvm_symbol(ccx, fn_nm);
let llfn = decl_cdecl_fn(ccx.llmod, *fn_nm, llfnty);
set_glue_inlining(llfn, t);
return llfn;

// glue functions aren't visible to user code, so function pointer addresses are never
// semantically relevant - we can inform LLVM and allow it to merge the functions
lib::llvm::set_unnamed_addr(llfn, true);

llfn
}

pub fn make_generic_glue_inner(ccx: @CrateContext,
Expand Down
5 changes: 5 additions & 0 deletions src/rustllvm/RustWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -603,3 +603,8 @@ extern "C" LLVMValueRef LLVMInlineAsm(LLVMTypeRef Ty,
Constraints, HasSideEffects,
IsAlignStack, (InlineAsm::AsmDialect) Dialect));
}

extern "C" void LLVMSetUnnamedAddr(LLVMValueRef Global, LLVMBool value) {
GlobalValue *GV = unwrap<GlobalValue>(Global);
GV->setUnnamedAddr(value);
}