Skip to content

Rollup of 11 pull requests #134098

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 44 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
1696f53
fix: rust-lang/rust#47446
sassman Oct 9, 2024
529aae6
wasi/fs: Improve stopping condition for <ReadDir as Iterator>::next
osiewicz Nov 18, 2024
ec5f41a
Run TLS destructors for wasm32-wasip1-threads
surban Nov 23, 2024
692c19a
Refactor ReadDir into a state machine
osiewicz Nov 26, 2024
f4ab982
chore: Improve doc comments
osiewicz Nov 26, 2024
9142cae
add `LinkageInfo` to keep track of how we figured out the linkage
folkertdev Aug 8, 2024
bdf64e1
squashed changes to inlining and const eval
folkertdev Jul 19, 2024
d67a5c0
test the new global asm output of naked functions
folkertdev Jul 19, 2024
a93192c
add `InstructionSetAttr::as_str` and make the type `Copy`
folkertdev Jul 20, 2024
49a297a
squashed changes to tests
folkertdev Jul 20, 2024
589ebb8
make naked functions always have external linkage *in LLVM*. If we do…
folkertdev Jul 26, 2024
2e24cdb
squashed changes:
folkertdev Aug 11, 2024
64420b6
skip `predefine_fn` for naked functions
folkertdev Nov 30, 2024
cf738f6
Revert "add `LinkageInfo` to keep track of how we figured out the lin…
folkertdev Nov 30, 2024
868668e
Run `cargo update` and update licenses
clubby789 Nov 25, 2024
4fe15b0
Use UNIX thread_local implementation for WASI.
surban Dec 3, 2024
30847eb
use vendor sources by default on dist tarballs
onur-ozkan Dec 4, 2024
a6aaef1
update `build.vendor` documentation
onur-ozkan Dec 4, 2024
9ca9b41
add a change entry for new default on `build.vendor`
onur-ozkan Dec 4, 2024
e4092bd
Fix compilation for wasm32-wasip1 (without threads).
surban Dec 5, 2024
4f16640
Add libc funcitons only for wasm32-wasip1-threads.
surban Dec 5, 2024
ac815ff
coverage: Prefer to visit nodes whose predecessors have been visited
Zalathar Dec 5, 2024
f3f7c20
coverage: Move `CoverageIdsInfo` into `mir::coverage`
Zalathar Dec 6, 2024
2022ef7
coverage: Use a query to find counters/expressions that must be zero
Zalathar Dec 6, 2024
4d2bfec
coverage: Remove FunctionCoverageCollector
Zalathar Dec 6, 2024
3a35fb6
coverage: Unused functions don't need to store `CoverageIdsInfo`
Zalathar Dec 8, 2024
9eb35a0
fix the `naked-asan` test
folkertdev Dec 1, 2024
2d8a871
Downgrade cc
clubby789 Dec 8, 2024
4f14890
Configure renovatebot
Kobzol Dec 9, 2024
ed8ee39
fix ICE on type error in promoted
RalfJung Dec 7, 2024
a9fc2e2
Add feature gate, not working yet
compiler-errors Nov 16, 2024
7951d19
Apply suggestions from code review
sassman Dec 9, 2024
3511a46
Implement projection and shim for AFIDT
compiler-errors Nov 16, 2024
b02fcc5
Rollup merge of #128004 - folkertdev:naked-fn-asm, r=Amanieu
fmease Dec 9, 2024
35fc15b
Rollup merge of #131558 - sassman:feat/warnin-for-no-mangle-together-…
fmease Dec 9, 2024
d0f329a
Rollup merge of #133122 - compiler-errors:afidt, r=oli-obk
fmease Dec 9, 2024
00a7584
Rollup merge of #133184 - osiewicz:wasm-fix-infinite-loop-in-remove-d…
fmease Dec 9, 2024
18419d0
Rollup merge of #133456 - clubby789:cargo-update, r=ChrisDenton
fmease Dec 9, 2024
2b252ba
Rollup merge of #133472 - rust-wasi-web:master, r=joboet
fmease Dec 9, 2024
0c87c3c
Rollup merge of #133853 - onur-ozkan:use-vendor-directory-on-dist-bui…
fmease Dec 9, 2024
69889fa
Rollup merge of #133946 - Zalathar:ready-first, r=oli-obk
fmease Dec 9, 2024
65e8897
Rollup merge of #134010 - RalfJung:promoted-type-error-ice, r=oli-obk
fmease Dec 9, 2024
ce27319
Rollup merge of #134029 - Zalathar:zero, r=oli-obk
fmease Dec 9, 2024
d5b0698
Rollup merge of #134071 - Kobzol:ci-renovatebot, r=MarcoIeni
fmease Dec 9, 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
Prev Previous commit
Next Next commit
skip predefine_fn for naked functions
  • Loading branch information
