@@ -97,3 +97,41 @@ TEST(ToAtomsTest, basic_obj_x86_64) {
97
97
EXPECT_TRUE (atom4->name ().equals (" _undef" ));
98
98
EXPECT_EQ (lld::Atom::definitionUndefined, atom4->definition ());
99
99
}
100
+
101
+ TEST (ToAtomsTest, reservedUnitLength) {
102
+ static const uint8_t debugInfoWithReservedLengthContent[12 ] = {
103
+ 0xf0 , 0xff , 0xff , 0xff // Reserved length value
104
+ };
105
+ static const uint8_t debugInfoWithValidBigLengthContent[12 ] = {
106
+ 0xef , 0xff , 0xff , 0xff , // The maximum valid length value for DWARF32
107
+ 0x00 , 0x00 // Wrong version
108
+ };
109
+ static const uint8_t debugAbbrevDummyContent[] = {0x00 };
110
+
111
+ NormalizedFile fReservedLength , fValidBigLength ;
112
+ fReservedLength .arch = lld::MachOLinkingContext::arch_x86;
113
+ fValidBigLength .arch = lld::MachOLinkingContext::arch_x86;
114
+ Section section;
115
+ section.segmentName = " __DWARF" ;
116
+ section.sectionName = " __debug_info" ;
117
+ section.content = llvm::makeArrayRef (debugInfoWithReservedLengthContent);
118
+ fReservedLength .sections .push_back (section);
119
+ section.content = llvm::makeArrayRef (debugInfoWithValidBigLengthContent);
120
+ fValidBigLength .sections .push_back (section);
121
+ section.sectionName = " __debug_abbrev" ;
122
+ section.content = llvm::makeArrayRef (debugAbbrevDummyContent);
123
+ fReservedLength .sections .push_back (section);
124
+ fValidBigLength .sections .push_back (section);
125
+
126
+ auto resultReservedLength = normalizedToAtoms (fReservedLength , " foo" , false );
127
+ auto resultValidBigLength = normalizedToAtoms (fValidBigLength , " foo" , false );
128
+
129
+ // Both cases should return errors, but different.
130
+ ASSERT_FALSE (resultReservedLength);
131
+ ASSERT_FALSE (resultValidBigLength);
132
+
133
+ EXPECT_STREQ (" Malformed DWARF in foo" ,
134
+ toString (resultReservedLength.takeError ()).c_str ());
135
+ EXPECT_STREQ (" Unsupported DWARF version in foo" ,
136
+ toString (resultValidBigLength.takeError ()).c_str ());
137
+ }
0 commit comments