llvm-project/lld/test/ELF/msp430.s

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

45 lines
1.0 KiB
ArmAsm
Raw Normal View History

; REQUIRES: msp430
; RUN: llvm-mc -filetype=obj -triple=msp430-elf -o %t1.o %s
; RUN: echo -e '.global _start\n _start: nop' | llvm-mc -filetype=obj -triple=msp430-elf -o %t2.o -
[ELF] Add -z separate-code and pad the last page of last PF_X PT_LOAD with traps only if -z separate-code is specified This patch 1) adds -z separate-code and -z noseparate-code (default). 2) changes the condition that the last page of last PF_X PT_LOAD is padded with trap instructions. Current condition (after D33630): if there is no `SECTIONS` commands. After this change: if -z separate-code is specified. -z separate-code was introduced to ld.bfd in 2018, to place the text segment in its own pages. There is no overlap in pages between an executable segment and a non-executable segment: 1) RX cannot load initial contents from R or RW(or non-SHF_ALLOC). 2) R and RW(or non-SHF_ALLOC) cannot load initial contents from RX. lld's current status: - Between R and RX: in `Writer<ELFT>::fixSectionAlignments()`, the start of a segment is always aligned to maxPageSize, so the initial contents loaded by R and RX do not overlap. I plan to allow overlaps in D64906 if -z noseparate-code is in effect. - Between RX and RW(or non-SHF_ALLOC if RW doesn't exist): we currently unconditionally pad the last page to commonPageSize (defaults to 4096 on all targets we support). This patch will make it effective only if -z separate-code is specified. -z separate-code is a dubious feature that intends to reduce the number of ROP gadgets (which is actually ineffective because attackers can find plenty of gadgets in the text segment, no need to find gadgets in non-code regions). With the overlapping PT_LOAD technique D64906, -z noseparate-code removes two more alignments at segment boundaries than -z separate-code. This saves at most defaultCommonPageSize*2 bytes, which are significant on targets with large defaultCommonPageSize (AArch64/MIPS/PPC: 65536). Issues/feedback on alignment at segment boundaries to help understand the implication: * binutils PR24490 (the situation on ld.bfd is worse because they have two R-- on both sides of R-E so more alignments.) * In binutils, the 2018-02-27 commit "ld: Add --enable-separate-code" made -z separate-code the default on Linux. https://github.com/richfelker/musl-cross-make/commit/d969dea983a2cc54a1e0308a0cdeb6c3307e4bfa In musl-cross-make, binutils is configured with --disable-separate-code to address size regressions caused by -z separate-code. (lld actually has the same issue, which I plan to fix in a future patch. The ld.bfd x86 status is worse because they default to max-page-size=0x200000). * https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=237676 people want smaller code size. This patch will remove one alignment boundary. * Stef O'Rear: I'm opposed to any kind of page alignment at the text/rodata line (having a partial page of text aliased as rodata and vice versa has no demonstrable harm, and I actually care about small systems). So, make -z noseparate-code the default. Reviewed By: ruiu Differential Revision: https://reviews.llvm.org/D64903 llvm-svn: 367537
2019-08-01 17:58:25 +08:00
; RUN: ld.lld -o %t.exe --Tdata=0x2000 --Ttext=0x8000 --defsym=_byte=0x21 -z separate-code %t2.o %t1.o
; RUN: llvm-objdump -s -d %t.exe | FileCheck %s
;; Check handling of basic msp430 relocation types.
.data
;; R_MSP430_8
.byte _byte
;; R_MSP430_16
.word _start
;; R_MSP430_32
.long _start
; CHECK: Contents of section .data:
; CHECK-NEXT: 2000 21008000 800000
.text
.global foo
foo:
;; R_MSP430_10_PCREL
jmp _start
; CHECK: Disassembly of section .text:
; CHECK-EMPTY:
; CHECK-NEXT: <_start>:
; CHECK-NEXT: 8000: {{.*}} nop
; CHECK: <foo>:
; CHECK-NEXT: 8004: {{.*}} jmp $-4
;; R_MSP430_16_BYTE
call #_start
; CHECK: call #32768
;; R_MSP430_16_PCREL_BYTE
mov #-1, _start
; CHECK: 800a: {{.*}} mov #-1, -12
; RUN: od -x %t.exe | FileCheck -check-prefix=TRAP %s
; TRAP: 4343 4343 4343 4343 4343 4343 4343 4343