-
Notifications
You must be signed in to change notification settings - Fork 13.3k
cg_llvm: Use constants for DWARF opcodes, instead of FFI calls #135115
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
//! Definitions of various DWARF-related constants. | ||
|
||
use libc::c_uint; | ||
|
||
/// Helper macro to let us redeclare gimli's constants as our own constants | ||
/// with a different type, with less risk of copy-paste errors. | ||
macro_rules! declare_constant { | ||
( | ||
$name:ident : $type:ty | ||
) => { | ||
#[allow(non_upper_case_globals)] | ||
pub(crate) const $name: $type = ::gimli::constants::$name.0 as $type; | ||
|
||
// Assert that as-cast probably hasn't changed the value. | ||
const _: () = assert!($name as i128 == ::gimli::constants::$name.0 as i128); | ||
}; | ||
} | ||
|
||
declare_constant!(DW_TAG_const_type: c_uint); | ||
|
||
// DWARF languages. | ||
declare_constant!(DW_LANG_Rust: c_uint); | ||
|
||
// DWARF attribute type encodings. | ||
declare_constant!(DW_ATE_boolean: c_uint); | ||
declare_constant!(DW_ATE_float: c_uint); | ||
declare_constant!(DW_ATE_signed: c_uint); | ||
declare_constant!(DW_ATE_unsigned: c_uint); | ||
declare_constant!(DW_ATE_UTF: c_uint); | ||
|
||
// DWARF expression operators. | ||
declare_constant!(DW_OP_deref: u64); | ||
declare_constant!(DW_OP_plus_uconst: u64); | ||
/// Defined by LLVM in `llvm/include/llvm/BinaryFormat/Dwarf.h`. | ||
/// Double-checked by a static assertion in `RustWrapper.cpp`. | ||
#[allow(non_upper_case_globals)] | ||
pub(crate) const DW_OP_LLVM_fragment: u64 = 0x1000; | ||
Zalathar marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ use rustc_target::spec::DebuginfoKind; | |
use smallvec::smallvec; | ||
use tracing::{debug, instrument}; | ||
|
||
pub(crate) use self::type_map::TypeMap; | ||
use self::type_map::{DINodeCreationResult, Stub, UniqueTypeId}; | ||
use super::CodegenUnitDebugContext; | ||
use super::namespace::mangled_name_of_instance; | ||
|
@@ -30,6 +31,7 @@ use super::utils::{ | |
DIB, create_DIArray, debug_context, get_namespace_for_item, is_node_local_to_unit, | ||
}; | ||
use crate::common::{AsCCharPtr, CodegenCx}; | ||
use crate::debuginfo::dwarf_const; | ||
use crate::debuginfo::metadata::type_map::build_type_with_children; | ||
use crate::debuginfo::utils::{WidePtrKind, wide_pointer_kind}; | ||
use crate::llvm::debuginfo::{ | ||
|
@@ -59,23 +61,6 @@ impl fmt::Debug for llvm::Metadata { | |
} | ||
} | ||
|
||
// From DWARF 5. | ||
// See http://www.dwarfstd.org/ShowIssue.php?issue=140129.1. | ||
const DW_LANG_RUST: c_uint = 0x1c; | ||
#[allow(non_upper_case_globals)] | ||
const DW_ATE_boolean: c_uint = 0x02; | ||
#[allow(non_upper_case_globals)] | ||
const DW_ATE_float: c_uint = 0x04; | ||
#[allow(non_upper_case_globals)] | ||
const DW_ATE_signed: c_uint = 0x05; | ||
#[allow(non_upper_case_globals)] | ||
const DW_ATE_unsigned: c_uint = 0x07; | ||
#[allow(non_upper_case_globals)] | ||
const DW_ATE_UTF: c_uint = 0x10; | ||
|
||
#[allow(non_upper_case_globals)] | ||
const DW_TAG_const_type: c_uint = 0x26; | ||
|
||
pub(super) const UNKNOWN_LINE_NUMBER: c_uint = 0; | ||
pub(super) const UNKNOWN_COLUMN_NUMBER: c_uint = 0; | ||
|
||
|
@@ -90,8 +75,6 @@ type SmallVec<T> = smallvec::SmallVec<[T; 16]>; | |
mod enums; | ||
mod type_map; | ||
|
||
pub(crate) use type_map::TypeMap; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I moved this to where the other imports are, so that it doesn't trick rust-analyzer into adding new imports in the wrong place. |
||
|
||
/// Returns from the enclosing function if the type debuginfo node with the given | ||
/// unique ID can be found in the type map. | ||
macro_rules! return_if_di_node_created_in_meantime { | ||
|
@@ -522,7 +505,7 @@ fn recursion_marker_type_di_node<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>) -> &'ll D | |
name.as_c_char_ptr(), | ||
name.len(), | ||
cx.tcx.data_layout.pointer_size.bits(), | ||
DW_ATE_unsigned, | ||
dwarf_const::DW_ATE_unsigned, | ||
) | ||
} | ||
}) | ||
|
@@ -781,6 +764,8 @@ fn build_basic_type_di_node<'ll, 'tcx>( | |
// .natvis visualizers (and perhaps other existing native debuggers?) | ||
let cpp_like_debuginfo = cpp_like_debuginfo(cx.tcx); | ||
|
||
use dwarf_const::{DW_ATE_UTF, DW_ATE_boolean, DW_ATE_float, DW_ATE_signed, DW_ATE_unsigned}; | ||
|
||
let (name, encoding) = match t.kind() { | ||
ty::Never => ("!", DW_ATE_unsigned), | ||
ty::Tuple(elements) if elements.is_empty() => { | ||
|
@@ -961,7 +946,7 @@ pub(crate) fn build_compile_unit_di_node<'ll, 'tcx>( | |
|
||
let unit_metadata = llvm::LLVMRustDIBuilderCreateCompileUnit( | ||
debug_context.builder, | ||
DW_LANG_RUST, | ||
dwarf_const::DW_LANG_Rust, | ||
compile_unit_file, | ||
producer.as_c_char_ptr(), | ||
producer.len(), | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mmm, three versions of gimli in the repo... should fix that...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it looks like we have:
used by most stuff, which can probably be bumped to 0.31thorin-dwp
, which has been bumped on main but hasn't had another release since thengimli
to 0.31 to avoid duplicate inrust-lang/rust
thorin#36backtrace
feature, which is perhaps not even needed nowadays?