[llvm] r219458 - obj2yaml, COFF: Handle long section names

David Majnemer david.majnemer at gmail.com
Thu Oct 9 17:17:58 PDT 2014


Author: majnemer
Date: Thu Oct  9 19:17:57 2014
New Revision: 219458

URL: http://llvm.org/viewvc/llvm-project?rev=219458&view=rev
Log:
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.

Added:
    llvm/trunk/test/Object/Inputs/COFF/long-section-name.yaml
    llvm/trunk/test/Object/obj2yaml-coff-long-section-name.test
Modified:
    llvm/trunk/tools/obj2yaml/coff2yaml.cpp

Added: llvm/trunk/test/Object/Inputs/COFF/long-section-name.yaml
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Object/Inputs/COFF/long-section-name.yaml?rev=219458&view=auto
==============================================================================
--- llvm/trunk/test/Object/Inputs/COFF/long-section-name.yaml (added)
+++ llvm/trunk/test/Object/Inputs/COFF/long-section-name.yaml Thu Oct  9 19:17:57 2014
@@ -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:
+...

Added: llvm/trunk/test/Object/obj2yaml-coff-long-section-name.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Object/obj2yaml-coff-long-section-name.test?rev=219458&view=auto
==============================================================================
--- llvm/trunk/test/Object/obj2yaml-coff-long-section-name.test (added)
+++ llvm/trunk/test/Object/obj2yaml-coff-long-section-name.test Thu Oct  9 19:17:57 2014
@@ -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

Modified: llvm/trunk/tools/obj2yaml/coff2yaml.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/obj2yaml/coff2yaml.cpp?rev=219458&r1=219457&r2=219458&view=diff
==============================================================================
--- llvm/trunk/tools/obj2yaml/coff2yaml.cpp (original)
+++ llvm/trunk/tools/obj2yaml/coff2yaml.cpp Thu Oct  9 19:17:57 2014
@@ -47,13 +47,13 @@ void COFFDumper::dumpSections(unsigned N
   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<uint8_t> sectionData;
-    Obj.getSectionContents(Sect, sectionData);
+    if (!Section.isBSS())
+      Obj.getSectionContents(Sect, sectionData);
     Sec.SectionData = yaml::BinaryRef(sectionData);
 
     std::vector<COFFYAML::Relocation> Relocations;





More information about the llvm-commits mailing list