diff options
author | V3n3RiX <venerix@koprulu.sector> | 2024-12-11 02:01:11 +0000 |
---|---|---|
committer | V3n3RiX <venerix@koprulu.sector> | 2024-12-11 02:01:11 +0000 |
commit | 494ca58c9f5243dd4b56557aa8c41bce76e95ec3 (patch) | |
tree | b699beb74ae3071c865d4f2e95ed7f376f99214a /dev-lang/rust | |
parent | 59437d191de3ff33f9bfa37f8656d849184fcaf0 (diff) |
gentoo auto-resync : 11:12:2024 - 02:01:11
Diffstat (limited to 'dev-lang/rust')
-rw-r--r-- | dev-lang/rust/Manifest | 3 | ||||
-rw-r--r-- | dev-lang/rust/files/1.83.0-dwarf-llvm-assertion.patch | 242 | ||||
-rw-r--r-- | dev-lang/rust/rust-1.83.0-r1.ebuild (renamed from dev-lang/rust/rust-1.83.0.ebuild) | 1 |
3 files changed, 245 insertions, 1 deletions
diff --git a/dev-lang/rust/Manifest b/dev-lang/rust/Manifest index e054f68d645d..1b9e2180326e 100644 --- a/dev-lang/rust/Manifest +++ b/dev-lang/rust/Manifest @@ -20,6 +20,7 @@ AUX 1.81.0-backport-llvm-pr101766.patch 1247 BLAKE2B fd809b6a7f6f7c4e0d324aa2912 AUX 1.82.0-dwarf-llvm-assertion.patch 10589 BLAKE2B 2fe6a9e5cb4714c310539cee24c2c13c226bec6eb50cf7ec5cc4089d6604f140703ad8d2030d91727036744750a724c3e68f573859ca3c8fbea72fbb5ef6bfc2 SHA512 0bfb26865fb797db0611ce91eb7e67d0807d4a36ce19b1b21afc3f843d1a4c91438c9f20f929e1435119b3c8f7623bf83dc36bc1337c33a211f75183851d747d AUX 1.82.0-i586-baseline.patch 1818 BLAKE2B 59f396cbcc9421ae9394d0bb51053dc9addb8ca895ea8c4d7633b56361782b65f4e7f0699dec2999f2e188b4929f9036991444187f8ef35f6fea176a01999f83 SHA512 898dbde6a2f3acbe7a50023b88d3280ae85125e2bb99d18823174b541972766cf75a3457a34a024cea7348537fa6854af6ffc975abbc19323a20de87cbf5e5fb AUX 1.83.0-cross-compile-libz.patch 915 BLAKE2B dbb726de09c9c957f245ecce29c597f4c9c26bae0c14901c62ad51349f02d47c69fa687bd926f7ecf47aaab4ac5aac9378dfe7fa0a66dee95ff1765c5aa9b0cc SHA512 b9127b7656b8e5f79db3157d9425f97af0634088fad512e572357797a2f24f9e9c3635e06ab2efc5ad8edf86ffcab53adbf013e29162579642a382d0015ab54e +AUX 1.83.0-dwarf-llvm-assertion.patch 10432 BLAKE2B 27f7c4145cf3046e7cb74071b72c5d7a4a3cfbdc97530c588f82225ecc8a76692d228804c3fb8e7f356d9e76b982d429fa369dc5f4607d8ad91e3a486c7cd5fd SHA512 aa0b4022f00fe126953d7d9bb6759c5ef1b6deaf7dd387e031e74c9d1cbcd6861c673afefdca5f494015ddcb64f23297f1176f22d4f3b63ec3dbd0c39527adfd AUX llvm/12/cstdint-signals-h.patch 993 BLAKE2B f771a4f0bbe1cef4001e471b55d9849999e53ea9eaf20b7cde76495faaa8b34f920c011d4ef1fb19c23b41b86c2fd46c9fdce068314d3450a99ef76b60173bc2 SHA512 4d7f2f90654eaa4132088dfc1541b9e804cd67f1889317c05bd7c2ebc65205388c3c128c749d864ca3b1e04e170f5aad5964e7eb331867043beb5b3f07548730 DIST openssl-0.10.35.crate 204462 BLAKE2B fb58a3be883bac3d5aa3e971172a281a80e9e100c51585db3d2828ecfd89d0b3b19edfacba2039056fa3aefb79717e03cd2ecbf932afb1acac2e74e1c29d3551 SHA512 5ebe4626a894ccc6e5c159cef72357654aa1a20dcc863fdab495f10a574b49b0b9d4e85a069b8b9297544ea0d09fd88a976396c3a8e8faaee9d01d79d943126f DIST openssl-sys-0.9.65.crate 54405 BLAKE2B f0e09accf076653f172199d36bfe0b7547a738f962e9ee8c15563c4d27587aade3e44830022a1787dfc932ae1f162336e3a110a34b1459656631c7ea50e58b75 SHA512 4c14ff5258a35b86e35d352c5702c90e1f70954c8f33d17160694b63305057b97da3ac6846d3e8f8e7293c40f15b76effd1e34fad4be613b8d815b90148406f7 @@ -59,5 +60,5 @@ EBUILD rust-1.80.1-r100.ebuild 23322 BLAKE2B db70df6663ce1ddceb947f19c4df11498fc EBUILD rust-1.81.0-r100.ebuild 23519 BLAKE2B a4dc37ae3972353f19dc803a7a3a0d08db29b25227c0c27ff8c409bd97e9af5c17acd8cc3d92de58ff302eddffb4a4583518f959959a534f31ca04461d2397ef SHA512 1676af16f4273d23ac2bad14d8b0ff47b1f6c66d379c688907cc0646b4866fe7c45bf4a4129ec1fc910970d7027d814d7f524a7860afa852d138bbfe2bf920ae EBUILD rust-1.82.0-r100.ebuild 23665 BLAKE2B b8f5f4b29652843825b5bb9a8522d7f86260bf6e2a9901e307173885e35df5c3445d0e1fc04520a8c6f89cb42d038504a661fe3f9c6d9d913e6f83784e1d2092 SHA512 79c3a343e555fafe21eb016bd86af5525fae9b8d4c5ac44960c70fb129688fa1dc1aba3ed997d1e5ef238530d52943edf48475a0364e73a36ebe87f746abf29f EBUILD rust-1.82.0-r101.ebuild 23714 BLAKE2B cf0423e0b6bb36132d7cf3a2e182f015c4f91a47cded2b852128a23f098032eb2f62fedbbc1d14ec6754d9c32aff193a871d480d017c8323a6f4118d8955d311 SHA512 aaf6cf387e689a6e7aee3f64dfaf5b5ab5644b8e64599c8d08e3ffa3ea7280c17d666c55fbbae1e9bd455bf92e84ad0251adcf0e06bfadc4c7ba69174dedf3f2 -EBUILD rust-1.83.0.ebuild 22905 BLAKE2B 0ba626df3d0cde5727a5c1511db8a39f23b5ba032830044c0e5d9a3844d4a3efd7814494bde9923543bb873203ca62f5c9bce5a727227f2e9e9c4be6839de6c8 SHA512 f9b958dbf0e845e16f72c9dce45c3632bab68d66251ea5580de78ae2dbaa3c0efb7dfa2a3689a9645567d92f5cd8d9bf518555aadc69cfbac64f635574388435 +EBUILD rust-1.83.0-r1.ebuild 22954 BLAKE2B 5b78edbc23badc3a1c25196ba18d9c2364583240ab4a4d3dec23cae71a8bce23fd215b190c0d5b39e1cecb6ebbbcb73b9bfa10366890700493305fbeab6fec42 SHA512 4ef5391f420e6d01e0454f9771818c406daff5eb3bd4d1ee069b729a72099292b170d7fca5fb2cba7ed58691c8997476da12e7fa3a78b5b3b39bc1fa62c7c35c MISC metadata.xml 1708 BLAKE2B ab2730e5846922c119865b26cf317a9d150321dca15500b2254fe6d0580e939a67d3b42ef1b74268ea629e843c251c5d1edc2e88edfe590c0c6e7d1b98b38b04 SHA512 6b7c99fed72711e3bdb024e6873ef0a372c7456ddcc56af239c6f8bacfff688ad8246ded6b6489172f94dbe5921159be42021248200afea2b304a529dcff7485 diff --git a/dev-lang/rust/files/1.83.0-dwarf-llvm-assertion.patch b/dev-lang/rust/files/1.83.0-dwarf-llvm-assertion.patch new file mode 100644 index 000000000000..64d00ac0aaaf --- /dev/null +++ b/dev-lang/rust/files/1.83.0-dwarf-llvm-assertion.patch @@ -0,0 +1,242 @@ +From 1dc106121b62562ead6e7d612fa136dc4b35cd5d Mon Sep 17 00:00:00 2001 +From: Kyle Huey <khuey@kylehuey.com> +Date: Mon, 4 Nov 2024 11:38:14 -0800 +Subject: [PATCH] Add discriminators to DILocations when multiple functions are + inlined into a single point. + +LLVM does not expect to ever see multiple dbg_declares for the same variable at the same +location with different values. proc-macros make it possible for arbitrary code, +including multiple calls that get inlined, to happen at any given location in the source +code. Add discriminators when that happens so these locations are different to LLVM. + +This may interfere with the AddDiscriminators pass in LLVM, which is added by the +unstable flag -Zdebug-info-for-profiling. + +Fixes #131944 +--- + .../src/debuginfo/create_scope_map.rs | 60 ++++++++++++++++++- + compiler/rustc_codegen_llvm/src/llvm/ffi.rs | 4 ++ + .../rustc_llvm/llvm-wrapper/RustWrapper.cpp | 8 +++ + .../auxiliary/macro_def.rs | 11 ++++ + .../mir_inlined_twice_var_locs.rs | 53 ++++++++++++++++ + 5 files changed, 133 insertions(+), 3 deletions(-) + create mode 100644 tests/codegen/debuginfo-proc-macro/auxiliary/macro_def.rs + create mode 100644 tests/codegen/debuginfo-proc-macro/mir_inlined_twice_var_locs.rs + +diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/create_scope_map.rs b/compiler/rustc_codegen_llvm/src/debuginfo/create_scope_map.rs +index ac6c2fb1b83a6..0f1909486ec7e 100644 +--- a/compiler/rustc_codegen_llvm/src/debuginfo/create_scope_map.rs ++++ b/compiler/rustc_codegen_llvm/src/debuginfo/create_scope_map.rs +@@ -1,11 +1,15 @@ ++use std::collections::hash_map::Entry; ++ + use rustc_codegen_ssa::mir::debuginfo::{DebugScope, FunctionDebugContext}; + use rustc_codegen_ssa::traits::*; ++use rustc_data_structures::fx::FxHashMap; + use rustc_index::Idx; + use rustc_index::bit_set::BitSet; + use rustc_middle::mir::{Body, SourceScope}; + use rustc_middle::ty::layout::FnAbiOf; + use rustc_middle::ty::{self, Instance}; + use rustc_session::config::DebugInfo; ++use rustc_span::BytePos; + + use super::metadata::file_metadata; + use super::utils::DIB; +@@ -37,10 +41,20 @@ pub(crate) fn compute_mir_scopes<'ll, 'tcx>( + None + }; + let mut instantiated = BitSet::new_empty(mir.source_scopes.len()); ++ let mut discriminators = FxHashMap::default(); + // Instantiate all scopes. + for idx in 0..mir.source_scopes.len() { + let scope = SourceScope::new(idx); +- make_mir_scope(cx, instance, mir, &variables, debug_context, &mut instantiated, scope); ++ make_mir_scope( ++ cx, ++ instance, ++ mir, ++ &variables, ++ debug_context, ++ &mut instantiated, ++ &mut discriminators, ++ scope, ++ ); + } + assert!(instantiated.count() == mir.source_scopes.len()); + } +@@ -52,6 +66,7 @@ fn make_mir_scope<'ll, 'tcx>( + variables: &Option<BitSet<SourceScope>>, + debug_context: &mut FunctionDebugContext<'tcx, &'ll DIScope, &'ll DILocation>, + instantiated: &mut BitSet<SourceScope>, ++ discriminators: &mut FxHashMap<BytePos, u32>, + scope: SourceScope, + ) { + if instantiated.contains(scope) { +@@ -60,7 +75,16 @@ fn make_mir_scope<'ll, 'tcx>( + + let scope_data = &mir.source_scopes[scope]; + let parent_scope = if let Some(parent) = scope_data.parent_scope { +- make_mir_scope(cx, instance, mir, variables, debug_context, instantiated, parent); ++ make_mir_scope( ++ cx, ++ instance, ++ mir, ++ variables, ++ debug_context, ++ instantiated, ++ discriminators, ++ parent, ++ ); + debug_context.scopes[parent] + } else { + // The root is the function itself. +@@ -117,7 +141,37 @@ fn make_mir_scope<'ll, 'tcx>( + // FIXME(eddyb) this doesn't account for the macro-related + // `Span` fixups that `rustc_codegen_ssa::mir::debuginfo` does. + let callsite_scope = parent_scope.adjust_dbg_scope_for_span(cx, callsite_span); +- cx.dbg_loc(callsite_scope, parent_scope.inlined_at, callsite_span) ++ let loc = cx.dbg_loc(callsite_scope, parent_scope.inlined_at, callsite_span); ++ ++ // NB: In order to produce proper debug info for variables (particularly ++ // arguments) in multiply-inline functions, LLVM expects to see a single ++ // DILocalVariable with multiple different DILocations in the IR. While ++ // the source information for each DILocation would be identical, their ++ // inlinedAt attributes will be unique to the particular callsite. ++ // ++ // We generate DILocations here based on the callsite's location in the ++ // source code. A single location in the source code usually can't ++ // produce multiple distinct calls so this mostly works, until ++ // proc-macros get involved. A proc-macro can generate multiple calls ++ // at the same span, which breaks the assumption that we're going to ++ // produce a unique DILocation for every scope we process here. We ++ // have to explicitly add discriminators if we see inlines into the ++ // same source code location. ++ // ++ // Note further that we can't key this hashtable on the span itself, ++ // because these spans could have distinct SyntaxContexts. We have ++ // to key on exactly what we're giving to LLVM. ++ match discriminators.entry(callsite_span.lo()) { ++ Entry::Occupied(mut o) => { ++ *o.get_mut() += 1; ++ unsafe { llvm::LLVMRustDILocationCloneWithBaseDiscriminator(loc, *o.get()) } ++ .expect("Failed to encode discriminator in DILocation") ++ } ++ Entry::Vacant(v) => { ++ v.insert(0); ++ loc ++ } ++ } + }); + + debug_context.scopes[scope] = DebugScope { +diff --git a/compiler/rustc_codegen_llvm/src/llvm/ffi.rs b/compiler/rustc_codegen_llvm/src/llvm/ffi.rs +index 3d2e270a3868e..75a5ec44c2285 100644 +--- a/compiler/rustc_codegen_llvm/src/llvm/ffi.rs ++++ b/compiler/rustc_codegen_llvm/src/llvm/ffi.rs +@@ -2174,6 +2174,10 @@ unsafe extern "C" { + Scope: &'a DIScope, + InlinedAt: Option<&'a DILocation>, + ) -> &'a DILocation; ++ pub fn LLVMRustDILocationCloneWithBaseDiscriminator<'a>( ++ Location: &'a DILocation, ++ BD: c_uint, ++ ) -> Option<&'a DILocation>; + pub fn LLVMRustDIBuilderCreateOpDeref() -> u64; + pub fn LLVMRustDIBuilderCreateOpPlusUconst() -> u64; + pub fn LLVMRustDIBuilderCreateOpLLVMFragment() -> u64; +diff --git a/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp b/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp +index 9330c83b7f230..cd70c3f266920 100644 +--- a/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp ++++ b/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp +@@ -1305,6 +1305,14 @@ LLVMRustDIBuilderCreateDebugLocation(unsigned Line, unsigned Column, + return wrap(Loc); + } + ++extern "C" LLVMMetadataRef ++LLVMRustDILocationCloneWithBaseDiscriminator(LLVMMetadataRef Location, ++ unsigned BD) { ++ DILocation *Loc = unwrapDIPtr<DILocation>(Location); ++ auto NewLoc = Loc->cloneWithBaseDiscriminator(BD); ++ return wrap(NewLoc.has_value() ? NewLoc.value() : nullptr); ++} ++ + extern "C" uint64_t LLVMRustDIBuilderCreateOpDeref() { + return dwarf::DW_OP_deref; + } +diff --git a/tests/codegen/debuginfo-proc-macro/auxiliary/macro_def.rs b/tests/codegen/debuginfo-proc-macro/auxiliary/macro_def.rs +new file mode 100644 +index 0000000000000..159ecfd09743d +--- /dev/null ++++ b/tests/codegen/debuginfo-proc-macro/auxiliary/macro_def.rs +@@ -0,0 +1,11 @@ ++//@ force-host ++//@ no-prefer-dynamic ++#![crate_type = "proc-macro"] ++ ++extern crate proc_macro; ++use proc_macro::*; ++ ++#[proc_macro] ++pub fn square_twice(_item: TokenStream) -> TokenStream { ++ "(square(env::vars().count() as i32), square(env::vars().count() as i32))".parse().unwrap() ++} +diff --git a/tests/codegen/debuginfo-proc-macro/mir_inlined_twice_var_locs.rs b/tests/codegen/debuginfo-proc-macro/mir_inlined_twice_var_locs.rs +new file mode 100644 +index 0000000000000..c3858044c0c9f +--- /dev/null ++++ b/tests/codegen/debuginfo-proc-macro/mir_inlined_twice_var_locs.rs +@@ -0,0 +1,53 @@ ++//@ min-llvm-version: 19 ++//@ compile-flags: -Cdebuginfo=2 -Copt-level=0 -Zmir-enable-passes=+Inline ++// MSVC is different because of the individual allocas. ++//@ ignore-msvc ++ ++//@ aux-build:macro_def.rs ++ ++// Find the variable. ++// CHECK-DAG: ![[#var_dbg:]] = !DILocalVariable(name: "n",{{( arg: 1,)?}} scope: ![[#var_scope:]] ++ ++// Find both dbg_declares. These will proceed the variable metadata, of course, so we're looking ++// backwards. ++// CHECK-DAG: dbg_declare(ptr %n.dbg.spill{{[0-9]}}, ![[#var_dbg]], !DIExpression(), ![[#var_loc2:]]) ++// CHECK-DAG: dbg_declare(ptr %n.dbg.spill, ![[#var_dbg]], !DIExpression(), ![[#var_loc1:]]) ++ ++// Find the first location definition, looking forwards again. ++// CHECK: ![[#var_loc1]] = !DILocation ++// CHECK-SAME: scope: ![[#var_scope:]], inlinedAt: ![[#var_inlinedAt1:]] ++ ++// Find the first location's inlinedAt ++// NB: If we fail here it's *probably* because we failed to produce two ++// different locations and ended up reusing an earlier one. ++// CHECK: ![[#var_inlinedAt1]] = !DILocation ++// CHECK-SAME: scope: ![[var_inlinedAt1_scope:]] ++ ++// Find the second location definition, still looking forwards. ++// NB: If we failed to produce two different locations, the test will ++// definitely fail by this point (if it hasn't already) because we won't ++// be able to find the same line again. ++// CHECK: ![[#var_loc2]] = !DILocation ++// CHECK-SAME: scope: ![[#var_scope]], inlinedAt: ![[#var_inlinedAt2:]] ++ ++// Find the second location's inlinedAt. ++// CHECK: ![[#var_inlinedAt2]] = !DILocation ++// CHECK-SAME: scope: ![[#var_inlinedAt2_scope:]] ++ ++// Finally, check that a discriminator was emitted for the second scope. ++// FIXMEkhuey ideally we would check that *either* scope has a discriminator ++// but I don't know that it's possible to check that with FileCheck. ++// CHECK: ![[#var_inlinedAt2_scope]] = !DILexicalBlockFile ++// CHECK-SAME: discriminator: [[#]] ++extern crate macro_def; ++ ++use std::env; ++ ++fn square(n: i32) -> i32 { ++ n * n ++} ++ ++fn main() { ++ let (z1, z2) = macro_def::square_twice!(); ++ println!("{z1} == {z2}"); ++} diff --git a/dev-lang/rust/rust-1.83.0.ebuild b/dev-lang/rust/rust-1.83.0-r1.ebuild index b0585b3218c1..db171b2fb483 100644 --- a/dev-lang/rust/rust-1.83.0.ebuild +++ b/dev-lang/rust/rust-1.83.0-r1.ebuild @@ -135,6 +135,7 @@ PATCHES=( "${FILESDIR}"/1.83.0-cross-compile-libz.patch #"${FILESDIR}"/1.72.0-bump-libc-deps-to-0.2.146.patch # pending refresh "${FILESDIR}"/1.67.0-doc-wasm.patch + "${FILESDIR}"/1.83.0-dwarf-llvm-assertion.patch ) clear_vendor_checksums() { |