Skip to content
Open
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
4 changes: 3 additions & 1 deletion compiler/rustc_codegen_llvm/src/callee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ pub(crate) fn get_fn<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>, instance: Instance<'t

let fn_abi = cx.fn_abi_of_instance(instance, ty::List::empty());

let llfn = if let Some(llfn) = cx.get_declared_value(sym) {
let llfn = if let Some(llfn) = cx.get_declared_value(sym)
&& (!cx.tcx.is_codegened_item(instance.def_id()) || !instance.def_id().is_local())
Copy link
Member

Choose a reason for hiding this comment

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

This will break things badly. With this change every time you refer to a different raw-dylib import of the same function, LLVM will use a different name for the function in the object file. For example open, open.1, open.2, ... Only the first reference will actually be resolved by the import library. Also in the case of #113050 where someone defines a local function with the same name, if this function is declared first, then the raw-dylib import get the mangled name and if it is declared second, then if another codegen unit tries to call this function it will call the raw-dylib instead.

The only fix for #113050 I can think of is to have rustc mangle raw-dylib imports and also record this mangled name in the import library rustc generates. The issue with that however is that when a user does want to override a raw-dylib import, they can't do that anymore either.

{
llfn
} else {
let instance_def_id = instance.def_id();
Expand Down
Loading