[llvm] 929edd8 - [DWARFYAML][debug_aranges] Replace InitialLength with Format and Length.
Xing GUO via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 4 21:13:14 PDT 2020
Author: Xing GUO
Date: 2020-06-05T12:16:44+08:00
New Revision: 929edd8bd25b0390de97994eb90f42b26636d205
URL: https://github.com/llvm/llvm-project/commit/929edd8bd25b0390de97994eb90f42b26636d205
DIFF: https://github.com/llvm/llvm-project/commit/929edd8bd25b0390de97994eb90f42b26636d205.diff
LOG: [DWARFYAML][debug_aranges] Replace InitialLength with Format and Length.
This patch addresses the comment in [D80972](https://reviews.llvm.org/D80972#inline-744217).
Before this patch, the initial length field of .debug_aranges section should be declared as:
```
## 32-bit DWARF
debug_aranges:
- Length:
TotalLength: 0x20
Version: 2
...
## 64-bit DWARF
debug_aranges:
- Length:
TotalLength: 0xffffffff
TotalLength64: 0x20
Version: 2
...
```
After this patch:
```
## 32-bit DWARF
debug_aranges:
- [[Format: DWARF32]] ## Optional
Length: 0x20
Version: 2
...
## 64-bit DWARF
debug_aranges:
- Format: DWARF64
Length: 0x20
Version: 2
```
Current implementation of generating DWARF64 .debug_aranges section is buggy. A follow-up patch will improve it and add test cases for DWARF64.
Reviewed By: jhenderson
Differential Revision: https://reviews.llvm.org/D81063
Added:
Modified:
llvm/include/llvm/ObjectYAML/DWARFYAML.h
llvm/lib/ObjectYAML/DWARFEmitter.cpp
llvm/lib/ObjectYAML/DWARFYAML.cpp
llvm/test/ObjectYAML/MachO/DWARF-debug_aranges.yaml
llvm/test/ObjectYAML/MachO/DWARF-debug_info.yaml
llvm/test/ObjectYAML/MachO/DWARF-debug_line.yaml
llvm/test/ObjectYAML/MachO/DWARF5-debug_info.yaml
llvm/test/tools/llvm-gsymutil/ARM_AArch64/fat-macho-dwarf.yaml
llvm/test/tools/llvm-gsymutil/X86/mach-dwarf.yaml
llvm/test/tools/obj2yaml/MachO/DWARF-debug_aranges-error.yaml
llvm/test/tools/yaml2obj/ELF/DWARF/debug-aranges.yaml
llvm/tools/obj2yaml/dwarf2yaml.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/ObjectYAML/DWARFYAML.h b/llvm/include/llvm/ObjectYAML/DWARFYAML.h
index 509417beb283..f270b09b1916 100644
--- a/llvm/include/llvm/ObjectYAML/DWARFYAML.h
+++ b/llvm/include/llvm/ObjectYAML/DWARFYAML.h
@@ -64,7 +64,8 @@ struct ARangeDescriptor {
};
struct ARange {
- InitialLength Length;
+ dwarf::DwarfFormat Format;
+ uint64_t Length;
uint16_t Version;
uint32_t CuOffset;
uint8_t AddrSize;
@@ -263,6 +264,13 @@ template <> struct MappingTraits<DWARFYAML::InitialLength> {
static void mapping(IO &IO, DWARFYAML::InitialLength &DWARF);
};
+template <> struct ScalarEnumerationTraits<dwarf::DwarfFormat> {
+ static void enumeration(IO &IO, dwarf::DwarfFormat &Format) {
+ IO.enumCase(Format, "DWARF32", dwarf::DWARF32);
+ IO.enumCase(Format, "DWARF64", dwarf::DWARF64);
+ }
+};
+
#define HANDLE_DW_TAG(unused, name, unused2, unused3, unused4) \
io.enumCase(value, "DW_TAG_" #name, dwarf::DW_TAG_##name);
diff --git a/llvm/lib/ObjectYAML/DWARFEmitter.cpp b/llvm/lib/ObjectYAML/DWARFEmitter.cpp
index a04f3c8f08d0..29320f085b8a 100644
--- a/llvm/lib/ObjectYAML/DWARFEmitter.cpp
+++ b/llvm/lib/ObjectYAML/DWARFEmitter.cpp
@@ -15,6 +15,7 @@
#include "DWARFVisitor.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringRef.h"
+#include "llvm/BinaryFormat/Dwarf.h"
#include "llvm/ObjectYAML/DWARFYAML.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/Host.h"
@@ -94,7 +95,11 @@ void DWARFYAML::EmitDebugAbbrev(raw_ostream &OS, const DWARFYAML::Data &DI) {
void DWARFYAML::EmitDebugAranges(raw_ostream &OS, const DWARFYAML::Data &DI) {
for (auto Range : DI.ARanges) {
auto HeaderStart = OS.tell();
- writeInitialLength(Range.Length, OS, DI.IsLittleEndian);
+ if (Range.Format == dwarf::DWARF64) {
+ writeInteger((uint32_t)dwarf::DW_LENGTH_DWARF64, OS, DI.IsLittleEndian);
+ writeInteger((uint64_t)Range.Length, OS, DI.IsLittleEndian);
+ } else
+ writeInteger((uint32_t)Range.Length, OS, DI.IsLittleEndian);
writeInteger((uint16_t)Range.Version, OS, DI.IsLittleEndian);
writeInteger((uint32_t)Range.CuOffset, OS, DI.IsLittleEndian);
writeInteger((uint8_t)Range.AddrSize, OS, DI.IsLittleEndian);
diff --git a/llvm/lib/ObjectYAML/DWARFYAML.cpp b/llvm/lib/ObjectYAML/DWARFYAML.cpp
index 6e43e72ddd48..adf92445dbb4 100644
--- a/llvm/lib/ObjectYAML/DWARFYAML.cpp
+++ b/llvm/lib/ObjectYAML/DWARFYAML.cpp
@@ -12,6 +12,7 @@
//===----------------------------------------------------------------------===//
#include "llvm/ObjectYAML/DWARFYAML.h"
+#include "llvm/BinaryFormat/Dwarf.h"
namespace llvm {
@@ -74,6 +75,7 @@ void MappingTraits<DWARFYAML::ARangeDescriptor>::mapping(
void MappingTraits<DWARFYAML::ARange>::mapping(IO &IO,
DWARFYAML::ARange &ARange) {
+ IO.mapOptional("Format", ARange.Format, dwarf::DWARF32);
IO.mapRequired("Length", ARange.Length);
IO.mapRequired("Version", ARange.Version);
IO.mapRequired("CuOffset", ARange.CuOffset);
diff --git a/llvm/test/ObjectYAML/MachO/DWARF-debug_aranges.yaml b/llvm/test/ObjectYAML/MachO/DWARF-debug_aranges.yaml
index 0b0421d6a092..2822c94d7751 100644
--- a/llvm/test/ObjectYAML/MachO/DWARF-debug_aranges.yaml
+++ b/llvm/test/ObjectYAML/MachO/DWARF-debug_aranges.yaml
@@ -313,8 +313,7 @@ LinkEditData:
- _main
DWARF:
debug_aranges:
- - Length:
- TotalLength: 44
+ - Length: 44
Version: 2
CuOffset: 0
AddrSize: 8
@@ -326,8 +325,7 @@ DWARF:
#CHECK: DWARF:
#CHECK: debug_aranges:
-#CHECK: - Length:
-#CHECK: TotalLength: 44
+#CHECK: - Length: 44
#CHECK: Version: 2
#CHECK: CuOffset: 0
#CHECK: AddrSize: 8
diff --git a/llvm/test/ObjectYAML/MachO/DWARF-debug_info.yaml b/llvm/test/ObjectYAML/MachO/DWARF-debug_info.yaml
index 3b311cf1681e..95f3eae597c2 100644
--- a/llvm/test/ObjectYAML/MachO/DWARF-debug_info.yaml
+++ b/llvm/test/ObjectYAML/MachO/DWARF-debug_info.yaml
@@ -375,8 +375,7 @@ DWARF:
- Attribute: DW_AT_type
Form: DW_FORM_ref4
debug_aranges:
- - Length:
- TotalLength: 44
+ - Length: 44
Version: 2
CuOffset: 0
AddrSize: 8
diff --git a/llvm/test/ObjectYAML/MachO/DWARF-debug_line.yaml b/llvm/test/ObjectYAML/MachO/DWARF-debug_line.yaml
index a80b118c3e38..5d17deb2fac2 100644
--- a/llvm/test/ObjectYAML/MachO/DWARF-debug_line.yaml
+++ b/llvm/test/ObjectYAML/MachO/DWARF-debug_line.yaml
@@ -394,8 +394,7 @@ DWARF:
- Attribute: DW_AT_type
Form: DW_FORM_ref4
debug_aranges:
- - Length:
- TotalLength: 44
+ - Length: 44
Version: 2
CuOffset: 0
AddrSize: 8
diff --git a/llvm/test/ObjectYAML/MachO/DWARF5-debug_info.yaml b/llvm/test/ObjectYAML/MachO/DWARF5-debug_info.yaml
index 6387b132843e..574796cbebda 100644
--- a/llvm/test/ObjectYAML/MachO/DWARF5-debug_info.yaml
+++ b/llvm/test/ObjectYAML/MachO/DWARF5-debug_info.yaml
@@ -375,8 +375,7 @@ DWARF:
- Attribute: DW_AT_type
Form: DW_FORM_ref4
debug_aranges:
- - Length:
- TotalLength: 44
+ - Length: 44
Version: 2
CuOffset: 0
AddrSize: 8
diff --git a/llvm/test/tools/llvm-gsymutil/ARM_AArch64/fat-macho-dwarf.yaml b/llvm/test/tools/llvm-gsymutil/ARM_AArch64/fat-macho-dwarf.yaml
index 4eec1aa1632d..a144a37b7f2e 100644
--- a/llvm/test/tools/llvm-gsymutil/ARM_AArch64/fat-macho-dwarf.yaml
+++ b/llvm/test/tools/llvm-gsymutil/ARM_AArch64/fat-macho-dwarf.yaml
@@ -378,8 +378,7 @@ Slices:
- Attribute: DW_AT_type
Form: DW_FORM_ref_addr
debug_aranges:
- - Length:
- TotalLength: 28
+ - Length: 28
Version: 2
CuOffset: 0
AddrSize: 4
@@ -859,8 +858,7 @@ Slices:
- Attribute: DW_AT_type
Form: DW_FORM_ref_addr
debug_aranges:
- - Length:
- TotalLength: 44
+ - Length: 44
Version: 2
CuOffset: 0
AddrSize: 8
diff --git a/llvm/test/tools/llvm-gsymutil/X86/mach-dwarf.yaml b/llvm/test/tools/llvm-gsymutil/X86/mach-dwarf.yaml
index 8580637cdde0..664b4ee7c070 100644
--- a/llvm/test/tools/llvm-gsymutil/X86/mach-dwarf.yaml
+++ b/llvm/test/tools/llvm-gsymutil/X86/mach-dwarf.yaml
@@ -539,8 +539,7 @@ DWARF:
- Attribute: DW_AT_type
Form: DW_FORM_ref_addr
debug_aranges:
- - Length:
- TotalLength: 60
+ - Length: 60
Version: 2
CuOffset: 0
AddrSize: 8
diff --git a/llvm/test/tools/obj2yaml/MachO/DWARF-debug_aranges-error.yaml b/llvm/test/tools/obj2yaml/MachO/DWARF-debug_aranges-error.yaml
index 680b7c6e80a6..8f392bc6b700 100644
--- a/llvm/test/tools/obj2yaml/MachO/DWARF-debug_aranges-error.yaml
+++ b/llvm/test/tools/obj2yaml/MachO/DWARF-debug_aranges-error.yaml
@@ -287,8 +287,7 @@ LoadCommands:
reserved3: 0x00000000
DWARF:
debug_aranges:
- - Length:
- TotalLength: 45
+ - Length: 45
Version: 2
CuOffset: 0
AddrSize: 8
diff --git a/llvm/test/tools/yaml2obj/ELF/DWARF/debug-aranges.yaml b/llvm/test/tools/yaml2obj/ELF/DWARF/debug-aranges.yaml
index 0d8b4ee132c6..cae5a214d09e 100644
--- a/llvm/test/tools/yaml2obj/ELF/DWARF/debug-aranges.yaml
+++ b/llvm/test/tools/yaml2obj/ELF/DWARF/debug-aranges.yaml
@@ -2,9 +2,9 @@
## a) Generate the .debug_aranges section from the "DWARF" entry.
-## Generate and verify a big endian object file.
+## Generate and verify a big endian DWARF32 .debug_aranges section.
-# RUN: yaml2obj --docnum=1 -DENDIAN=ELFDATA2MSB %s -o %t.be.o
+# RUN: yaml2obj --docnum=1 -DENDIAN=ELFDATA2MSB -DFORMAT=DWARF32 %s -o %t.be.o
# RUN: llvm-readobj --sections --section-data %t.be.o | \
# RUN: FileCheck %s -DADDRALIGN=1 -DSIZE=96 --check-prefixes=DWARF-BE-HEADER,DWARF-BE-CONTENT
@@ -69,8 +69,8 @@ FileHeader:
Machine: EM_X86_64
DWARF:
debug_aranges:
- - Length:
- TotalLength: 0x2c
+ - Format: [[FORMAT]]
+ Length: 0x2c
Version: 2
CuOffset: 0
AddrSize: 0x04
@@ -78,8 +78,8 @@ DWARF:
Descriptors:
- Address: 0x00001234
Length: 0x20
- - Length:
- TotalLength: 0x2c
+ - Format: [[FORMAT]]
+ Length: 0x2c
Version: 2
CuOffset: 0x65
AddrSize: 0x08
@@ -90,9 +90,9 @@ DWARF:
- Address: 0x0000000056780000
Length: 0x10
-## Generate and verify a little endian object file.
+## Generate and verify a little endian DWARF32 .debug_aranges section.
-# RUN: yaml2obj --docnum=1 -DENDIAN=ELFDATA2LSB %s -o %t.le.o
+# RUN: yaml2obj --docnum=1 -DENDIAN=ELFDATA2LSB -DFORMAT=DWARF32 %s -o %t.le.o
# RUN: llvm-readobj --sections --section-data %t.le.o | \
# RUN: FileCheck %s --check-prefixes=DWARF-LE-DEFAULT
@@ -211,8 +211,7 @@ Sections:
Size: 0x10
DWARF:
debug_aranges:
- - Length:
- TotalLength: 0x2c
+ - Length: 0x2c
Version: 2
CuOffset: 0
AddrSize: 0x08
@@ -238,8 +237,7 @@ Sections:
Content: "00"
DWARF:
debug_aranges:
- - Length:
- TotalLength: 0x2c
+ - Length: 0x2c
Version: 2
CuOffset: 0
AddrSize: 0x08
@@ -304,8 +302,7 @@ Sections:
Type: SHT_STRTAB
DWARF:
debug_aranges:
- - Length:
- TotalLength: 0x2c
+ - Length: 0x2c
Version: 2
CuOffset: 0
AddrSize: 0x08
diff --git a/llvm/tools/obj2yaml/dwarf2yaml.cpp b/llvm/tools/obj2yaml/dwarf2yaml.cpp
index ec42f1caff7c..12cb0c294d4a 100644
--- a/llvm/tools/obj2yaml/dwarf2yaml.cpp
+++ b/llvm/tools/obj2yaml/dwarf2yaml.cpp
@@ -68,7 +68,8 @@ Error dumpDebugARanges(DWARFContext &DCtx, DWARFYAML::Data &Y) {
if (Error E = Set.extract(ArangesData, &Offset))
return E;
DWARFYAML::ARange Range;
- Range.Length.setLength(Set.getHeader().Length);
+ Range.Format = Set.getHeader().Format;
+ Range.Length = Set.getHeader().Length;
Range.Version = Set.getHeader().Version;
Range.CuOffset = Set.getHeader().CuOffset;
Range.AddrSize = Set.getHeader().AddrSize;
More information about the llvm-commits
mailing list