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

Xing GUO via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 11 19:57:20 PDT 2020


Higuoxing created this revision.
Higuoxing added reviewers: jhenderson, grimar, MaskRay.
Herald added subscribers: llvm-commits, hiraditya, emaste.
Herald added a reviewer: espindola.
Herald added a project: LLVM.
Higuoxing requested review of this revision.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D85805

Files:
  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


Index: llvm/test/tools/yaml2obj/ELF/DWARF/debug-info.yaml
===================================================================
--- llvm/test/tools/yaml2obj/ELF/DWARF/debug-info.yaml
+++ llvm/test/tools/yaml2obj/ELF/DWARF/debug-info.yaml
@@ -874,3 +874,27 @@
         - 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
Index: llvm/lib/ObjectYAML/DWARFYAML.cpp
===================================================================
--- llvm/lib/ObjectYAML/DWARFYAML.cpp
+++ llvm/lib/ObjectYAML/DWARFYAML.cpp
@@ -150,7 +150,7 @@
   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);
 }
 
Index: llvm/lib/ObjectYAML/DWARFEmitter.cpp
===================================================================
--- llvm/lib/ObjectYAML/DWARFEmitter.cpp
+++ llvm/lib/ObjectYAML/DWARFEmitter.cpp
@@ -382,7 +382,12 @@
 
 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 @@
     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());
Index: llvm/include/llvm/ObjectYAML/DWARFYAML.h
===================================================================
--- llvm/include/llvm/ObjectYAML/DWARFYAML.h
+++ llvm/include/llvm/ObjectYAML/DWARFYAML.h
@@ -123,7 +123,7 @@
   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;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D85805.284957.patch
Type: text/x-patch
Size: 3575 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200812/8929bc57/attachment.bin>


More information about the llvm-commits mailing list