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

Rollup of 5 pull requests #132175

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
9f8a6be
coverage: Consolidate creation of covmap/covfun records
Zalathar Oct 24, 2024
0a96176
coverage: Make obtaining the codegen coverage context infallible
Zalathar Oct 24, 2024
0356908
coverage: Store `covfun_section_name` in the codegen context
Zalathar Oct 24, 2024
e2d3f5a
Allow building rustc's LLVM with Offload support
ZuseZ4 Oct 11, 2024
aa14cb8
Add a macro that derives `TryFrom<u32>` for fieldless enums
Zalathar Oct 25, 2024
ce87180
Use safe wrappers `get_linkage` and `set_linkage`
Zalathar Oct 25, 2024
62ffe3d
Use safe wrappers `get_visibility` and `set_visibility`
Zalathar Oct 19, 2024
f2f6723
Deny calls to non-`#[const_trait]` methods in MIR constck
fee1-dead Oct 26, 2024
becd32c
Add a wrapper type for raw enum values returned by LLVM
Zalathar Oct 25, 2024
1aed407
Use LLVM-C APIs for getting/setting linkage
Zalathar Oct 25, 2024
3e51f6f
Use LLVM-C APIs for getting/setting visibility
Zalathar Oct 25, 2024
0d653a5
coverage: Add links to LLVM docs for the coverage mapping format
Zalathar Oct 26, 2024
867640e
x86 target features: make pclmulqdq imply sse2
RalfJung Oct 26, 2024
9e17703
Rollup merge of #131527 - ZuseZ4:enable-llvm-offload-runtime, r=Kobzol
Zalathar Oct 26, 2024
6813884
Rollup merge of #132124 - Zalathar:consolidate-covstar, r=jieyouxu
Zalathar Oct 26, 2024
a72b321
Rollup merge of #132167 - Zalathar:llvm-wrappers, r=jieyouxu
Zalathar Oct 26, 2024
18aa883
Rollup merge of #132169 - fee1-dead-contrib:consttraitsck, r=compiler…
Zalathar Oct 26, 2024
a8d2f9c
Rollup merge of #132174 - RalfJung:pclmulqdq, r=calebzulawski
Zalathar Oct 26, 2024
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
17 changes: 4 additions & 13 deletions compiler/rustc_codegen_llvm/src/allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,20 +77,14 @@ pub(crate) unsafe fn codegen(
// __rust_alloc_error_handler_should_panic
let name = OomStrategy::SYMBOL;
let ll_g = llvm::LLVMRustGetOrInsertGlobal(llmod, name.as_ptr().cast(), name.len(), i8);
llvm::LLVMRustSetVisibility(
ll_g,
llvm::Visibility::from_generic(tcx.sess.default_visibility()),
);
llvm::set_visibility(ll_g, llvm::Visibility::from_generic(tcx.sess.default_visibility()));
let val = tcx.sess.opts.unstable_opts.oom.should_panic();
let llval = llvm::LLVMConstInt(i8, val as u64, False);
llvm::LLVMSetInitializer(ll_g, llval);

let name = NO_ALLOC_SHIM_IS_UNSTABLE;
let ll_g = llvm::LLVMRustGetOrInsertGlobal(llmod, name.as_ptr().cast(), name.len(), i8);
llvm::LLVMRustSetVisibility(
ll_g,
llvm::Visibility::from_generic(tcx.sess.default_visibility()),
);
llvm::set_visibility(ll_g, llvm::Visibility::from_generic(tcx.sess.default_visibility()));
let llval = llvm::LLVMConstInt(i8, 0, False);
llvm::LLVMSetInitializer(ll_g, llval);
}
Expand Down Expand Up @@ -134,10 +128,7 @@ fn create_wrapper_function(
None
};

llvm::LLVMRustSetVisibility(
llfn,
llvm::Visibility::from_generic(tcx.sess.default_visibility()),
);
llvm::set_visibility(llfn, llvm::Visibility::from_generic(tcx.sess.default_visibility()));

