@@ -117,6 +117,161 @@ TEST_F(ObjectFileELFTest, SectionsResolveConsistently) {
117
117
EXPECT_EQ (text_sp, start->GetAddress ().GetSection ());
118
118
}
119
119
120
+ TEST_F (ObjectFileELFTest, GNUPropertyAArch64PAuthABI) {
121
+ // Successful parsing
122
+ {
123
+ llvm::StringRef SinglePropertyYaml = R"(
124
+ --- !ELF
125
+ FileHeader:
126
+ Class: ELFCLASS64
127
+ Data: ELFDATA2LSB
128
+ Type: ET_DYN
129
+ Machine: EM_AARCH64
130
+ Sections:
131
+ - Name: .note.gnu.property
132
+ Type: SHT_NOTE
133
+ Flags: [ SHF_ALLOC ]
134
+ AddressAlign: 0x8
135
+ Notes:
136
+ - Name: GNU
137
+ Desc: 010000C01000000002000000000000001F00000000000000
138
+ # ^^^^^^^^
139
+ # type = 0xC0000001 = GNU_PROPERTY_AARCH64_FEATURE_PAUTH
140
+ # ^^^^^^^^
141
+ # size = 0x00000010 = 16
142
+ # ^^^^^^^^^^^^^^^^
143
+ # platform = 0x0000000000000002 = 2
144
+ # ^^^^^^^^^^^^^^^^
145
+ # version = 0x000000000000001F = 31
146
+ Type: NT_GNU_PROPERTY_TYPE_0
147
+ ...
148
+ )" ;
149
+ llvm::StringRef MultiplePropertiesYaml = R"(
150
+ --- !ELF
151
+ FileHeader:
152
+ Class: ELFCLASS64
153
+ Data: ELFDATA2LSB
154
+ Type: ET_DYN
155
+ Machine: EM_AARCH64
156
+ Sections:
157
+ - Name: .note.gnu.property
158
+ Type: SHT_NOTE
159
+ Flags: [ SHF_ALLOC ]
160
+ AddressAlign: 0x8
161
+ Notes:
162
+ - Name: GNU
163
+ Desc: 42424242040000001234567800000000010000C01000000002000000000000001F00000000000000
164
+ # ^^^^^^^^
165
+ # dummy property type = 0x42424242
166
+ # ^^^^^^^^
167
+ # dummy property size = 0x00000008 = 4
168
+ # ^^^^^^^^________
169
+ # dummy property contents = 0x78563412 and padding
170
+ # ^^^^^^^^
171
+ # type = 0xC0000001 = GNU_PROPERTY_AARCH64_FEATURE_PAUTH
172
+ # ^^^^^^^^
173
+ # size = 0x00000010 = 16
174
+ # ^^^^^^^^^^^^^^^^
175
+ # platform = 0x0000000000000002 = 2
176
+ # ^^^^^^^^^^^^^^^^
177
+ # version = 0x000000000000001F = 31
178
+ Type: NT_GNU_PROPERTY_TYPE_0
179
+ ...
180
+ )" ;
181
+ std::array<llvm::Expected<TestFile>, 2 > TestFiles = {
182
+ TestFile::fromYaml (SinglePropertyYaml),
183
+ TestFile::fromYaml (MultiplePropertiesYaml)};
184
+
185
+ for (auto &TF : TestFiles) {
186
+ ASSERT_THAT_EXPECTED (TF, llvm::Succeeded ());
187
+
188
+ auto module_sp = std::make_shared<Module>(TF->moduleSpec ());
189
+ ObjectFile *obj_file = module_sp->GetObjectFile ();
190
+ ASSERT_NE (nullptr , obj_file);
191
+
192
+ std::optional<std::pair<uint64_t , uint64_t >> pauthabi =
193
+ obj_file->ParseGNUPropertyAArch64PAuthABI ();
194
+ ASSERT_NE (std::nullopt , pauthabi);
195
+ ASSERT_EQ (uint64_t (2 ), pauthabi->first );
196
+ ASSERT_EQ (uint64_t (31 ), pauthabi->second );
197
+ }
198
+ }
199
+
200
+ // Error during parsing
201
+ {
202
+ llvm::StringRef InvalidNameSizeYaml = R"(
203
+ --- !ELF
204
+ FileHeader:
205
+ Class: ELFCLASS64
206
+ Data: ELFDATA2LSB
207
+ Type: ET_DYN
208
+ Machine: EM_AARCH64
209
+ Sections:
210
+ - Name: .note.gnu.property
211
+ Type: SHT_NOTE
212
+ Flags: [ SHF_ALLOC ]
213
+ AddressAlign: 0x8
214
+ Notes:
215
+ - Name: XXXXX
216
+ Desc: 010000C01000000002000000000000001F00000000000000
217
+ Type: NT_GNU_PROPERTY_TYPE_0
218
+ ...
219
+ )" ;
220
+ llvm::StringRef InvalidNameYaml = R"(
221
+ --- !ELF
222
+ FileHeader:
223
+ Class: ELFCLASS64
224
+ Data: ELFDATA2LSB
225
+ Type: ET_DYN
226
+ Machine: EM_AARCH64
227
+ Sections:
228
+ - Name: .note.gnu.property
229
+ Type: SHT_NOTE
230
+ Flags: [ SHF_ALLOC ]
231
+ AddressAlign: 0x8
232
+ Notes:
233
+ - Name: XXX
234
+ Desc: 010000C01000000002000000000000001F00000000000000
235
+ Type: NT_GNU_PROPERTY_TYPE_0
236
+ ...
237
+ )" ;
238
+ llvm::StringRef InvalidPropertySizeYaml = R"(
239
+ --- !ELF
240
+ FileHeader:
241
+ Class: ELFCLASS64
242
+ Data: ELFDATA2LSB
243
+ Type: ET_DYN
244
+ Machine: EM_AARCH64
245
+ Sections:
246
+ - Name: .note.gnu.property
247
+ Type: SHT_NOTE
248
+ Flags: [ SHF_ALLOC ]
249
+ AddressAlign: 0x8
250
+ Notes:
251
+ - Name: XXXXX
252
+ Desc: 0000000000000000
253
+ Type: NT_GNU_PROPERTY_TYPE_0
254
+ ...
255
+ )" ;
256
+ std::array<llvm::Expected<TestFile>, 3 > TestFiles = {
257
+ TestFile::fromYaml (InvalidNameSizeYaml),
258
+ TestFile::fromYaml (InvalidNameYaml),
259
+ TestFile::fromYaml (InvalidPropertySizeYaml)};
260
+
261
+ for (auto &TF : TestFiles) {
262
+ ASSERT_THAT_EXPECTED (TF, llvm::Succeeded ());
263
+
264
+ auto module_sp = std::make_shared<Module>(TF->moduleSpec ());
265
+ ObjectFile *obj_file = module_sp->GetObjectFile ();
266
+ ASSERT_NE (nullptr , obj_file);
267
+
268
+ std::optional<std::pair<uint64_t , uint64_t >> pauthabi =
269
+ obj_file->ParseGNUPropertyAArch64PAuthABI ();
270
+ ASSERT_EQ (std::nullopt , pauthabi);
271
+ }
272
+ }
273
+ }
274
+
120
275
// Test that GetModuleSpecifications works on an "atypical" object file which
121
276
// has section headers right after the ELF header (instead of the more common
122
277
// layout where the section headers are at the very end of the object file).
0 commit comments