folkertdev committed Nov 30, 2024
commit 64420b6ea81d9f7065421add9843ba22e876cd6c
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_llvm/src/mono_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ impl<'tcx> PreDefineCodegenMethods<'tcx> for CodegenCx<'_, 'tcx> {

let fn_abi = self.fn_abi_of_instance(instance, ty::List::empty());
let lldecl = self.declare_fn(symbol_name, fn_abi, Some(instance));
let attrs = self.tcx.codegen_fn_attrs(instance.def_id());
llvm::set_linkage(lldecl, base::linkage_to_llvm(linkage));
let attrs = self.tcx.codegen_fn_attrs(instance.def_id());
base::set_link_section(lldecl, attrs);
if (linkage == Linkage::LinkOnceODR || linkage == Linkage::WeakODR)
&& self.tcx.sess.target.supports_comdat()
Expand Down
40 changes: 36 additions & 4 deletions compiler/rustc_codegen_ssa/src/mir/naked_asm.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use rustc_attr::InstructionSetAttr;
use rustc_middle::mir::mono::{MonoItem, MonoItemData, Visibility};
use rustc_middle::mir::mono::{Linkage, MonoItem, MonoItemData, Visibility};
use rustc_middle::mir::{Body, InlineAsmOperand};
use rustc_middle::ty::layout::{HasTyCtxt, HasTypingEnv, LayoutOf};
use rustc_middle::ty::{Instance, TyCtxt};
Expand Down Expand Up @@ -153,6 +153,30 @@ fn prefix_and_suffix<'tcx>(
("", "")
};

let emit_fatal = |msg| tcx.dcx().span_fatal(tcx.def_span(instance.def_id()), msg);

// see https://godbolt.org/z/cPK4sxKor.
// None means the default, which corresponds to internal linkage
let linkage = match item_data.linkage {
Linkage::External => Some(".globl"),
Linkage::LinkOnceAny => Some(".weak"),
Linkage::LinkOnceODR => Some(".weak"),
Linkage::WeakAny => Some(".weak"),
Linkage::WeakODR => Some(".weak"),
Linkage::Internal => None,
Linkage::Private => None,
Linkage::Appending => emit_fatal("Only global variables can have appending linkage!"),
Linkage::Common => emit_fatal("Functions may not have common linkage"),
Linkage::AvailableExternally => {
// this would make the function equal an extern definition
emit_fatal("Functions may not have available_externally linkage")
}
Linkage::ExternalWeak => {
// FIXME: actually this causes a SIGILL in LLVM
emit_fatal("Functions may not have external weak linkage")
}
};

