From: David Majnemer Date: Fri, 10 Oct 2014 00:17:57 +0000 (+0000) Subject: obj2yaml, COFF: Handle long section names X-Git-Url: http://plrg.eecs.uci.edu/git/?p=oota-llvm.git;a=commitdiff_plain;h=54a3b749e19968fadbbdf021bf9c1b2d3affa04a obj2yaml, COFF: Handle long section names Long section names are represented as a slash followed by a numeric ASCII string. This number is an offset into a string table. Print the appropriate entry in the string table instead of the less enlightening /4. N.B. yaml2obj already does the right thing, this test exercises both sides of the (de-)serialization. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@219458 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/test/Object/Inputs/COFF/long-section-name.yaml b/test/Object/Inputs/COFF/long-section-name.yaml new file mode 100644 index 00000000000..a86f9019cd5 --- /dev/null +++ b/test/Object/Inputs/COFF/long-section-name.yaml @@ -0,0 +1,11 @@ +--- +header: + Machine: IMAGE_FILE_MACHINE_I386 + Characteristics: [ IMAGE_FILE_RELOCS_STRIPPED, IMAGE_FILE_LINE_NUMS_STRIPPED, IMAGE_FILE_LOCAL_SYMS_STRIPPED, IMAGE_FILE_32BIT_MACHINE ] +sections: + - Name: .long_section_name + Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ ] + Alignment: 1 + SectionData: '' +symbols: +... diff --git a/test/Object/obj2yaml-coff-long-section-name.test b/test/Object/obj2yaml-coff-long-section-name.test new file mode 100644 index 00000000000..5457aef28c5 --- /dev/null +++ b/test/Object/obj2yaml-coff-long-section-name.test @@ -0,0 +1,3 @@ +RUN: yaml2obj %p/Inputs/COFF/long-section-name.yaml | obj2yaml | FileCheck %s --check-prefix COFF-I386 + +COFF-I386: Name: .long_section_name diff --git a/tools/obj2yaml/coff2yaml.cpp b/tools/obj2yaml/coff2yaml.cpp index e22aff76071..05d30f3fb62 100644 --- a/tools/obj2yaml/coff2yaml.cpp +++ b/tools/obj2yaml/coff2yaml.cpp @@ -47,13 +47,13 @@ void COFFDumper::dumpSections(unsigned NumSections) { for (const auto &Section : Obj.sections()) { const object::coff_section *Sect = Obj.getCOFFSection(Section); COFFYAML::Section Sec; - Sec.Name = Sect->Name; // FIXME: check the null termination! - uint32_t Characteristics = Sect->Characteristics; - Sec.Header.Characteristics = Characteristics; - Sec.Alignment = 1 << (((Characteristics >> 20) & 0xf) - 1); + Section.getName(Sec.Name); + Sec.Header.Characteristics = Sect->Characteristics; + Sec.Alignment = Section.getAlignment(); ArrayRef sectionData; - Obj.getSectionContents(Sect, sectionData); + if (!Section.isBSS()) + Obj.getSectionContents(Sect, sectionData); Sec.SectionData = yaml::BinaryRef(sectionData); std::vector Relocations;