[llvm] e891b6a - [DWARFYAML] Make the address size of compilation units optional.

Xing GUO via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 12 06:48:06 PDT 2020


Author: Xing GUO
Date: 2020-08-12T21:47:32+08:00
New Revision: e891b6a75d919b5bcb95577d1e5eb0ebad0ea427

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

LOG: [DWARFYAML] Make the address size of compilation units optional.

This patch makes the 'AddrSize' field optional. If the address size is
missing, yaml2obj will infer it from the object file.

Reviewed By: jhenderson

Differential Revision: https://reviews.llvm.org/D85805

Added: 
    

Modified: 
    llvm/include/llvm/ObjectYAML/DWARFYAML.h
    llvm/lib/ObjectYAML/DWARFEmitter.cpp
    llvm/lib/ObjectYAML/DWARFYAML.cpp
    llvm/test/tools/yaml2obj/ELF/DWARF/debug-info.yaml

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/ObjectYAML/DWARFYAML.h b/llvm/include/llvm/ObjectYAML/DWARFYAML.h
index d927b1e72092b..e548f2a236f0e 100644
--- a/llvm/include/llvm/ObjectYAML/DWARFYAML.h
+++ b/llvm/include/llvm/ObjectYAML/DWARFYAML.h
@@ -123,7 +123,7 @@ struct Unit {
   dwarf::DwarfFormat Format;
   Optional<yaml::Hex64> Length;
   uint16_t Version;
-  uint8_t AddrSize;
+  Optional<uint8_t> AddrSize;
   llvm::dwarf::UnitType Type; // Added in DWARF 5
   yaml::Hex64 AbbrOffset;
   std::vector<Entry> Entries;

diff  --git a/llvm/lib/ObjectYAML/DWARFEmitter.cpp b/llvm/lib/ObjectYAML/DWARFEmitter.cpp
index 7c2e7504f77ec..a20322cc766d5 100644
--- a/llvm/lib/ObjectYAML/DWARFEmitter.cpp
+++ b/llvm/lib/ObjectYAML/DWARFEmitter.cpp
@@ -382,7 +382,12 @@ static Expected<uint64_t> writeDIE(ArrayRef<DWARFYAML::Abbrev> AbbrevDecls,
 
 Error DWARFYAML::emitDebugInfo(raw_ostream &OS, const DWARFYAML::Data &DI) {
   for (const DWARFYAML::Unit &Unit : DI.CompileUnits) {
-    dwarf::FormParams Params = {Unit.Version, Unit.AddrSize, Unit.Format};
+    uint8_t AddrSize;
+    if (Unit.AddrSize)
+      AddrSize = *Unit.AddrSize;
+    else
+      AddrSize = DI.Is64BitAddrSize ? 8 : 4;
+    dwarf::FormParams Params = {Unit.Version, AddrSize, Unit.Format};
     uint64_t Length = 3; // sizeof(version) + sizeof(address_size)
     Length += Unit.Version >= 5 ? 1 : 0;       // sizeof(unit_type)
     Length += Params.getDwarfOffsetByteSize(); // sizeof(debug_abbrev_offset)
@@ -411,11 +416,11 @@ Error DWARFYAML::emitDebugInfo(raw_ostream &OS, const DWARFYAML::Data &DI) {
     writeInteger((uint16_t)Unit.Version, OS, DI.IsLittleEndian);
     if (Unit.Version >= 5) {
       writeInteger((uint8_t)Unit.Type, OS, DI.IsLittleEndian);
-      writeInteger((uint8_t)Unit.AddrSize, OS, DI.IsLittleEndian);
+      writeInteger((uint8_t)AddrSize, OS, DI.IsLittleEndian);
       writeDWARFOffset(Unit.AbbrOffset, Unit.Format, OS, DI.IsLittleEndian);
     } else {
       writeDWARFOffset(Unit.AbbrOffset, Unit.Format, OS, DI.IsLittleEndian);
-      writeInteger((uint8_t)Unit.AddrSize, OS, DI.IsLittleEndian);
+      writeInteger((uint8_t)AddrSize, OS, DI.IsLittleEndian);
     }
 
     OS.write(EntryBuffer.data(), EntryBuffer.size());

diff  --git a/llvm/lib/ObjectYAML/DWARFYAML.cpp b/llvm/lib/ObjectYAML/DWARFYAML.cpp
index 048a7237774c4..01a5d75c50b6a 100644
--- a/llvm/lib/ObjectYAML/DWARFYAML.cpp
+++ b/llvm/lib/ObjectYAML/DWARFYAML.cpp
@@ -150,7 +150,7 @@ void MappingTraits<DWARFYAML::Unit>::mapping(IO &IO, DWARFYAML::Unit &Unit) {
   if (Unit.Version >= 5)
     IO.mapRequired("UnitType", Unit.Type);
   IO.mapRequired("AbbrOffset", Unit.AbbrOffset);
-  IO.mapRequired("AddrSize", Unit.AddrSize);
+  IO.mapOptional("AddrSize", Unit.AddrSize);
   IO.mapOptional("Entries", Unit.Entries);
 }
 

diff  --git a/llvm/test/tools/yaml2obj/ELF/DWARF/debug-info.yaml b/llvm/test/tools/yaml2obj/ELF/DWARF/debug-info.yaml
index 25b5a88b84101..a1b6bf2bc19da 100644
--- a/llvm/test/tools/yaml2obj/ELF/DWARF/debug-info.yaml
+++ b/llvm/test/tools/yaml2obj/ELF/DWARF/debug-info.yaml
@@ -453,7 +453,6 @@ DWARF:
       Version:    5
       UnitType:   DW_UT_type
       AbbrOffset: 0x1234
-      AddrSize:   4
       Entries:    []
 
 ## e) Test that yaml2obj emits an error message when both the "Content" and the
@@ -482,7 +481,6 @@ DWARF:
       Version:    5
       UnitType:   DW_UT_type
       AbbrOffset: 0x1234
-      AddrSize:   4
       Entries:    []
 
 ## f) Test that all the properties can be overridden by the section header when
@@ -550,7 +548,6 @@ DWARF:
       Version:    5
       UnitType:   DW_UT_type
       AbbrOffset: 0x1234
-      AddrSize:   4
       Entries:
         - AbbrCode: 0
           Values:   []
@@ -568,7 +565,7 @@ DWARF:
 
 --- !ELF
 FileHeader:
-  Class:   ELFCLASS64
+  Class:   ELFCLASS32
   Data:    ELFDATA2LSB
   Type:    ET_EXEC
   Machine: EM_X86_64
@@ -578,7 +575,6 @@ DWARF:
       Version:    5
       UnitType:   DW_UT_type
       AbbrOffset: 0x1234
-      AddrSize:   4
       Entries:    []
 
 ## h) Test that yaml2obj emits values in the DIE according to the abbreviation whose
@@ -604,7 +600,7 @@ DWARF:
 
 --- !ELF
 FileHeader:
-  Class:   ELFCLASS64
+  Class:   ELFCLASS32
   Data:    ELFDATA2LSB
   Type:    ET_EXEC
   Machine: EM_X86_64
@@ -629,7 +625,6 @@ DWARF:
       Version:    5
       UnitType:   DW_UT_type
       AbbrOffset: 0x1234
-      AddrSize:   4
       Entries:
         ## Test that yaml2obj emits values when the abbrev code is specified.
         - AbbrCode: 2
@@ -667,7 +662,6 @@ DWARF:
       Version:    5
       UnitType:   DW_UT_type
       AbbrOffset: 0x1234
-      AddrSize:   4
       Entries:
         - AbbrCode: 1
           Values:
@@ -703,7 +697,6 @@ DWARF:
       Version:    5
       UnitType:   DW_UT_type
       AbbrOffset: 0x1234
-      AddrSize:   8
       Entries:    []
 
 ## DWARFv4 unit header.
@@ -733,7 +726,6 @@ DWARF:
       Length:     0x0c
       Version:    4
       AbbrOffset: 0x1234
-      AddrSize:   8
       Entries:    []
 
 ## k) Test that yaml2obj is able to emit a correct length for compilation units.
@@ -826,7 +818,6 @@ DWARF:
   debug_info:
     - Version:    4
       AbbrOffset: 0x00
-      AddrSize:   0x08
       Entries:
         - AbbrCode: 1
           Values:
@@ -869,8 +860,31 @@ DWARF:
   debug_info:
     - Version:    4
       AbbrOffset: 0x00
-      AddrSize:   0x08
       Entries:
         - AbbrCode: 1
         - AbbrCode: 0
         - AbbrCode: 2
+
+## m) Test that yaml2obj is able to infer the address size from the object file.
+
+# RUN: yaml2obj --docnum=15 -DBITS=64 %s -o %t15.64-bit.o
+# RUN: llvm-readelf --hex-dump=.debug_info %t15.64-bit.o | \
+# RUN:   FileCheck %s --check-prefix=ADDRSIZE -DADDRSIZE=08
+
+#      ADDRSIZE: Hex dump of section '.debug_info':
+# ADDRSIZE-NEXT: 0x00000000 07000000 04000000 0000[[ADDRSIZE]]            ...........
+
+# RUN: yaml2obj --docnum=15 -DBITS=32 %s -o %t15.32-bit.o
+# RUN: llvm-readelf --hex-dump=.debug_info %t15.32-bit.o | \
+# RUN:   FileCheck %s --check-prefix=ADDRSIZE -DADDRSIZE=04
+
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS[[BITS]]
+  Data:    ELFDATA2LSB
+  Type:    ET_EXEC
+  Machine: EM_X86_64
+DWARF:
+  debug_info:
+    - Version:    4
+      AbbrOffset: 0x00


        


More information about the llvm-commits mailing list