Skip to content

Commit f7ef2a1

Browse files
author
George Rimar
committedAug 21, 2017
[ELF] - Recommit "[ELF] - Do not forget to fill last bytes of PT_LOADs with trap instructions."
With fix: explicitly specify ouput format for hexdump tool call. Original commit message: [ELF] - Do not forget to fill last bytes of PT_LOADs with trap instructions. Previously last 4 bytes of executable loads were not filled with trap instructions, patch fixes this bug. Differential revision: https://reviews.llvm.org/D36262 llvm-svn: 311315
1 parent 09a6945 commit f7ef2a1

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed
 

‎lld/ELF/Writer.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1856,7 +1856,7 @@ template <class ELFT> void Writer<ELFT>::writeSectionsBinary() {
18561856
}
18571857

18581858
static void fillTrap(uint8_t *I, uint8_t *End) {
1859-
for (; I + 4 < End; I += 4)
1859+
for (; I + 4 <= End; I += 4)
18601860
memcpy(I, &Target->TrapInstr, 4);
18611861
}
18621862

‎lld/test/ELF/build-id.s

+3-3
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,15 @@ _start:
4848
# DEFAULT: Contents of section .note.test:
4949
# DEFAULT: Contents of section .note.gnu.build-id:
5050
# DEFAULT-NEXT: 04000000 08000000 03000000 474e5500 ............GNU.
51-
# DEFAULT-NEXT: d618a375 bc6301ec
51+
# DEFAULT-NEXT: b0148597 ba5eb7e9
5252

5353
# MD5: Contents of section .note.gnu.build-id:
5454
# MD5-NEXT: 04000000 10000000 03000000 474e5500 ............GNU.
55-
# MD5-NEXT: 051084fe ce1f30ed e035b79e 11262808
55+
# MD5-NEXT: dce3bcaf 5219454c e89a1fc7 86ab17bd
5656

5757
# SHA1: Contents of section .note.gnu.build-id:
5858
# SHA1-NEXT: 04000000 14000000 03000000 474e5500 ............GNU.
59-
# SHA1-NEXT: c70b9aec 903fd291 8b677cd8 1e04f8b6
59+
# SHA1-NEXT: 2f716666 fe3668fe 370a02a1 579c3eb2
6060

6161
# UUID: Contents of section .note.gnu.build-id:
6262
# UUID-NEXT: 04000000 10000000 03000000 474e5500 ............GNU.

‎lld/test/ELF/fill-trap.s

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# REQUIRES: x86
2+
3+
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
4+
# RUN: ld.lld %t -o %t2
5+
# RUN: llvm-readobj -program-headers %t2 | FileCheck %s
6+
# RUN: hexdump -v -s 0x0001ff0 -x %t2 | FileCheck %s -check-prefix=FILL
7+
8+
# CHECK: ProgramHeader {
9+
# CHECK: Type: PT_LOAD
10+
# CHECK: Offset: 0x1000
11+
# CHECK-NEXT: VirtualAddress:
12+
# CHECK-NEXT: PhysicalAddress:
13+
# CHECK-NEXT: FileSize: 4096
14+
# CHECK-NEXT: MemSize:
15+
# CHECK-NEXT: Flags [
16+
# CHECK-NEXT: PF_R
17+
# CHECK-NEXT: PF_X
18+
# CHECK-NEXT: ]
19+
20+
## Check that executable page is filled with traps at it's end.
21+
# FILL: 0001ff0 cccc cccc cccc cccc cccc cccc cccc cccc
22+
23+
.globl _start
24+
_start:
25+
nop

0 commit comments

Comments
 (0)
Please sign in to comment.