]> granicus.if.org Git - llvm/commitdiff
[llvm-mc] - Properly set the the address align field of the compressed sections.
authorGeorge Rimar <grimar@accesssoftek.com>
Tue, 23 Apr 2019 09:16:53 +0000 (09:16 +0000)
committerGeorge Rimar <grimar@accesssoftek.com>
Tue, 23 Apr 2019 09:16:53 +0000 (09:16 +0000)
About the compressed sections spec says:
(https://docs.oracle.com/cd/E37838_01/html/E36783/section_compression.html)
sh_addralign fields of the section header for a compressed section
reflect the requirements of the compressed section.

Currently, llvm-mc always puts uncompressed section alignment to sh_addralign.
It is not correct. zlib styled section contains an Elfxx_Chdr header,
so we should either use 4 or 8 values depending on the target
(Uncompressed section alignment is stored in ch_addralign field of the compression header).

GNU assembler version 2.31.1 also has this issue,
but in 2.32.51 it was already fixed. This is how it was found
during debugging of the https://bugs.llvm.org/show_bug.cgi?id=40482
actually.

Differential revision: https://reviews.llvm.org/D60965

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358960 91177308-0d34-0410-b5e6-96231b3b80d8

lib/MC/ELFObjectWriter.cpp
test/MC/ELF/compression.s

index 1d4f3afe2ea26664748d56f8e214820486c3fbfe..96bbc2ee630c2904d140e41e09dab19645d173d2 100644 (file)
@@ -886,12 +886,16 @@ void ELFWriter::writeSectionData(const MCAssembler &Asm, MCSection &Sec,
     return;
   }
 
-  if (ZlibStyle)
+  if (ZlibStyle) {
     // Set the compressed flag. That is zlib style.
     Section.setFlags(Section.getFlags() | ELF::SHF_COMPRESSED);
-  else
+    // Alignment field should reflect the requirements of
+    // the compressed section header.
+    Section.setAlignment(is64Bit() ? 8 : 4);
+  } else {
     // Add "z" prefix to section name. This is zlib-gnu style.
     MC.renameELFSection(&Section, (".z" + SectionName.drop_front(1)).str());
+  }
   W.OS << CompressedContents;
 }
 
index 517112e31e6a3e8dc48130907745346b83e9b4d8..fddc4d28e571babd901358a360a44de3aedb2ffb 100644 (file)
 // RUN: llvm-mc -filetype=obj -compress-debug-sections=zlib -triple x86_64-pc-linux-gnu < %s -o %t
 // RUN: llvm-objdump -s %t | FileCheck --check-prefix=CHECK-ZLIB-STYLE %s
 // RUN: llvm-dwarfdump -debug-str %t | FileCheck --check-prefix=STR %s
-// RUN: llvm-mc -filetype=obj -compress-debug-sections=zlib -triple i386-pc-linux-gnu < %s \
-// RUN:     | llvm-readobj -symbols - | FileCheck --check-prefix=386-SYMBOLS-ZLIB %s
-// RUN: llvm-readobj -sections %t | FileCheck --check-prefix=ZLIB-STYLE-FLAGS %s
+// RUN: llvm-readobj -sections %t | FileCheck --check-prefixes=ZLIB-STYLE-FLAGS,ZLIB-STYLE-FLAGS64 %s
+
+// RUN: llvm-mc -filetype=obj -compress-debug-sections=zlib -triple i386-pc-linux-gnu < %s -o %t
+// RUN: llvm-readobj -symbols -sections %t \
+// RUN:   | FileCheck --check-prefixes=386-SYMBOLS-ZLIB,ZLIB-STYLE-FLAGS,ZLIB-STYLE-FLAGS32 %s
 
 // Don't compress small sections, such as this simple debug_abbrev example
 // CHECK-GNU-STYLE: Contents of section .debug_abbrev:
 // ZLIB-STYLE-FLAGS-NEXT:   Type: SHT_PROGBITS
 // ZLIB-STYLE-FLAGS-NEXT:   Flags [
 // ZLIB-STYLE-FLAGS-NEXT:     SHF_COMPRESSED
+// ZLIB-STYLE-FLAGS-NEXT:     SHF_MERGE
+// ZLIB-STYLE-FLAGS-NEXT:     SHF_STRINGS
+// ZLIB-STYLE-FLAGS-NEXT:   ]
+// ZLIB-STYLE-FLAGS-NEXT:   Address:
+// ZLIB-STYLE-FLAGS-NEXT:   Offset:
+// ZLIB-STYLE-FLAGS-NEXT:   Size:
+// ZLIB-STYLE-FLAGS-NEXT:   Link:
+// ZLIB-STYLE-FLAGS-NEXT:   Info:
+// ZLIB-STYLE-FLAGS32-NEXT: AddressAlignment: 4
+// ZLIB-STYLE-FLAGS64-NEXT: AddressAlignment: 8
 
 // 386-SYMBOLS-ZLIB: Name: .Linfo_string0
 // 386-SYMBOLS-ZLIB-NOT: }