[lld] r328902 - Initialize Elf Header to zero to ensure that bytes not assigned any value later on are initialized properly.
Rumeet Dhindsa via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 30 13:49:34 PDT 2018
Author: rdhindsa
Date: Fri Mar 30 13:49:34 2018
New Revision: 328902
URL: http://llvm.org/viewvc/llvm-project?rev=328902&view=rev
Log:
Initialize Elf Header to zero to ensure that bytes not assigned any value later on are initialized properly.
Differential Revision: https://reviews.llvm.org/D44986
Added:
lld/trunk/test/ELF/elf-header.s
Modified:
lld/trunk/ELF/Writer.cpp
Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=328902&r1=328901&r2=328902&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Fri Mar 30 13:49:34 2018
@@ -2092,6 +2092,10 @@ static uint8_t getAbiVersion() {
template <class ELFT> void Writer<ELFT>::writeHeader() {
uint8_t *Buf = Buffer->getBufferStart();
+ // For executable segments, the trap instructions are written before writing
+ // the header. Setting Elf header bytes to zero ensures that any unused bytes
+ // in header are zero-cleared, instead of having trap instructions.
+ memset(Buf, 0, sizeof(Elf_Ehdr));
memcpy(Buf, "\177ELF", 4);
// Write the ELF header.
Added: lld/trunk/test/ELF/elf-header.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/elf-header.s?rev=328902&view=auto
==============================================================================
--- lld/trunk/test/ELF/elf-header.s (added)
+++ lld/trunk/test/ELF/elf-header.s Fri Mar 30 13:49:34 2018
@@ -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 %t1 | FileCheck %s
+
+# RUN: ld.lld %t.o -no-rosegment -o %t2
+# RUN: llvm-readobj -file-headers %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: }
More information about the llvm-commits
mailing list