llvm-capstone/lld/test/ELF/fill-trap.s
Fangrui Song 0264950697 [ELF] Add -z separate-loadable-segments to complement separate-code and noseparate-code
D64906 allows PT_LOAD to have overlapping p_offset ranges. In the
default R RX RW RW layout + -z noseparate-code case, we do not tail pad
segments when transiting to another segment. This can save at most
3*maxPageSize bytes.

a) Before D64906, we tail pad R, RX and the first RW.
b) With -z separate-code, we tail pad R and RX, but not the first RW (RELRO).

In some cases, b) saves one file page. In some cases, b) wastes one
virtual memory page. The waste is a concern on Fuchsia. Because it uses
compressed binaries, it doesn't benefit from the saved file page.

This patch adds -z separate-loadable-segments to restore the behavior before
D64906. It can affect section addresses and can thus be used as a
debugging mechanism (see PR43214 and ld.so partition bug in
crbug.com/998712).

Reviewed By: jakehehrlich, ruiu

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

llvm-svn: 372807
2019-09-25 03:39:31 +00:00

43 lines
1.5 KiB
ArmAsm

# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
## -z noseparate-code is the default: text segment is not tail padded.
# RUN: ld.lld %t.o -o %t
# RUN: llvm-readobj -l %t | FileCheck %s --check-prefixes=CHECK,NOPAD
# RUN: ld.lld %t.o -z noseparate-code -o %t
# RUN: llvm-readobj -l %t | FileCheck %s --check-prefixes=CHECK,NOPAD
## -z separate-code pads the tail of text segment with traps.
# RUN: ld.lld %t.o -z separate-code -o %t
# RUN: llvm-readobj -l %t | FileCheck %s --check-prefixes=CHECK,PAD
# RUN: od -Ax -x -N16 -j0x1ff0 %t | FileCheck %s --check-prefix=FILL
## -z separate-loadable-segments pads all segments, including the text segment.
# RUN: ld.lld %t.o -z separate-loadable-segments -o %t
# RUN: llvm-readobj -l %t | FileCheck %s --check-prefixes=CHECK,PAD
# RUN: od -Ax -x -N16 -j0x1ff0 %t | FileCheck %s --check-prefix=FILL
# RUN: ld.lld %t.o -z separate-code -z noseparate-code -o %t
# RUN: llvm-readobj -l %t | FileCheck %s --check-prefixes=CHECK,NOPAD
# CHECK: ProgramHeader {
# CHECK: Type: PT_LOAD
# PAD: Offset: 0x1000
# NOPAD: Offset: 0x120
# CHECK-NEXT: VirtualAddress:
# CHECK-NEXT: PhysicalAddress:
# PAD-NEXT: FileSize: 4096
# NOPAD-NEXT: FileSize: 1
# CHECK-NEXT: MemSize:
# CHECK-NEXT: Flags [
# CHECK-NEXT: PF_R
# CHECK-NEXT: PF_X
# CHECK-NEXT: ]
## Check that executable page is filled with traps at its end.
# FILL: 001ff0 cccc cccc cccc cccc cccc cccc cccc cccc
.globl _start
_start:
nop