obj2yaml: Correctly round-trip default alignment.
authorPeter Collingbourne <peter@pcc.me.uk>
Fri, 4 May 2018 16:28:41 +0000 (16:28 +0000)
committerPeter Collingbourne <peter@pcc.me.uk>
Fri, 4 May 2018 16:28:41 +0000 (16:28 +0000)
Previously we were emitting the "cooked" alignment, which made it hard
to distinguish between that and the default alignment.

Differential Revision: https://reviews.llvm.org/D46418

llvm-svn: 331537

llvm/test/ObjectYAML/COFF/default-alignment.yaml [new file with mode: 0644]
llvm/tools/obj2yaml/coff2yaml.cpp

diff --git a/llvm/test/ObjectYAML/COFF/default-alignment.yaml b/llvm/test/ObjectYAML/COFF/default-alignment.yaml
new file mode 100644 (file)
index 0000000..d561521
--- /dev/null
@@ -0,0 +1,15 @@
+# RUN: yaml2obj %s | obj2yaml | FileCheck %s
+
+# CHECK:      Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ ]
+# CHECK-NEXT: SectionData:     '01'
+
+--- !COFF
+header:
+  Machine:         IMAGE_FILE_MACHINE_AMD64
+  Characteristics: []
+sections:
+  - Name:            .rdata
+    Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ ]
+    SectionData:     01
+symbols:
+...
index 1c59c5c35efe055a5dba2c28d4dab60ea4155573..e7e9e19fd3dc1b95c33155a8112b4676b32d9b5a 100644 (file)
@@ -159,7 +159,8 @@ void COFFDumper::dumpSections(unsigned NumSections) {
     NewYAMLSection.Header.PointerToRelocations =
         COFFSection->PointerToRelocations;
     NewYAMLSection.Header.SizeOfRawData = COFFSection->SizeOfRawData;
-    NewYAMLSection.Alignment = ObjSection.getAlignment();
+    uint32_t Shift = (COFFSection->Characteristics >> 20) & 0xF;
+    NewYAMLSection.Alignment = (1U << Shift) >> 1;
     assert(NewYAMLSection.Alignment <= 8192);
 
     ArrayRef<uint8_t> sectionData;