Skip to content

Commit edd9070

Browse files
committed
Use constants for DWARF opcodes, instead of FFI calls
1 parent f02f863 commit edd9070

File tree

3 files changed

+14
-24
lines changed

3 files changed

+14
-24
lines changed

compiler/rustc_codegen_llvm/src/debuginfo/mod.rs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,16 @@ const DW_TAG_auto_variable: c_uint = 0x100;
5353
#[allow(non_upper_case_globals)]
5454
const DW_TAG_arg_variable: c_uint = 0x101;
5555

56+
// `DW_OP_*` values taken from:
57+
// - `llvm/include/llvm/BinaryFormat/Dwarf.def`
58+
// - `llvm/include/llvm/BinaryFormat/Dwarf.h`
59+
#[allow(non_upper_case_globals)]
60+
const DW_OP_deref: u64 = 0x06;
61+
#[allow(non_upper_case_globals)]
62+
const DW_OP_plus_uconst: u64 = 0x23;
63+
#[allow(non_upper_case_globals)]
64+
const DW_OP_LLVM_fragment: u64 = 0x1000;
65+
5666
/// A context object for maintaining all state needed by the debuginfo module.
5767
pub(crate) struct CodegenUnitDebugContext<'ll, 'tcx> {
5868
llmod: &'ll llvm::Module,
@@ -146,28 +156,23 @@ impl<'ll> DebugInfoBuilderMethods for Builder<'_, 'll, '_> {
146156
fragment: Option<Range<Size>>,
147157
) {
148158
// Convert the direct and indirect offsets and fragment byte range to address ops.
149-
// FIXME(eddyb) use `const`s instead of getting the values via FFI,
150-
// the values should match the ones in the DWARF standard anyway.
151-
let op_deref = || unsafe { llvm::LLVMRustDIBuilderCreateOpDeref() };
152-
let op_plus_uconst = || unsafe { llvm::LLVMRustDIBuilderCreateOpPlusUconst() };
153-
let op_llvm_fragment = || unsafe { llvm::LLVMRustDIBuilderCreateOpLLVMFragment() };
154159
let mut addr_ops = SmallVec::<[u64; 8]>::new();
155160

156161
if direct_offset.bytes() > 0 {
157-
addr_ops.push(op_plus_uconst());
162+
addr_ops.push(DW_OP_plus_uconst);
158163
addr_ops.push(direct_offset.bytes() as u64);
159164
}
160165
for &offset in indirect_offsets {
161-
addr_ops.push(op_deref());
166+
addr_ops.push(DW_OP_deref);
162167
if offset.bytes() > 0 {
163-
addr_ops.push(op_plus_uconst());
168+
addr_ops.push(DW_OP_plus_uconst);
164169
addr_ops.push(offset.bytes() as u64);
165170
}
166171
}
167172
if let Some(fragment) = fragment {
168173
// `DW_OP_LLVM_fragment` takes as arguments the fragment's
169174
// offset and size, both of them in bits.
170-
addr_ops.push(op_llvm_fragment());
175+
addr_ops.push(DW_OP_LLVM_fragment);
171176
addr_ops.push(fragment.start.bits() as u64);
172177
addr_ops.push((fragment.end - fragment.start).bits() as u64);
173178
}

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2237,9 +2237,6 @@ unsafe extern "C" {
22372237
Location: &'a DILocation,
22382238
BD: c_uint,
22392239
) -> Option<&'a DILocation>;
2240-
pub fn LLVMRustDIBuilderCreateOpDeref() -> u64;
2241-
pub fn LLVMRustDIBuilderCreateOpPlusUconst() -> u64;
2242-
pub fn LLVMRustDIBuilderCreateOpLLVMFragment() -> u64;
22432240

22442241
pub fn LLVMRustWriteTypeToString(Type: &Type, s: &RustString);
22452242
pub fn LLVMRustWriteValueToString(value_ref: &Value, s: &RustString);

compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,18 +1111,6 @@ LLVMRustDILocationCloneWithBaseDiscriminator(LLVMMetadataRef Location,
11111111
return wrap(NewLoc.has_value() ? NewLoc.value() : nullptr);
11121112
}
11131113

1114-
extern "C" uint64_t LLVMRustDIBuilderCreateOpDeref() {
1115-
return dwarf::DW_OP_deref;
1116-
}
1117-
1118-
extern "C" uint64_t LLVMRustDIBuilderCreateOpPlusUconst() {
1119-
return dwarf::DW_OP_plus_uconst;
1120-
}
1121-
1122-
extern "C" uint64_t LLVMRustDIBuilderCreateOpLLVMFragment() {
1123-
return dwarf::DW_OP_LLVM_fragment;
1124-
}
1125-
11261114
extern "C" void LLVMRustWriteTypeToString(LLVMTypeRef Ty, RustStringRef Str) {
11271115
auto OS = RawRustStringOstream(Str);
11281116
unwrap<llvm::Type>(Ty)->print(OS);

0 commit comments

Comments
 (0)