2019-01-10 23:34:33 +08:00
|
|
|
; REQUIRES: msp430
|
2019-01-11 01:57:30 +08:00
|
|
|
; 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
|
2019-01-11 01:57:30 +08:00
|
|
|
; RUN: llvm-objdump -s -d %t.exe | FileCheck %s
|
2019-01-10 23:34:33 +08:00
|
|
|
|
|
|
|
;; Check handling of basic msp430 relocation types.
|
|
|
|
|
[llvm-objdump] Further rearrange llvm-objdump sections for compatability
Summary:
rL371826 rearranged some output from llvm-objdump for GNU objdump compatability, but there still seem to be some more.
I think this rearrangement is a little closer. Overview of the ordering which matches GNU objdump:
* Archive headers
* File headers
* Section headers
* Symbol table
* Dwarf debugging
* Relocations (if `--disassemble` is not used)
* Section contents
* Disassembly
Reviewers: jhenderson, justice_adams, grimar, ychen, espindola
Reviewed By: jhenderson
Subscribers: aprantl, emaste, arichardson, jrtc27, atanasyan, seiya, llvm-commits, MaskRay
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D68066
llvm-svn: 373671
2019-10-04 06:01:08 +08:00
|
|
|
.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
|
|
|
|
|
2019-01-10 23:34:33 +08:00
|
|
|
.text
|
|
|
|
.global foo
|
|
|
|
foo:
|
|
|
|
;; R_MSP430_10_PCREL
|
|
|
|
jmp _start
|
|
|
|
|
|
|
|
; CHECK: Disassembly of section .text:
|
2019-05-01 18:40:48 +08:00
|
|
|
; CHECK-EMPTY:
|
2020-03-06 06:18:38 +08:00
|
|
|
; CHECK-NEXT: <_start>:
|
2019-01-10 23:34:33 +08:00
|
|
|
; CHECK-NEXT: 8000: {{.*}} nop
|
2020-03-06 06:18:38 +08:00
|
|
|
; CHECK: <foo>:
|
2019-01-10 23:34:33 +08:00
|
|
|
; 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
|
|
|
|
|
2019-01-11 01:57:30 +08:00
|
|
|
; RUN: od -x %t.exe | FileCheck -check-prefix=TRAP %s
|
2019-01-11 01:45:56 +08:00
|
|
|
; TRAP: 4343 4343 4343 4343 4343 4343 4343 4343
|