[PATCH] D44986: Initialize Elf header and Program Header to Zero

Rumeet Dhindsa via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 28 15:40:12 PDT 2018


rdhindsa updated this revision to Diff 140150.

https://reviews.llvm.org/D44986

Files:
  lld/ELF/Writer.cpp
  lld/test/ELF/elf-header-initialized.s


Index: lld/test/ELF/elf-header-initialized.s
===================================================================
--- /dev/null
+++ lld/test/ELF/elf-header-initialized.s
@@ -0,0 +1,18 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
+# RUN: ld.lld %t.o -o %t1
+# RUN: llvm-readobj -file-headers -r %t1 | FileCheck %s
+
+# RUN: ld.lld %t.o -no-rosegment -o %t2
+# RUN: llvm-readobj -file-headers -r %t2 | FileCheck %s
+
+# CHECK:      ElfHeader {
+# CHECK-NEXT:   Ident {
+# CHECK-NEXT:     Magic: (7F 45 4C 46)
+# CHECK-NEXT:     Class: 64-bit (0x2)
+# CHECK-NEXT:     DataEncoding: LittleEndian (0x1)
+# CHECK-NEXT:     FileVersion: 1
+# CHECK-NEXT:     OS/ABI: SystemV (0x0)
+# CHECK-NEXT:     ABIVersion: 0
+# CHECK-NEXT:     Unused: (00 00 00 00 00 00 00)
+# CHECK-NEXT:   }
Index: lld/ELF/Writer.cpp
===================================================================
--- lld/ELF/Writer.cpp
+++ lld/ELF/Writer.cpp
@@ -2108,6 +2108,7 @@
 
 template <class ELFT> void Writer<ELFT>::writeHeader() {
   uint8_t *Buf = Buffer->getBufferStart();
+  memset(Buf, 0, sizeof(Elf_Ehdr));
   memcpy(Buf, "\177ELF", 4);
 
   // Write the ELF header.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D44986.140150.patch
Type: text/x-patch
Size: 1177 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180328/b7f38474/attachment.bin>


More information about the llvm-commits mailing list