@@ -55,6 +55,7 @@ class ELFDumper {
55
55
std::vector<ELFYAML::Symbol> &Symbols);
56
56
Error dumpSymbol (const Elf_Sym *Sym, const Elf_Shdr *SymTab,
57
57
StringRef StrTable, ELFYAML::Symbol &S);
58
+ Expected<std::vector<std::unique_ptr<ELFYAML::Chunk>>> dumpSections ();
58
59
Error dumpCommonSection (const Elf_Shdr *Shdr, ELFYAML::Section &S);
59
60
Error dumpCommonRelocationSection (const Elf_Shdr *Shdr,
60
61
ELFYAML::RelocationSection &S);
@@ -228,13 +229,27 @@ template <class ELFT> Expected<ELFYAML::Object *> ELFDumper<ELFT>::dump() {
228
229
return std::move (E);
229
230
}
230
231
232
+ if (Expected<std::vector<std::unique_ptr<ELFYAML::Chunk>>> ChunksOrErr =
233
+ dumpSections ())
234
+ Y->Chunks = std::move (*ChunksOrErr);
235
+ else
236
+ return ChunksOrErr.takeError ();
237
+
238
+ return Y.release ();
239
+ }
240
+
241
+ template <class ELFT >
242
+ Expected<std::vector<std::unique_ptr<ELFYAML::Chunk>>>
243
+ ELFDumper<ELFT>::dumpSections() {
244
+ std::vector<std::unique_ptr<ELFYAML::Chunk>> Ret;
245
+
231
246
for (const Elf_Shdr &Sec : Sections) {
232
247
switch (Sec.sh_type ) {
233
248
case ELF::SHT_DYNAMIC: {
234
249
Expected<ELFYAML::DynamicSection *> SecOrErr = dumpDynamicSection (&Sec);
235
250
if (!SecOrErr)
236
251
return SecOrErr.takeError ();
237
- Y-> Chunks .emplace_back (*SecOrErr);
252
+ Ret .emplace_back (*SecOrErr);
238
253
break ;
239
254
}
240
255
case ELF::SHT_STRTAB:
@@ -247,116 +262,116 @@ template <class ELFT> Expected<ELFYAML::Object *> ELFDumper<ELFT>::dump() {
247
262
dumpSymtabShndxSection (&Sec);
248
263
if (!SecOrErr)
249
264
return SecOrErr.takeError ();
250
- Y-> Chunks .emplace_back (*SecOrErr);
265
+ Ret .emplace_back (*SecOrErr);
251
266
break ;
252
267
}
253
268
case ELF::SHT_REL:
254
269
case ELF::SHT_RELA: {
255
270
Expected<ELFYAML::RelocationSection *> SecOrErr = dumpRelocSection (&Sec);
256
271
if (!SecOrErr)
257
272
return SecOrErr.takeError ();
258
- Y-> Chunks .emplace_back (*SecOrErr);
273
+ Ret .emplace_back (*SecOrErr);
259
274
break ;
260
275
}
261
276
case ELF::SHT_RELR: {
262
277
Expected<ELFYAML::RelrSection *> SecOrErr = dumpRelrSection (&Sec);
263
278
if (!SecOrErr)
264
279
return SecOrErr.takeError ();
265
- Y-> Chunks .emplace_back (*SecOrErr);
280
+ Ret .emplace_back (*SecOrErr);
266
281
break ;
267
282
}
268
283
case ELF::SHT_GROUP: {
269
284
Expected<ELFYAML::Group *> GroupOrErr = dumpGroup (&Sec);
270
285
if (!GroupOrErr)
271
286
return GroupOrErr.takeError ();
272
- Y-> Chunks .emplace_back (*GroupOrErr);
287
+ Ret .emplace_back (*GroupOrErr);
273
288
break ;
274
289
}
275
290
case ELF::SHT_MIPS_ABIFLAGS: {
276
291
Expected<ELFYAML::MipsABIFlags *> SecOrErr = dumpMipsABIFlags (&Sec);
277
292
if (!SecOrErr)
278
293
return SecOrErr.takeError ();
279
- Y-> Chunks .emplace_back (*SecOrErr);
294
+ Ret .emplace_back (*SecOrErr);
280
295
break ;
281
296
}
282
297
case ELF::SHT_NOBITS: {
283
298
Expected<ELFYAML::NoBitsSection *> SecOrErr = dumpNoBitsSection (&Sec);
284
299
if (!SecOrErr)
285
300
return SecOrErr.takeError ();
286
- Y-> Chunks .emplace_back (*SecOrErr);
301
+ Ret .emplace_back (*SecOrErr);
287
302
break ;
288
303
}
289
304
case ELF::SHT_NOTE: {
290
305
Expected<ELFYAML::NoteSection *> SecOrErr = dumpNoteSection (&Sec);
291
306
if (!SecOrErr)
292
307
return SecOrErr.takeError ();
293
- Y-> Chunks .emplace_back (*SecOrErr);
308
+ Ret .emplace_back (*SecOrErr);
294
309
break ;
295
310
}
296
311
case ELF::SHT_HASH: {
297
312
Expected<ELFYAML::HashSection *> SecOrErr = dumpHashSection (&Sec);
298
313
if (!SecOrErr)
299
314
return SecOrErr.takeError ();
300
- Y-> Chunks .emplace_back (*SecOrErr);
315
+ Ret .emplace_back (*SecOrErr);
301
316
break ;
302
317
}
303
318
case ELF::SHT_GNU_HASH: {
304
319
Expected<ELFYAML::GnuHashSection *> SecOrErr = dumpGnuHashSection (&Sec);
305
320
if (!SecOrErr)
306
321
return SecOrErr.takeError ();
307
- Y-> Chunks .emplace_back (*SecOrErr);
322
+ Ret .emplace_back (*SecOrErr);
308
323
break ;
309
324
}
310
325
case ELF::SHT_GNU_verdef: {
311
326
Expected<ELFYAML::VerdefSection *> SecOrErr = dumpVerdefSection (&Sec);
312
327
if (!SecOrErr)
313
328
return SecOrErr.takeError ();
314
- Y-> Chunks .emplace_back (*SecOrErr);
329
+ Ret .emplace_back (*SecOrErr);
315
330
break ;
316
331
}
317
332
case ELF::SHT_GNU_versym: {
318
333
Expected<ELFYAML::SymverSection *> SecOrErr = dumpSymverSection (&Sec);
319
334
if (!SecOrErr)
320
335
return SecOrErr.takeError ();
321
- Y-> Chunks .emplace_back (*SecOrErr);
336
+ Ret .emplace_back (*SecOrErr);
322
337
break ;
323
338
}
324
339
case ELF::SHT_GNU_verneed: {
325
340
Expected<ELFYAML::VerneedSection *> SecOrErr = dumpVerneedSection (&Sec);
326
341
if (!SecOrErr)
327
342
return SecOrErr.takeError ();
328
- Y-> Chunks .emplace_back (*SecOrErr);
343
+ Ret .emplace_back (*SecOrErr);
329
344
break ;
330
345
}
331
346
case ELF::SHT_LLVM_ADDRSIG: {
332
347
Expected<ELFYAML::AddrsigSection *> SecOrErr = dumpAddrsigSection (&Sec);
333
348
if (!SecOrErr)
334
349
return SecOrErr.takeError ();
335
- Y-> Chunks .emplace_back (*SecOrErr);
350
+ Ret .emplace_back (*SecOrErr);
336
351
break ;
337
352
}
338
353
case ELF::SHT_LLVM_LINKER_OPTIONS: {
339
354
Expected<ELFYAML::LinkerOptionsSection *> SecOrErr =
340
355
dumpLinkerOptionsSection (&Sec);
341
356
if (!SecOrErr)
342
357
return SecOrErr.takeError ();
343
- Y-> Chunks .emplace_back (*SecOrErr);
358
+ Ret .emplace_back (*SecOrErr);
344
359
break ;
345
360
}
346
361
case ELF::SHT_LLVM_DEPENDENT_LIBRARIES: {
347
362
Expected<ELFYAML::DependentLibrariesSection *> SecOrErr =
348
363
dumpDependentLibrariesSection (&Sec);
349
364
if (!SecOrErr)
350
365
return SecOrErr.takeError ();
351
- Y-> Chunks .emplace_back (*SecOrErr);
366
+ Ret .emplace_back (*SecOrErr);
352
367
break ;
353
368
}
354
369
case ELF::SHT_LLVM_CALL_GRAPH_PROFILE: {
355
370
Expected<ELFYAML::CallGraphProfileSection *> SecOrErr =
356
371
dumpCallGraphProfileSection (&Sec);
357
372
if (!SecOrErr)
358
373
return SecOrErr.takeError ();
359
- Y-> Chunks .emplace_back (*SecOrErr);
374
+ Ret .emplace_back (*SecOrErr);
360
375
break ;
361
376
}
362
377
case ELF::SHT_NULL: {
@@ -378,7 +393,7 @@ template <class ELFT> Expected<ELFYAML::Object *> ELFDumper<ELFT>::dump() {
378
393
if (!SpecialSecOrErr)
379
394
return SpecialSecOrErr.takeError ();
380
395
if (*SpecialSecOrErr) {
381
- Y-> Chunks .emplace_back (*SpecialSecOrErr);
396
+ Ret .emplace_back (*SpecialSecOrErr);
382
397
break ;
383
398
}
384
399
}
@@ -387,12 +402,11 @@ template <class ELFT> Expected<ELFYAML::Object *> ELFDumper<ELFT>::dump() {
387
402
dumpContentSection (&Sec);
388
403
if (!SecOrErr)
389
404
return SecOrErr.takeError ();
390
- Y-> Chunks .emplace_back (*SecOrErr);
405
+ Ret .emplace_back (*SecOrErr);
391
406
}
392
407
}
393
408
}
394
-
395
- return Y.release ();
409
+ return std::move (Ret);
396
410
}
397
411
398
412
template <class ELFT >
0 commit comments