@@ -55,6 +55,7 @@ class ELFDumper {
5555 std::vector<ELFYAML::Symbol> &Symbols);
5656 Error dumpSymbol (const Elf_Sym *Sym, const Elf_Shdr *SymTab,
5757 StringRef StrTable, ELFYAML::Symbol &S);
58+ Expected<std::vector<std::unique_ptr<ELFYAML::Chunk>>> dumpSections ();
5859 Error dumpCommonSection (const Elf_Shdr *Shdr, ELFYAML::Section &S);
5960 Error dumpCommonRelocationSection (const Elf_Shdr *Shdr,
6061 ELFYAML::RelocationSection &S);
@@ -228,13 +229,27 @@ template <class ELFT> Expected<ELFYAML::Object *> ELFDumper<ELFT>::dump() {
228229 return std::move (E);
229230 }
230231
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+
231246 for (const Elf_Shdr &Sec : Sections) {
232247 switch (Sec.sh_type ) {
233248 case ELF::SHT_DYNAMIC: {
234249 Expected<ELFYAML::DynamicSection *> SecOrErr = dumpDynamicSection (&Sec);
235250 if (!SecOrErr)
236251 return SecOrErr.takeError ();
237- Y-> Chunks .emplace_back (*SecOrErr);
252+ Ret .emplace_back (*SecOrErr);
238253 break ;
239254 }
240255 case ELF::SHT_STRTAB:
@@ -247,116 +262,116 @@ template <class ELFT> Expected<ELFYAML::Object *> ELFDumper<ELFT>::dump() {
247262 dumpSymtabShndxSection (&Sec);
248263 if (!SecOrErr)
249264 return SecOrErr.takeError ();
250- Y-> Chunks .emplace_back (*SecOrErr);
265+ Ret .emplace_back (*SecOrErr);
251266 break ;
252267 }
253268 case ELF::SHT_REL:
254269 case ELF::SHT_RELA: {
255270 Expected<ELFYAML::RelocationSection *> SecOrErr = dumpRelocSection (&Sec);
256271 if (!SecOrErr)
257272 return SecOrErr.takeError ();
258- Y-> Chunks .emplace_back (*SecOrErr);
273+ Ret .emplace_back (*SecOrErr);
259274 break ;
260275 }
261276 case ELF::SHT_RELR: {
262277 Expected<ELFYAML::RelrSection *> SecOrErr = dumpRelrSection (&Sec);
263278 if (!SecOrErr)
264279 return SecOrErr.takeError ();
265- Y-> Chunks .emplace_back (*SecOrErr);
280+ Ret .emplace_back (*SecOrErr);
266281 break ;
267282 }
268283 case ELF::SHT_GROUP: {
269284 Expected<ELFYAML::Group *> GroupOrErr = dumpGroup (&Sec);
270285 if (!GroupOrErr)
271286 return GroupOrErr.takeError ();
272- Y-> Chunks .emplace_back (*GroupOrErr);
287+ Ret .emplace_back (*GroupOrErr);
273288 break ;
274289 }
275290 case ELF::SHT_MIPS_ABIFLAGS: {
276291 Expected<ELFYAML::MipsABIFlags *> SecOrErr = dumpMipsABIFlags (&Sec);
277292 if (!SecOrErr)
278293 return SecOrErr.takeError ();
279- Y-> Chunks .emplace_back (*SecOrErr);
294+ Ret .emplace_back (*SecOrErr);
280295 break ;
281296 }
282297 case ELF::SHT_NOBITS: {
283298 Expected<ELFYAML::NoBitsSection *> SecOrErr = dumpNoBitsSection (&Sec);
284299 if (!SecOrErr)
285300 return SecOrErr.takeError ();
286- Y-> Chunks .emplace_back (*SecOrErr);
301+ Ret .emplace_back (*SecOrErr);
287302 break ;
288303 }
289304 case ELF::SHT_NOTE: {
290305 Expected<ELFYAML::NoteSection *> SecOrErr = dumpNoteSection (&Sec);
291306 if (!SecOrErr)
292307 return SecOrErr.takeError ();
293- Y-> Chunks .emplace_back (*SecOrErr);
308+ Ret .emplace_back (*SecOrErr);
294309 break ;
295310 }
296311 case ELF::SHT_HASH: {
297312 Expected<ELFYAML::HashSection *> SecOrErr = dumpHashSection (&Sec);
298313 if (!SecOrErr)
299314 return SecOrErr.takeError ();
300- Y-> Chunks .emplace_back (*SecOrErr);
315+ Ret .emplace_back (*SecOrErr);
301316 break ;
302317 }
303318 case ELF::SHT_GNU_HASH: {
304319 Expected<ELFYAML::GnuHashSection *> SecOrErr = dumpGnuHashSection (&Sec);
305320 if (!SecOrErr)
306321 return SecOrErr.takeError ();
307- Y-> Chunks .emplace_back (*SecOrErr);
322+ Ret .emplace_back (*SecOrErr);
308323 break ;
309324 }
310325 case ELF::SHT_GNU_verdef: {
311326 Expected<ELFYAML::VerdefSection *> SecOrErr = dumpVerdefSection (&Sec);
312327 if (!SecOrErr)
313328 return SecOrErr.takeError ();
314- Y-> Chunks .emplace_back (*SecOrErr);
329+ Ret .emplace_back (*SecOrErr);
315330 break ;
316331 }
317332 case ELF::SHT_GNU_versym: {
318333 Expected<ELFYAML::SymverSection *> SecOrErr = dumpSymverSection (&Sec);
319334 if (!SecOrErr)
320335 return SecOrErr.takeError ();
321- Y-> Chunks .emplace_back (*SecOrErr);
336+ Ret .emplace_back (*SecOrErr);
322337 break ;
323338 }
324339 case ELF::SHT_GNU_verneed: {
325340 Expected<ELFYAML::VerneedSection *> SecOrErr = dumpVerneedSection (&Sec);
326341 if (!SecOrErr)
327342 return SecOrErr.takeError ();
328- Y-> Chunks .emplace_back (*SecOrErr);
343+ Ret .emplace_back (*SecOrErr);
329344 break ;
330345 }
331346 case ELF::SHT_LLVM_ADDRSIG: {
332347 Expected<ELFYAML::AddrsigSection *> SecOrErr = dumpAddrsigSection (&Sec);
333348 if (!SecOrErr)
334349 return SecOrErr.takeError ();
335- Y-> Chunks .emplace_back (*SecOrErr);
350+ Ret .emplace_back (*SecOrErr);
336351 break ;
337352 }
338353 case ELF::SHT_LLVM_LINKER_OPTIONS: {
339354 Expected<ELFYAML::LinkerOptionsSection *> SecOrErr =
340355 dumpLinkerOptionsSection (&Sec);
341356 if (!SecOrErr)
342357 return SecOrErr.takeError ();
343- Y-> Chunks .emplace_back (*SecOrErr);
358+ Ret .emplace_back (*SecOrErr);
344359 break ;
345360 }
346361 case ELF::SHT_LLVM_DEPENDENT_LIBRARIES: {
347362 Expected<ELFYAML::DependentLibrariesSection *> SecOrErr =
348363 dumpDependentLibrariesSection (&Sec);
349364 if (!SecOrErr)
350365 return SecOrErr.takeError ();
351- Y-> Chunks .emplace_back (*SecOrErr);
366+ Ret .emplace_back (*SecOrErr);
352367 break ;
353368 }
354369 case ELF::SHT_LLVM_CALL_GRAPH_PROFILE: {
355370 Expected<ELFYAML::CallGraphProfileSection *> SecOrErr =
356371 dumpCallGraphProfileSection (&Sec);
357372 if (!SecOrErr)
358373 return SecOrErr.takeError ();
359- Y-> Chunks .emplace_back (*SecOrErr);
374+ Ret .emplace_back (*SecOrErr);
360375 break ;
361376 }
362377 case ELF::SHT_NULL: {
@@ -378,7 +393,7 @@ template <class ELFT> Expected<ELFYAML::Object *> ELFDumper<ELFT>::dump() {
378393 if (!SpecialSecOrErr)
379394 return SpecialSecOrErr.takeError ();
380395 if (*SpecialSecOrErr) {
381- Y-> Chunks .emplace_back (*SpecialSecOrErr);
396+ Ret .emplace_back (*SpecialSecOrErr);
382397 break ;
383398 }
384399 }
@@ -387,12 +402,11 @@ template <class ELFT> Expected<ELFYAML::Object *> ELFDumper<ELFT>::dump() {
387402 dumpContentSection (&Sec);
388403 if (!SecOrErr)
389404 return SecOrErr.takeError ();
390- Y-> Chunks .emplace_back (*SecOrErr);
405+ Ret .emplace_back (*SecOrErr);
391406 }
392407 }
393408 }
394-
395- return Y.release ();
409+ return std::move (Ret);
396410}
397411
398412template <class ELFT >
0 commit comments