-
Notifications
You must be signed in to change notification settings - Fork 109
Closed
Labels
A-debuginfoArea: Debugging information at runtime in generated code.Area: Debugging information at runtime in generated code.C-bugCategory: This is a bug.Category: This is a bug.O-macosOperating system: MacOSOperating system: MacOS
Description
After applying the following patch, because macOS doesn't use .debug_*
relocations.
diff --git a/src/debuginfo.rs b/src/debuginfo.rs
index 6da47d2..4c943c4 100644
--- a/src/debuginfo.rs
+++ b/src/debuginfo.rs
@@ -740,15 +740,7 @@ impl<'a, 'tcx> Writer for WriterRelocate<'a, 'tcx> {
}
fn write_offset(&mut self, val: usize, section: SectionId, size: u8) -> Result<()> {
- let offset = self.len() as u32;
- let name = self.ctx.section_name(section);
- self.relocs.push(DebugReloc {
- offset,
- size,
- name,
- addend: val as i64,
- });
- self.write_word(0, size)
+ self.write_word(val as u64, size)
}
fn write_offset_at(
@@ -758,14 +750,7 @@ impl<'a, 'tcx> Writer for WriterRelocate<'a, 'tcx> {
section: SectionId,
size: u8,
) -> Result<()> {
- let name = self.ctx.section_name(section);
- self.relocs.push(DebugReloc {
- offset: offset as u32,
- size,
- name,
- addend: val as i64,
- });
- self.write_word_at(offset, 0, size)
+ self.write_word_at(offset, val as u64, size)
}
}
The resulting DWARF has wrong addresses, even though the original object files had relocations for the .debug_*
sections:
dwarfdump --verify target/out/mini_core_hello_world.dSYM
----------------------------------------------------------------------
File: target/out/mini_core_hello_world.dSYM/Contents/Resources/DWARF/mini_core_hello_world (x86_64)
----------------------------------------------------------------------
Verifying Compile Unit Header chain... ok
Verifying .debug_info...
error: Range is not in parent
TAG_subprogram {0x00000066}: [0x0000000100000ade - 0x0000000100000c6e)
error: Range is not in parent
TAG_subprogram {0x0000019d}: [0x0000000100000d2b - 0x0000000100001b9e)
error: Range is not in parent
TAG_subprogram {0x000007f8}: [0x0000000100001bbf - 0x0000000100001bcd)
error: Range is not in parent
TAG_subprogram {0x00000835}: [0x0000000100001b9e - 0x0000000100001bbf)
error: Range is not in parent
TAG_subprogram {0x0000086e}: [0x0000000100001cac - 0x0000000100001d2e)
error: Range is not in parent
TAG_subprogram {0x0000090c}: [0x0000000100001bcd - 0x0000000100001c52)
error: Range is not in parent
TAG_subprogram {0x00000a13}: [0x0000000100001eab - 0x0000000100001f30)
error: Range is not in parent
TAG_subprogram {0x00000a96}: [0x0000000100001d2e - 0x0000000100001eab)
error: Range is not in parent
TAG_subprogram {0x00000b2d}: [0x0000000100001c52 - 0x0000000100001cac)
error: Range is not in parent
TAG_subprogram {0x00000bae}: [0x0000000100001f58 - 0x0000000100001f65)
error: Range is not in parent
TAG_subprogram {0x00000beb}: [0x0000000100001f6b - 0x0000000100001f90)
11 error(s) were found.
Verifying .apple_names... ok
Verifying .apple_types... ok
Verifying .apple_namespaces... ok
Verifying .apple_objc... ok
Verifying .debug_frame... ok
Verifying .debug_line... ok
$ dwarfdump target/out/mini_core_hello_world.dSYM
----------------------------------------------------------------------
File: target/out/mini_core_hello_world.dSYM/Contents/Resources/DWARF/mini_core_hello_world (x86_64)
----------------------------------------------------------------------
.debug_info contents:
0x00000000: Compile Unit: length = 0x00000b7a version = 0x0004 abbr_offset = 0x00000000 addr_size = 0x08 (next CU at 0x00000b7e)
0x0000000b: TAG_compile_unit [1] *
AT_producer( "cranelift fn (rustc version unknown version)" )
AT_language( DW_LANG_Rust )
AT_name( "example/mini_core_hello_world.rs" )
AT_comp_dir( "/Users/bjorn/Documents/rustc_codegen_cranelift" )
AT_stmt_list( 0x00000000 )
AT_low_pc( 0x0000000100000ad0 )
AT_ranges( 0x00000000
[0x0000000100000ad0 - 0x0000000100000ade)
[0x0000000100000ad0 - 0x0000000100000ade)
[0x0000000100000ad0 - 0x0000000100000aeb)
[0x0000000100000ad0 - 0x0000000100000af1)
[0x0000000100000ad0 - 0x0000000100000b2a)
[0x0000000100000ad0 - 0x0000000100000b52)
[0x0000000100000ad0 - 0x0000000100000b55)
[0x0000000100000ad0 - 0x0000000100000b55)
[0x0000000100000ad0 - 0x0000000100000b72)
[0x0000000100000ad0 - 0x0000000100000c4d)
[0x0000000100000ad0 - 0x0000000100000c60)
[0x0000000100000ad0 - 0x0000000100001943)
End )
[...]
$ objdump -r target/out/mini_core.dummy_name.rcgu.o
target/out/mini_core.dummy_name.rcgu.o: file format Mach-O 64-bit x86-64
RELOCATION RECORDS FOR [__text]:
000000000000034f X86_64_RELOC_GOT_LOAD __ZN9mini_core12MY_TINY_HEAP17h06b8b6ee678156b1E@GOTPCREL
RELOCATION RECORDS FOR [__debug_info]:
0000000000000032 X86_64_RELOC_UNSIGNED __ZN68_$LT$$RF$$u27$a$u20$bool$u20$as$u20$mini_core..BitOr$LT$bool$GT$$GT$5bitor17h06c4c08238ea11b3E
00000000000000a8 X86_64_RELOC_UNSIGNED __ZN39_$LT$bool$u20$as$u20$mini_core..Not$GT$3not17h0dfb0e7a03f21bafE
00000000000000f3 X86_64_RELOC_UNSIGNED __ZN37_$LT$u8$u20$as$u20$mini_core..Mul$GT$3mul17hbadd8ec33043e277E
0000000000000174 X86_64_RELOC_UNSIGNED __ZN37_$LT$u8$u20$as$u20$mini_core..Add$GT$3add17hf2b580c713c9aa22E
00000000000001e8 X86_64_RELOC_UNSIGNED __ZN45_$LT$char$u20$as$u20$mini_core..PartialEq$GT$2ne17h6591d7d822cd694dE
000000000000025e X86_64_RELOC_UNSIGNED __ZN40_$LT$isize$u20$as$u20$mini_core..Neg$GT$3neg17ha9990a7b7c09dbf8E
00000000000002ba X86_64_RELOC_UNSIGNED __ZN45_$LT$char$u20$as$u20$mini_core..PartialEq$GT$2eq17h85da6c7efdb2221eE
0000000000000323 X86_64_RELOC_UNSIGNED __ZN40_$LT$usize$u20$as$u20$mini_core..Sub$GT$3sub17h1819823fa4db3789E
00000000000003a5 X86_64_RELOC_UNSIGNED __ZN9mini_core5panic17h1b8c87c5633941c5E
00000000000003e2 X86_64_RELOC_UNSIGNED __ZN43_$LT$u8$u20$as$u20$mini_core..PartialEq$GT$2eq17h77b456aa7ccf9ab8E
0000000000000451 X86_64_RELOC_UNSIGNED __ZN41_$LT$bool$u20$as$u20$mini_core..BitOr$GT$5bitor17hc51993c0e2f70499E
00000000000004ba X86_64_RELOC_UNSIGNED _rust_eh_personality
00000000000004dc X86_64_RELOC_UNSIGNED __ZN43_$LT$u8$u20$as$u20$mini_core..PartialEq$GT$2ne17h40203ccd00452a56E
0000000000000545 X86_64_RELOC_UNSIGNED __ZN9mini_core8allocate17h122bb7e874c2cf63E
RELOCATION RECORDS FOR [__debug_line]:
0000000000000038 X86_64_RELOC_UNSIGNED __ZN68_$LT$$RF$$u27$a$u20$bool$u20$as$u20$mini_core..BitOr$LT$bool$GT$$GT$5bitor17h06c4c08238ea11b3E
0000000000000068 X86_64_RELOC_UNSIGNED __ZN39_$LT$bool$u20$as$u20$mini_core..Not$GT$3not17h0dfb0e7a03f21bafE
0000000000000096 X86_64_RELOC_UNSIGNED __ZN37_$LT$u8$u20$as$u20$mini_core..Mul$GT$3mul17hbadd8ec33043e277E
00000000000000e0 X86_64_RELOC_UNSIGNED __ZN37_$LT$u8$u20$as$u20$mini_core..Add$GT$3add17hf2b580c713c9aa22E
000000000000012a X86_64_RELOC_UNSIGNED __ZN45_$LT$char$u20$as$u20$mini_core..PartialEq$GT$2ne17h6591d7d822cd694dE
000000000000015d X86_64_RELOC_UNSIGNED __ZN40_$LT$isize$u20$as$u20$mini_core..Neg$GT$3neg17ha9990a7b7c09dbf8E
000000000000018f X86_64_RELOC_UNSIGNED __ZN45_$LT$char$u20$as$u20$mini_core..PartialEq$GT$2eq17h85da6c7efdb2221eE
00000000000001c2 X86_64_RELOC_UNSIGNED __ZN40_$LT$usize$u20$as$u20$mini_core..Sub$GT$3sub17h1819823fa4db3789E
0000000000000205 X86_64_RELOC_UNSIGNED __ZN9mini_core5panic17h1b8c87c5633941c5E
0000000000000222 X86_64_RELOC_UNSIGNED __ZN43_$LT$u8$u20$as$u20$mini_core..PartialEq$GT$2eq17h77b456aa7ccf9ab8E
0000000000000259 X86_64_RELOC_UNSIGNED __ZN41_$LT$bool$u20$as$u20$mini_core..BitOr$GT$5bitor17hc51993c0e2f70499E
0000000000000287 X86_64_RELOC_UNSIGNED _rust_eh_personality
00000000000002a4 X86_64_RELOC_UNSIGNED __ZN43_$LT$u8$u20$as$u20$mini_core..PartialEq$GT$2ne17h40203ccd00452a56E
00000000000002db X86_64_RELOC_UNSIGNED __ZN9mini_core8allocate17h122bb7e874c2cf63E
RELOCATION RECORDS FOR [__debug_ranges]:
0000000000000000 X86_64_RELOC_UNSIGNED __ZN68_$LT$$RF$$u27$a$u20$bool$u20$as$u20$mini_core..BitOr$LT$bool$GT$$GT$5bitor17h06c4c08238ea11b3E
0000000000000008 X86_64_RELOC_UNSIGNED __ZN68_$LT$$RF$$u27$a$u20$bool$u20$as$u20$mini_core..BitOr$LT$bool$GT$$GT$5bitor17h06c4c08238ea11b3E
0000000000000010 X86_64_RELOC_UNSIGNED __ZN39_$LT$bool$u20$as$u20$mini_core..Not$GT$3not17h0dfb0e7a03f21bafE
0000000000000018 X86_64_RELOC_UNSIGNED __ZN39_$LT$bool$u20$as$u20$mini_core..Not$GT$3not17h0dfb0e7a03f21bafE
0000000000000020 X86_64_RELOC_UNSIGNED __ZN37_$LT$u8$u20$as$u20$mini_core..Mul$GT$3mul17hbadd8ec33043e277E
0000000000000028 X86_64_RELOC_UNSIGNED __ZN37_$LT$u8$u20$as$u20$mini_core..Mul$GT$3mul17hbadd8ec33043e277E
0000000000000030 X86_64_RELOC_UNSIGNED __ZN37_$LT$u8$u20$as$u20$mini_core..Add$GT$3add17hf2b580c713c9aa22E
0000000000000038 X86_64_RELOC_UNSIGNED __ZN37_$LT$u8$u20$as$u20$mini_core..Add$GT$3add17hf2b580c713c9aa22E
0000000000000040 X86_64_RELOC_UNSIGNED __ZN45_$LT$char$u20$as$u20$mini_core..PartialEq$GT$2ne17h6591d7d822cd694dE
0000000000000048 X86_64_RELOC_UNSIGNED __ZN45_$LT$char$u20$as$u20$mini_core..PartialEq$GT$2ne17h6591d7d822cd694dE
0000000000000050 X86_64_RELOC_UNSIGNED __ZN40_$LT$isize$u20$as$u20$mini_core..Neg$GT$3neg17ha9990a7b7c09dbf8E
0000000000000058 X86_64_RELOC_UNSIGNED __ZN40_$LT$isize$u20$as$u20$mini_core..Neg$GT$3neg17ha9990a7b7c09dbf8E
0000000000000060 X86_64_RELOC_UNSIGNED __ZN45_$LT$char$u20$as$u20$mini_core..PartialEq$GT$2eq17h85da6c7efdb2221eE
0000000000000068 X86_64_RELOC_UNSIGNED __ZN45_$LT$char$u20$as$u20$mini_core..PartialEq$GT$2eq17h85da6c7efdb2221eE
0000000000000070 X86_64_RELOC_UNSIGNED __ZN40_$LT$usize$u20$as$u20$mini_core..Sub$GT$3sub17h1819823fa4db3789E
0000000000000078 X86_64_RELOC_UNSIGNED __ZN40_$LT$usize$u20$as$u20$mini_core..Sub$GT$3sub17h1819823fa4db3789E
0000000000000080 X86_64_RELOC_UNSIGNED __ZN9mini_core5panic17h1b8c87c5633941c5E
0000000000000088 X86_64_RELOC_UNSIGNED __ZN9mini_core5panic17h1b8c87c5633941c5E
0000000000000090 X86_64_RELOC_UNSIGNED __ZN43_$LT$u8$u20$as$u20$mini_core..PartialEq$GT$2eq17h77b456aa7ccf9ab8E
0000000000000098 X86_64_RELOC_UNSIGNED __ZN43_$LT$u8$u20$as$u20$mini_core..PartialEq$GT$2eq17h77b456aa7ccf9ab8E
00000000000000a0 X86_64_RELOC_UNSIGNED __ZN41_$LT$bool$u20$as$u20$mini_core..BitOr$GT$5bitor17hc51993c0e2f70499E
00000000000000a8 X86_64_RELOC_UNSIGNED __ZN41_$LT$bool$u20$as$u20$mini_core..BitOr$GT$5bitor17hc51993c0e2f70499E
00000000000000b0 X86_64_RELOC_UNSIGNED _rust_eh_personality
00000000000000b8 X86_64_RELOC_UNSIGNED _rust_eh_personality
00000000000000c0 X86_64_RELOC_UNSIGNED __ZN43_$LT$u8$u20$as$u20$mini_core..PartialEq$GT$2ne17h40203ccd00452a56E
00000000000000c8 X86_64_RELOC_UNSIGNED __ZN43_$LT$u8$u20$as$u20$mini_core..PartialEq$GT$2ne17h40203ccd00452a56E
00000000000000d0 X86_64_RELOC_UNSIGNED __ZN9mini_core8allocate17h122bb7e874c2cf63E
00000000000000d8 X86_64_RELOC_UNSIGNED __ZN9mini_core8allocate17h122bb7e874c2cf63E
And .debug_line
has all sequences start at 0x0000000100000ad0
Originally posted by @bjorn3 in https://github.com/bjorn3/rustc_codegen_cranelift/pull/291#issuecomment-455791860
Metadata
Metadata
Assignees
Labels
A-debuginfoArea: Debugging information at runtime in generated code.Area: Debugging information at runtime in generated code.C-bugCategory: This is a bug.Category: This is a bug.O-macosOperating system: MacOSOperating system: MacOS