From bc90fd09e09a845ae6ea0d84ad67560575a94142 Mon Sep 17 00:00:00 2001 From: David Srbecky Date: Wed, 22 Apr 2015 19:40:27 +0100 Subject: Major refactoring of ElfBuilder. Simplify ElfBuilder by removing duplicated or redundant code. Many of the repeated code patterns were replaced by just looping over the list of all sections. Methods Init() and Write() have been merged into one. The split between those was rather arbitrary, but it was there for a reason. It allowed creation of raw sections between the calls which may have depended on layout decisions done in Init(), but not in Write() (e.g. knowing of offset of .text). This has been replaced by more generic solution. All sections are asked about their size first and complete file layout is calculated. Then the sections are asked to write their content (potentially using the layout information). This should be pure refactoring CL - the compiler should produce bit for bit identical output as before. Change-Id: I281d13d469801bd8288b36b360d200d98a3e92d7 --- compiler/dwarf/dwarf_test.h | 43 ++++++++++++++++++++----------------------- 1 file changed, 20 insertions(+), 23 deletions(-) (limited to 'compiler/dwarf/dwarf_test.h') diff --git a/compiler/dwarf/dwarf_test.h b/compiler/dwarf/dwarf_test.h index 022fac27e1..230ebe3a79 100644 --- a/compiler/dwarf/dwarf_test.h +++ b/compiler/dwarf/dwarf_test.h @@ -57,44 +57,41 @@ class DwarfTest : public CommonRuntimeTest { // Pretty-print the generated DWARF data using objdump. template - std::vector Objdump(bool is64bit, const char* args) { + std::vector Objdump(const char* args) { // Write simple elf file with just the DWARF sections. + InstructionSet isa = (sizeof(typename ElfTypes::Addr) == 8) ? kX86_64 : kX86; class NoCode : public CodeOutput { - virtual void SetCodeOffset(size_t) { } - virtual bool Write(OutputStream*) { return true; } - } code; - ScratchFile file; - InstructionSet isa = is64bit ? kX86_64 : kX86; - ElfBuilder builder( - &code, file.GetFile(), isa, 0, 0, 0, 0, 0, 0, false, false); - typedef typename ElfBuilder::ElfRawSectionBuilder Section; - Section debug_info(".debug_info", SHT_PROGBITS, 0, nullptr, 0, 1, 0); - Section debug_abbrev(".debug_abbrev", SHT_PROGBITS, 0, nullptr, 0, 1, 0); - Section debug_str(".debug_str", SHT_PROGBITS, 0, nullptr, 0, 1, 0); - Section debug_line(".debug_line", SHT_PROGBITS, 0, nullptr, 0, 1, 0); - Section eh_frame(".eh_frame", SHT_PROGBITS, SHF_ALLOC, nullptr, 0, 4, 0); + bool Write(OutputStream*) OVERRIDE { return true; } // NOLINT + } no_code; + ElfBuilder builder(isa, 0, &no_code, 0, &no_code, 0); + typedef typename ElfBuilder::RawSection RawSection; + RawSection debug_info(".debug_info", SHT_PROGBITS, 0, nullptr, 0, 1, 0); + RawSection debug_abbrev(".debug_abbrev", SHT_PROGBITS, 0, nullptr, 0, 1, 0); + RawSection debug_str(".debug_str", SHT_PROGBITS, 0, nullptr, 0, 1, 0); + RawSection debug_line(".debug_line", SHT_PROGBITS, 0, nullptr, 0, 1, 0); + RawSection eh_frame(".eh_frame", SHT_PROGBITS, SHF_ALLOC, nullptr, 0, kPageSize, 0); if (!debug_info_data_.empty()) { debug_info.SetBuffer(debug_info_data_); - builder.RegisterRawSection(&debug_info); + builder.RegisterSection(&debug_info); } if (!debug_abbrev_data_.empty()) { debug_abbrev.SetBuffer(debug_abbrev_data_); - builder.RegisterRawSection(&debug_abbrev); + builder.RegisterSection(&debug_abbrev); } if (!debug_str_data_.empty()) { debug_str.SetBuffer(debug_str_data_); - builder.RegisterRawSection(&debug_str); + builder.RegisterSection(&debug_str); } if (!debug_line_data_.empty()) { debug_line.SetBuffer(debug_line_data_); - builder.RegisterRawSection(&debug_line); + builder.RegisterSection(&debug_line); } if (!eh_frame_data_.empty()) { eh_frame.SetBuffer(eh_frame_data_); - builder.RegisterRawSection(&eh_frame); + builder.RegisterSection(&eh_frame); } - builder.Init(); - builder.Write(); + ScratchFile file; + builder.Write(file.GetFile()); // Read the elf file back using objdump. std::vector lines; @@ -123,9 +120,9 @@ class DwarfTest : public CommonRuntimeTest { std::vector Objdump(bool is64bit, const char* args) { if (is64bit) { - return Objdump(is64bit, args); + return Objdump(args); } else { - return Objdump(is64bit, args); + return Objdump(args); } } -- cgit v1.2.3-59-g8ed1b