let mut begin = String::new();
let mut end = String::new();
match AsmBinaryFormat::from_target(&tcx.sess.target) {
Expand All @@ -171,7 +195,9 @@ fn prefix_and_suffix<'tcx>(

writeln!(begin, ".pushsection {section},\"ax\", {progbits}").unwrap();
writeln!(begin, ".balign {align}").unwrap();
writeln!(begin, ".globl {asm_name}").unwrap();
if let Some(linkage) = linkage {
writeln!(begin, "{linkage} {asm_name}").unwrap();
}
if let Visibility::Hidden = item_data.visibility {
writeln!(begin, ".hidden {asm_name}").unwrap();
}
Expand All @@ -181,6 +207,8 @@ fn prefix_and_suffix<'tcx>(
}
writeln!(begin, "{asm_name}:").unwrap();

eprintln!("{}", &begin);

writeln!(end).unwrap();
writeln!(end, ".size {asm_name}, . - {asm_name}").unwrap();
writeln!(end, ".popsection").unwrap();
Expand All @@ -192,7 +220,9 @@ fn prefix_and_suffix<'tcx>(
let section = link_section.unwrap_or("__TEXT,__text".to_string());
writeln!(begin, ".pushsection {},regular,pure_instructions", section).unwrap();
writeln!(begin, ".balign {align}").unwrap();
writeln!(begin, ".globl {asm_name}").unwrap();
if let Some(linkage) = linkage {
writeln!(begin, "{linkage} {asm_name}").unwrap();
}
if let Visibility::Hidden = item_data.visibility {
writeln!(begin, ".private_extern {asm_name}").unwrap();
}
Expand All @@ -208,7 +238,9 @@ fn prefix_and_suffix<'tcx>(
let section = link_section.unwrap_or(format!(".text.{asm_name}"));
writeln!(begin, ".pushsection {},\"xr\"", section).unwrap();
writeln!(begin, ".balign {align}").unwrap();
writeln!(begin, ".globl {asm_name}").unwrap();
if let Some(linkage) = linkage {
writeln!(begin, "{linkage} {asm_name}").unwrap();
}
writeln!(begin, ".def {asm_name}").unwrap();
writeln!(begin, ".scl 2").unwrap();
writeln!(begin, ".type 32").unwrap();
Expand Down
9 changes: 4 additions & 5 deletions compiler/rustc_codegen_ssa/src/mono_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,12 @@ impl<'a, 'tcx: 'a> MonoItemExt<'a, 'tcx> for MonoItem<'tcx> {
}
MonoItem::Fn(instance) => {
let attrs = cx.tcx().codegen_fn_attrs(instance.def_id());
let linkage = if attrs.flags.contains(CodegenFnAttrFlags::NAKED) {
linkage_info.into_naked_linkage()

if attrs.flags.contains(CodegenFnAttrFlags::NAKED) {
// do not define this function; it will become a global assembly block
} else {
linkage_info.into_linkage()
cx.predefine_fn(instance, linkage_info.into_linkage(), visibility, symbol_name);
};

cx.predefine_fn(instance, linkage, visibility, symbol_name);
}
MonoItem::GlobalAsm(..) => {}
}
Expand Down
22 changes: 0 additions & 22 deletions compiler/rustc_middle/src/mir/mono.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,28 +299,6 @@ impl LinkageInfo {
Self::ImplicitInternal => Linkage::Internal,
}
}

/// Linkage when the MonoItem is a naked function
///
/// Naked functions are generated as a separate declaration (effectively an extern fn) and
/// definition (using global assembly). To link them together, some flavor of external linkage
/// must be used.
///
/// This should be just an implementation detail of the backend, which is why this translation
/// is made at the final moment.
pub const fn into_naked_linkage(self) -> Linkage {
match self {
// promote Weak linkage to ExternalWeak
Self::Explicit(Linkage::WeakAny | Linkage::WeakODR) => Linkage::ExternalWeak,
Self::Explicit(linkage) => linkage,

// the "implicit" means that linkage is picked by the partitioning algorithm.
// picking external should always be valid (given that we are in fact linking
// to the global assembly in the same CGU)
Self::ImplicitExternal => Linkage::External,
Self::ImplicitInternal => Linkage::External,
}
}
}

/// Specifies the linkage type for a `MonoItem`.
Expand Down