[DWARFYAML] Let the address size of line tables inferred from the object file.

Currently, the line table uses the first compilation unit's address size
as its address size. It's not the right behavior. The address size should be
inferred from the target machine.

Reviewed By: jhenderson

Differential Revision: https://reviews.llvm.org/D85707
This commit is contained in:
Xing GUO 2020-08-11 22:41:14 +08:00
parent 16c1d251c4
commit 1d4bc08ce4
2 changed files with 58 additions and 4 deletions

View File

@ -461,6 +461,8 @@ Error DWARFYAML::emitDebugLine(raw_ostream &OS, const DWARFYAML::Data &DI) {
emitFileEntry(OS, File);
OS.write('\0');
uint8_t AddrSize = DI.Is64BitAddrSize ? 8 : 4;
for (auto Op : LineTable.Opcodes) {
writeInteger((uint8_t)Op.Opcode, OS, DI.IsLittleEndian);
if (Op.Opcode == 0) {
@ -469,10 +471,9 @@ Error DWARFYAML::emitDebugLine(raw_ostream &OS, const DWARFYAML::Data &DI) {
switch (Op.SubOpcode) {
case dwarf::DW_LNE_set_address:
case dwarf::DW_LNE_set_discriminator:
// TODO: Test this error.
if (Error Err = writeVariableSizedInteger(
Op.Data, DI.CompileUnits[0].AddrSize, OS, DI.IsLittleEndian))
return Err;
// FIXME: The operand of set_discriminator is not an address.
cantFail(writeVariableSizedInteger(Op.Data, AddrSize, OS,
DI.IsLittleEndian));
break;
case dwarf::DW_LNE_define_file:
emitFileEntry(OS, Op.FileEntry);

View File

@ -317,3 +317,56 @@ DWARF:
IncludeDirs: []
Files: []
Opcodes: []
## h) Test that the address size is inferred from the target machine.
# RUN: yaml2obj --docnum=8 -DBITS=64 -DADDR=0x1234567890abcdef %s -o %t8.64-bit.o
# RUN: llvm-readelf --hex-dump=.debug_line %t8.64-bit.o | \
# RUN: FileCheck %s --check-prefix=ADDRSIZE -DADDR="efcdab90 78563412"
# ADDRSIZE: Hex dump of section '.debug_line':
# ADDRSIZE-NEXT: 0x00000000 34120000 02003412 00000101 010e0d00 4.....4.........
## ^------- unit_length (4-byte)
## ^--- version (2-byte)
## ^-------- header_length (4-byte)
## ^- minimum_instruction_length (1-byte)
## ^- default_is_stmt (1-byte)
## ^- line_base (1-byte)
## ^- line_range (1-byte)
## ^- opcode_base (1-byte)
## ^- null byte for terminating include_directories
# ADDRSIZE-NEXT: 0x00000010 00000902 [[ADDR]]
## ^- null byte for terminating file_names
## ^- DW_LNS_extended_op
## ^- extended op length (ULEB128) 0x09
## ^- DW_LNE_set_address
## ^------- address
# RUN: yaml2obj --docnum=8 -DBITS=32 -DADDR=0x12345678 %s -o %t8.32-bit.o
# RUN: llvm-readelf --hex-dump=.debug_line %t8.32-bit.o | \
# RUN: FileCheck %s --check-prefix=ADDRSIZE -DADDR="78563412"
--- !ELF
FileHeader:
Class: ELFCLASS[[BITS]]
Data: ELFDATA2LSB
Type: ET_EXEC
Machine: EM_X86_64
DWARF:
debug_line:
- Length: 0x1234
Version: 2
PrologueLength: 0x1234
MinInstLength: 1
DefaultIsStmt: 1
LineBase: 1
LineRange: 14
OpcodeBase: 13
StandardOpcodeLengths: []
IncludeDirs: []
Files: []
Opcodes:
- Opcode: DW_LNS_extended_op
ExtLen: 9
SubOpcode: DW_LNE_set_address
Data: [[ADDR]]