[llvm] 006f6f8 - [DWARFYAML] Make the 'AddressSize', 'SegmentSelectorSize' fields optional.
Xing GUO via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 30 02:41:22 PDT 2020
Author: Xing GUO
Date: 2020-07-30T17:39:58+08:00
New Revision: 006f6f8ac6fe920e978f65d92bb44825833f2933
URL: https://github.com/llvm/llvm-project/commit/006f6f8ac6fe920e978f65d92bb44825833f2933
DIFF: https://github.com/llvm/llvm-project/commit/006f6f8ac6fe920e978f65d92bb44825833f2933.diff
LOG: [DWARFYAML] Make the 'AddressSize', 'SegmentSelectorSize' fields optional.
This patch makes the 'AddressSize' and 'SegmentSelectorSize' fields of
address range table optional.
Reviewed By: jhenderson
Differential Revision: https://reviews.llvm.org/D84907
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/tools/yaml2obj/ELF/DWARF/debug-aranges.yaml
Removed:
################################################################################
diff --git a/llvm/include/llvm/ObjectYAML/DWARFYAML.h b/llvm/include/llvm/ObjectYAML/DWARFYAML.h
index 6b8ab07274ac..5375074817fa 100644
--- a/llvm/include/llvm/ObjectYAML/DWARFYAML.h
+++ b/llvm/include/llvm/ObjectYAML/DWARFYAML.h
@@ -69,7 +69,7 @@ struct ARange {
yaml::Hex64 Length;
uint16_t Version;
yaml::Hex64 CuOffset;
- yaml::Hex8 AddrSize;
+ Optional<yaml::Hex8> AddrSize;
yaml::Hex8 SegSize;
std::vector<ARangeDescriptor> Descriptors;
};
diff --git a/llvm/lib/ObjectYAML/DWARFEmitter.cpp b/llvm/lib/ObjectYAML/DWARFEmitter.cpp
index 66fabe875f7b..0790eb623440 100644
--- a/llvm/lib/ObjectYAML/DWARFEmitter.cpp
+++ b/llvm/lib/ObjectYAML/DWARFEmitter.cpp
@@ -127,26 +127,33 @@ Error DWARFYAML::emitDebugAbbrev(raw_ostream &OS, const DWARFYAML::Data &DI) {
Error DWARFYAML::emitDebugAranges(raw_ostream &OS, const DWARFYAML::Data &DI) {
for (auto Range : DI.ARanges) {
auto HeaderStart = OS.tell();
+
+ uint8_t AddrSize;
+ if (Range.AddrSize)
+ AddrSize = *Range.AddrSize;
+ else
+ AddrSize = DI.Is64BitAddrSize ? 8 : 4;
+
writeInitialLength(Range.Format, Range.Length, OS, DI.IsLittleEndian);
writeInteger((uint16_t)Range.Version, OS, DI.IsLittleEndian);
writeDWARFOffset(Range.CuOffset, Range.Format, OS, DI.IsLittleEndian);
- writeInteger((uint8_t)Range.AddrSize, OS, DI.IsLittleEndian);
+ writeInteger((uint8_t)AddrSize, OS, DI.IsLittleEndian);
writeInteger((uint8_t)Range.SegSize, OS, DI.IsLittleEndian);
auto HeaderSize = OS.tell() - HeaderStart;
- auto FirstDescriptor = alignTo(HeaderSize, Range.AddrSize * 2);
+ auto FirstDescriptor = alignTo(HeaderSize, AddrSize * 2);
ZeroFillBytes(OS, FirstDescriptor - HeaderSize);
for (auto Descriptor : Range.Descriptors) {
- if (Error Err = writeVariableSizedInteger(
- Descriptor.Address, Range.AddrSize, OS, DI.IsLittleEndian))
+ if (Error Err = writeVariableSizedInteger(Descriptor.Address, AddrSize,
+ OS, DI.IsLittleEndian))
return createStringError(errc::not_supported,
"unable to write debug_aranges address: %s",
toString(std::move(Err)).c_str());
- cantFail(writeVariableSizedInteger(Descriptor.Length, Range.AddrSize, OS,
+ cantFail(writeVariableSizedInteger(Descriptor.Length, AddrSize, OS,
DI.IsLittleEndian));
}
- ZeroFillBytes(OS, Range.AddrSize * 2);
+ ZeroFillBytes(OS, AddrSize * 2);
}
return Error::success();
diff --git a/llvm/lib/ObjectYAML/DWARFYAML.cpp b/llvm/lib/ObjectYAML/DWARFYAML.cpp
index fda1ba797a91..5c2675e1d1eb 100644
--- a/llvm/lib/ObjectYAML/DWARFYAML.cpp
+++ b/llvm/lib/ObjectYAML/DWARFYAML.cpp
@@ -106,8 +106,8 @@ void MappingTraits<DWARFYAML::ARange>::mapping(IO &IO,
IO.mapRequired("Length", ARange.Length);
IO.mapRequired("Version", ARange.Version);
IO.mapRequired("CuOffset", ARange.CuOffset);
- IO.mapRequired("AddressSize", ARange.AddrSize);
- IO.mapRequired("SegmentSelectorSize", ARange.SegSize);
+ IO.mapOptional("AddressSize", ARange.AddrSize);
+ IO.mapOptional("SegmentSelectorSize", ARange.SegSize, 0);
IO.mapRequired("Descriptors", ARange.Descriptors);
}
diff --git a/llvm/test/ObjectYAML/MachO/DWARF-debug_aranges.yaml b/llvm/test/ObjectYAML/MachO/DWARF-debug_aranges.yaml
index 868054b08a99..ecdd88a68dd0 100644
--- a/llvm/test/ObjectYAML/MachO/DWARF-debug_aranges.yaml
+++ b/llvm/test/ObjectYAML/MachO/DWARF-debug_aranges.yaml
@@ -328,7 +328,6 @@ DWARF:
# CHECK-NEXT: Version: 2
# CHECK-NEXT: CuOffset: 0x0000000000000000
# CHECK-NEXT: AddressSize: 0x08
-# CHECK-NEXT: SegmentSelectorSize: 0x00
# CHECK-NEXT: Descriptors:
# CHECK-NEXT: - Address: 0x0000000100000F50
# CHECK-NEXT: Length: 52
diff --git a/llvm/test/tools/yaml2obj/ELF/DWARF/debug-aranges.yaml b/llvm/test/tools/yaml2obj/ELF/DWARF/debug-aranges.yaml
index b1064a9ae215..b11d107f5bad 100644
--- a/llvm/test/tools/yaml2obj/ELF/DWARF/debug-aranges.yaml
+++ b/llvm/test/tools/yaml2obj/ELF/DWARF/debug-aranges.yaml
@@ -458,3 +458,55 @@ DWARF:
Descriptors:
- Address: 0x1234
Length: 0x1000
+
+## j) Test the default value of address_size and segment_selector_size in a 64/32-bit object file.
+
+# RUN: yaml2obj --docnum=10 -DCLASS=ELFCLASS64 %s -o %t10.64-bit.o
+# RUN: llvm-readelf --hex-dump=.debug_aranges %t10.64-bit.o | \
+# RUN: FileCheck %s --check-prefix=DEFAULT64
+
+# DEFAULT64: Hex dump of section '.debug_aranges':
+# DEFAULT64-NEXT: 0x00000000 2c000000 02000000 00000800 00000000 ,...............
+## ^------- unit_length (4-byte)
+## ^--- version (2-byte)
+## ^-------- debug_info_offset (4-byte)
+## ^- address_size (1-byte)
+## ^- segment_selector_size (1-byte)
+## ^------- padding (4-byte)
+# DEFAULT64-NEXT: 0x00000010 34120000 00000000 00100000 00000000 4...............
+## ^---------------- address (8-byte)
+## ^---------------- length (8-byte)
+# DEFAULT64-NEXT: 0x00000020 00000000 00000000 00000000 00000000 ................
+## ^---------------------------------- terminating entry (16-byte)
+
+# RUN: yaml2obj --docnum=10 -DCLASS=ELFCLASS32 %s -o %t10.32-bit.o
+# RUN: llvm-readelf --hex-dump=.debug_aranges %t10.32-bit.o | \
+# RUN: FileCheck %s --check-prefix=DEFAULT32
+
+# DEFAULT32: Hex dump of section '.debug_aranges':
+# DEFAULT32-NEXT: 0x00000000 2c000000 02000000 00000400 00000000 ,...............
+## ^------- unit_length (4-byte)
+## ^--- version (2-byte)
+## ^-------- debug_info_offset (4-byte)
+## ^- address_size (1-byte)
+## ^- segment_selector_size (1-byte)
+## ^------- padding (4-byte)
+# DEFAULT32-NEXT: 0x00000010 34120000 00100000 00000000 00000000 4...............
+## ^------- address (4-byte)
+## ^------- length (4-byte)
+## ^---------------- terminating entry (8-byte)
+
+--- !ELF
+FileHeader:
+ Class: [[CLASS]]
+ Data: ELFDATA2LSB
+ Type: ET_EXEC
+ Machine: EM_X86_64
+DWARF:
+ debug_aranges:
+ - Length: 0x2c
+ Version: 2
+ CuOffset: 0
+ Descriptors:
+ - Address: 0x1234
+ Length: 0x1000
More information about the llvm-commits
mailing list