[llvm] 1d4bc08 - [DWARFYAML] Let the address size of line tables inferred from the object file.

Xing GUO via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 11 07:46:04 PDT 2020


Author: Xing GUO
Date: 2020-08-11T22:45:55+08:00
New Revision: 1d4bc08ce43c8e2f07df3aa22a0787907750bf88

URL: https://github.com/llvm/llvm-project/commit/1d4bc08ce43c8e2f07df3aa22a0787907750bf88
DIFF: https://github.com/llvm/llvm-project/commit/1d4bc08ce43c8e2f07df3aa22a0787907750bf88.diff

LOG: [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

Added: 
    

Modified: 
    llvm/lib/ObjectYAML/DWARFEmitter.cpp
    llvm/test/tools/yaml2obj/ELF/DWARF/debug-line.yaml

Removed: 
    


################################################################################
diff  --git a/llvm/lib/ObjectYAML/DWARFEmitter.cpp b/llvm/lib/ObjectYAML/DWARFEmitter.cpp
index ad03104552e1..103e8b25441f 100644
--- a/llvm/lib/ObjectYAML/DWARFEmitter.cpp
+++ b/llvm/lib/ObjectYAML/DWARFEmitter.cpp
@@ -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);

diff  --git a/llvm/test/tools/yaml2obj/ELF/DWARF/debug-line.yaml b/llvm/test/tools/yaml2obj/ELF/DWARF/debug-line.yaml
index 020fadc57b34..0c86a8194fa2 100644
--- a/llvm/test/tools/yaml2obj/ELF/DWARF/debug-line.yaml
+++ b/llvm/test/tools/yaml2obj/ELF/DWARF/debug-line.yaml
@@ -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]]


        


More information about the llvm-commits mailing list