if tcx.sess.must_emit_unwind_tables() {
let uwtable =
Expand All @@ -151,7 +142,7 @@ fn create_wrapper_function(
// -> ! DIFlagNoReturn
attributes::apply_to_llfn(callee, llvm::AttributePlace::Function, &[no_return]);
}
llvm::LLVMRustSetVisibility(callee, llvm::Visibility::Hidden);
llvm::set_visibility(callee, llvm::Visibility::Hidden);

let llbb = llvm::LLVMAppendBasicBlockInContext(llcx, llfn, c"entry".as_ptr());

Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_codegen_llvm/src/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1043,7 +1043,7 @@ unsafe fn embed_bitcode(

let section = bitcode_section_name(cgcx);
llvm::LLVMSetSection(llglobal, section.as_ptr().cast());
llvm::LLVMRustSetLinkage(llglobal, llvm::Linkage::PrivateLinkage);
llvm::set_linkage(llglobal, llvm::Linkage::PrivateLinkage);
llvm::LLVMSetGlobalConstant(llglobal, llvm::True);

let llconst = common::bytes_in_context(llcx, cmdline.as_bytes());
Expand All @@ -1061,7 +1061,7 @@ unsafe fn embed_bitcode(
c".llvmcmd"
};
llvm::LLVMSetSection(llglobal, section.as_ptr());
llvm::LLVMRustSetLinkage(llglobal, llvm::Linkage::PrivateLinkage);
llvm::set_linkage(llglobal, llvm::Linkage::PrivateLinkage);
} else {
// We need custom section flags, so emit module-level inline assembly.
let section_flags = if cgcx.is_pe_coff { "n" } else { "e" };
Expand Down Expand Up @@ -1096,7 +1096,7 @@ fn create_msvc_imps(
let ptr_ty = Type::ptr_llcx(llcx);
let globals = base::iter_globals(llmod)
.filter(|&val| {
llvm::LLVMRustGetLinkage(val) == llvm::Linkage::ExternalLinkage
llvm::get_linkage(val) == llvm::Linkage::ExternalLinkage
&& llvm::LLVMIsDeclaration(val) == 0
})
.filter_map(|val| {
Expand All @@ -1115,7 +1115,7 @@ fn create_msvc_imps(
for (imp_name, val) in globals {
let imp = llvm::LLVMAddGlobal(llmod, ptr_ty, imp_name.as_ptr());
llvm::LLVMSetInitializer(imp, val);
llvm::LLVMRustSetLinkage(imp, llvm::Linkage::ExternalLinkage);
llvm::set_linkage(imp, llvm::Linkage::ExternalLinkage);
}
}

Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_codegen_llvm/src/callee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ pub(crate) fn get_fn<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>, instance: Instance<'t
// whether we are sharing generics or not. The important thing here is
// that the visibility we apply to the declaration is the same one that
// has been applied to the definition (wherever that definition may be).
unsafe {
llvm::LLVMRustSetLinkage(llfn, llvm::Linkage::ExternalLinkage);

llvm::set_linkage(llfn, llvm::Linkage::ExternalLinkage);
unsafe {
let is_generic =
instance.args.non_erasable_generics(tcx, instance.def_id()).next().is_some();

Expand Down Expand Up @@ -136,7 +136,7 @@ pub(crate) fn get_fn<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>, instance: Instance<'t
|| !cx.tcx.is_reachable_non_generic(instance_def_id))
};
if is_hidden {
llvm::LLVMRustSetVisibility(llfn, llvm::Visibility::Hidden);
llvm::set_visibility(llfn, llvm::Visibility::Hidden);
}

// MinGW: For backward compatibility we rely on the linker to decide whether it
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_llvm/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,8 @@ impl<'ll, 'tcx> ConstCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> {
llvm::LLVMSetInitializer(g, sc);
llvm::LLVMSetGlobalConstant(g, True);
llvm::LLVMSetUnnamedAddress(g, llvm::UnnamedAddr::Global);
llvm::LLVMRustSetLinkage(g, llvm::Linkage::InternalLinkage);
}
llvm::set_linkage(g, llvm::Linkage::InternalLinkage);
(s.to_owned(), g)
})
.1;
Expand Down
90 changes: 42 additions & 48 deletions compiler/rustc_codegen_llvm/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,29 +172,27 @@ fn check_and_apply_linkage<'ll, 'tcx>(
if let Some(linkage) = attrs.import_linkage {
debug!("get_static: sym={} linkage={:?}", sym, linkage);

unsafe {
// Declare a symbol `foo` with the desired linkage.
let g1 = cx.declare_global(sym, cx.type_i8());
llvm::LLVMRustSetLinkage(g1, base::linkage_to_llvm(linkage));

// Declare an internal global `extern_with_linkage_foo` which
// is initialized with the address of `foo`. If `foo` is
// discarded during linking (for example, if `foo` has weak
// linkage and there are no definitions), then
// `extern_with_linkage_foo` will instead be initialized to
// zero.
let mut real_name = "_rust_extern_with_linkage_".to_string();
real_name.push_str(sym);
let g2 = cx.define_global(&real_name, llty).unwrap_or_else(|| {
cx.sess().dcx().emit_fatal(SymbolAlreadyDefined {
span: cx.tcx.def_span(def_id),
symbol_name: sym,
})
});
llvm::LLVMRustSetLinkage(g2, llvm::Linkage::InternalLinkage);
llvm::LLVMSetInitializer(g2, g1);
g2
}
// Declare a symbol `foo` with the desired linkage.
let g1 = cx.declare_global(sym, cx.type_i8());
llvm::set_linkage(g1, base::linkage_to_llvm(linkage));

// Declare an internal global `extern_with_linkage_foo` which
// is initialized with the address of `foo`. If `foo` is
// discarded during linking (for example, if `foo` has weak
// linkage and there are no definitions), then
// `extern_with_linkage_foo` will instead be initialized to
// zero.
let mut real_name = "_rust_extern_with_linkage_".to_string();
real_name.push_str(sym);
let g2 = cx.define_global(&real_name, llty).unwrap_or_else(|| {
cx.sess().dcx().emit_fatal(SymbolAlreadyDefined {
span: cx.tcx.def_span(def_id),
symbol_name: sym,
})
});
llvm::set_linkage(g2, llvm::Linkage::InternalLinkage);
unsafe { llvm::LLVMSetInitializer(g2, g1) };
g2
} else if cx.tcx.sess.target.arch == "x86"
&& let Some(dllimport) = crate::common::get_dllimport(cx.tcx, def_id, sym)
{
Expand Down Expand Up @@ -224,23 +222,21 @@ impl<'ll> CodegenCx<'ll, '_> {
align: Align,
kind: Option<&str>,
) -> &'ll Value {
unsafe {
let gv = match kind {
Some(kind) if !self.tcx.sess.fewer_names() => {
let name = self.generate_local_symbol_name(kind);
let gv = self.define_global(&name, self.val_ty(cv)).unwrap_or_else(|| {
bug!("symbol `{}` is already defined", name);
});
llvm::LLVMRustSetLinkage(gv, llvm::Linkage::PrivateLinkage);
gv
}
_ => self.define_private_global(self.val_ty(cv)),
};
llvm::LLVMSetInitializer(gv, cv);
set_global_alignment(self, gv, align);
llvm::SetUnnamedAddress(gv, llvm::UnnamedAddr::Global);
gv
}
let gv = match kind {
Some(kind) if !self.tcx.sess.fewer_names() => {
let name = self.generate_local_symbol_name(kind);
let gv = self.define_global(&name, self.val_ty(cv)).unwrap_or_else(|| {
bug!("symbol `{}` is already defined", name);
});
llvm::set_linkage(gv, llvm::Linkage::PrivateLinkage);
gv
}
_ => self.define_private_global(self.val_ty(cv)),
};
unsafe { llvm::LLVMSetInitializer(gv, cv) };
set_global_alignment(self, gv, align);
llvm::SetUnnamedAddress(gv, llvm::UnnamedAddr::Global);
gv
}

#[instrument(level = "debug", skip(self))]
Expand Down Expand Up @@ -292,9 +288,7 @@ impl<'ll> CodegenCx<'ll, '_> {
let g = self.declare_global(sym, llty);

if !self.tcx.is_reachable_non_generic(def_id) {
unsafe {
llvm::LLVMRustSetVisibility(g, llvm::Visibility::Hidden);
}
llvm::set_visibility(g, llvm::Visibility::Hidden);
}

g
Expand All @@ -312,7 +306,7 @@ impl<'ll> CodegenCx<'ll, '_> {
llvm::set_thread_local_mode(g, self.tls_model);
}

let dso_local = unsafe { self.should_assume_dso_local(g, true) };
let dso_local = self.should_assume_dso_local(g, true);
if dso_local {
unsafe {
llvm::LLVMRustSetDSOLocal(g, true);
Expand Down Expand Up @@ -401,8 +395,8 @@ impl<'ll> CodegenCx<'ll, '_> {
let name = llvm::get_value_name(g).to_vec();
llvm::set_value_name(g, b"");

let linkage = llvm::LLVMRustGetLinkage(g);
let visibility = llvm::LLVMRustGetVisibility(g);
let linkage = llvm::get_linkage(g);
let visibility = llvm::get_visibility(g);

let new_g = llvm::LLVMRustGetOrInsertGlobal(
self.llmod,
Expand All @@ -411,8 +405,8 @@ impl<'ll> CodegenCx<'ll, '_> {
val_llty,
);

llvm::LLVMRustSetLinkage(new_g, linkage);
llvm::LLVMRustSetVisibility(new_g, visibility);
llvm::set_linkage(new_g, linkage);
llvm::set_visibility(new_g, visibility);

// The old global has had its name removed but is returned by
// get_static since it is in the instance cache. Provide an
Expand Down
10 changes: 5 additions & 5 deletions compiler/rustc_codegen_llvm/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ pub(crate) struct CodegenCx<'ll, 'tcx> {

pub isize_ty: &'ll Type,

/// Extra codegen state needed when coverage instrumentation is enabled.
pub coverage_cx: Option<coverageinfo::CrateCoverageContext<'ll, 'tcx>>,
pub dbg_cx: Option<debuginfo::CodegenUnitDebugContext<'ll, 'tcx>>,

Expand Down Expand Up @@ -592,11 +593,10 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
&self.statics_to_rauw
}

/// Extra state that is only available when coverage instrumentation is enabled.
#[inline]
pub(crate) fn coverage_context(
&self,
) -> Option<&coverageinfo::CrateCoverageContext<'ll, 'tcx>> {
self.coverage_cx.as_ref()
pub(crate) fn coverage_cx(&self) -> &coverageinfo::CrateCoverageContext<'ll, 'tcx> {
self.coverage_cx.as_ref().expect("only called when coverage instrumentation is enabled")
}

pub(crate) fn create_used_variable_impl(&self, name: &'static CStr, values: &[&'ll Value]) {
Expand All @@ -605,7 +605,7 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
unsafe {
let g = llvm::LLVMAddGlobal(self.llmod, self.val_ty(array), name.as_ptr());
llvm::LLVMSetInitializer(g, array);
llvm::LLVMRustSetLinkage(g, llvm::Linkage::AppendingLinkage);
llvm::set_linkage(g, llvm::Linkage::AppendingLinkage);
llvm::LLVMSetSection(g, c"llvm.metadata".as_ptr());
}
}
Expand Down
Loading
Loading