Skip to content

Commit 23743f5

Browse files
authored
[readobj][ELFExtendedAttrParser] Add destructor with error handling (#131783)
ELFExtendedAttrParser lacked a destructor that properly handled errors, causing `llvm-readobj --arch-specific` to crash when the AArch64 Build Attributes section was empty. This commit adds error handling in the destructor and introduces test files for `--arch-specific` to cover both an empty AArch64 Build Attributes section and a populated one. Fixes: sivan-shani@b1ebfac
1 parent 3d63191 commit 23743f5

File tree

3 files changed

+69
-0
lines changed

3 files changed

+69
-0
lines changed

llvm/include/llvm/Support/ELFAttrParserExtended.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class ELFExtendedAttrParser : public ELFAttributeParser {
3535
const unsigned Tag);
3636

3737
public:
38+
virtual ~ELFExtendedAttrParser() { static_cast<void>(!Cursor.takeError()); }
3839
Error parse(ArrayRef<uint8_t> Section, llvm::endianness Endian) override;
3940

4041
std::optional<unsigned> getAttributeValue(unsigned Tag) const override;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// RUN: llvm-mc -triple=aarch64 -filetype=obj %s | llvm-readelf --arch-specific - | FileCheck %s --check-prefix=CHECK
2+
3+
// test llvm-readelf with empty file.
4+
5+
// CHECK: BuildAttributes {
6+
// CHECK-NEXT: }
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// RUN: llvm-mc -triple=aarch64 -filetype=obj %s | llvm-readelf --arch-specific - | FileCheck %s --check-prefix=ASM
2+
3+
// ASM: BuildAttributes {
4+
// ASM-NEXT: FormatVersion: 0x41
5+
// ASM-NEXT: Section 1 {
6+
// ASM-NEXT: SectionLength: 21
7+
// ASM-NEXT: VendorName: subsection_a Optionality: optional Type: uleb128
8+
// ASM-NEXT: Attributes {
9+
// ASM-NEXT: 7: 11
10+
// ASM-NEXT: }
11+
// ASM-NEXT: }
12+
// ASM-NEXT: Section 2 {
13+
// ASM-NEXT: SectionLength: 32
14+
// ASM-NEXT: VendorName: aeabi_subsection Optionality: optional Type: ntbs
15+
// ASM-NEXT: Attributes {
16+
// ASM-NEXT: 5: "Value"
17+
// ASM-NEXT: }
18+
// ASM-NEXT: }
19+
// ASM-NEXT: Section 3 {
20+
// ASM-NEXT: SectionLength: 22
21+
// ASM-NEXT: VendorName: subsection_b Optionality: required Type: uleb128
22+
// ASM-NEXT: Attributes {
23+
// ASM-NEXT: 6: 536
24+
// ASM-NEXT: }
25+
// ASM-NEXT: }
26+
// ASM-NEXT: Section 4 {
27+
// ASM-NEXT: SectionLength: 26
28+
// ASM-NEXT: VendorName: aeabi_pauthabi Optionality: required Type: uleb128
29+
// ASM-NEXT: Attributes {
30+
// ASM-NEXT: Tag_PAuth_Platform: 9
31+
// ASM-NEXT: Tag_PAuth_Schema: 777
32+
// ASM-NEXT: }
33+
// ASM-NEXT: }
34+
// ASM-NEXT: Section 5 {
35+
// ASM-NEXT: SectionLength: 35
36+
// ASM-NEXT: VendorName: aeabi_feature_and_bits Optionality: optional Type: uleb128
37+
// ASM-NEXT: Attributes {
38+
// ASM-NEXT: Tag_Feature_BTI: 1
39+
// ASM-NEXT: Tag_Feature_PAC: 1
40+
// ASM-NEXT: Tag_Feature_GCS: 1
41+
// ASM-NEXT: }
42+
// ASM-NEXT: }
43+
// ASM-NEXT: }
44+
45+
46+
.aeabi_subsection subsection_a, optional, uleb128
47+
.aeabi_subsection aeabi_subsection, optional, ntbs
48+
.aeabi_subsection subsection_b, required, uleb128
49+
.aeabi_subsection aeabi_pauthabi, required, uleb128
50+
.aeabi_attribute Tag_PAuth_Platform, 7
51+
.aeabi_attribute Tag_PAuth_Schema, 777
52+
.aeabi_attribute Tag_PAuth_Platform, 9
53+
.aeabi_subsection aeabi_feature_and_bits, optional, uleb128
54+
.aeabi_attribute Tag_Feature_BTI, 1
55+
.aeabi_attribute Tag_Feature_PAC, 1
56+
.aeabi_attribute Tag_Feature_GCS, 1
57+
.aeabi_subsection aeabi_subsection, optional, ntbs
58+
.aeabi_attribute 5, "Value"
59+
.aeabi_subsection subsection_b, required, uleb128
60+
.aeabi_attribute 6, 536
61+
.aeabi_subsection subsection_a, optional, uleb128
62+
.aeabi_attribute 7, 11

0 commit comments

Comments
 (0)