2019-07-18 18:43:07 +08:00
|
|
|
# REQUIRES: ppc
|
|
|
|
|
|
|
|
# RUN: llvm-mc -filetype=obj -triple=powerpc64le %s -o %t.o
|
|
|
|
# RUN: llvm-readobj -r %t.o | FileCheck --check-prefix=INPUT-REL %s
|
|
|
|
## IE
|
|
|
|
# RUN: ld.lld -shared %t.o -o %t.so
|
|
|
|
# RUN: llvm-readobj -r %t.so | FileCheck --check-prefix=IE-REL %s
|
|
|
|
# RUN: llvm-objdump -d --no-show-raw-insn %t.so | FileCheck --check-prefix=IE %s
|
|
|
|
## IE -> LE
|
|
|
|
# RUN: ld.lld %t.o -o %t
|
|
|
|
# RUN: llvm-readelf -r %t | FileCheck --check-prefix=NOREL %s
|
|
|
|
# RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck --check-prefix=LE %s
|
|
|
|
|
|
|
|
# RUN: llvm-mc -filetype=obj -triple=powerpc64 %s -o %t.o
|
|
|
|
# RUN: llvm-readobj -r %t.o | FileCheck --check-prefix=INPUT-REL %s
|
|
|
|
## IE
|
|
|
|
# RUN: ld.lld -shared %t.o -o %t.so
|
|
|
|
# RUN: llvm-readobj -r %t.so | FileCheck --check-prefix=IE-REL %s
|
|
|
|
# RUN: llvm-objdump -d --no-show-raw-insn %t.so | FileCheck --check-prefix=IE %s
|
|
|
|
## IE -> LE
|
|
|
|
# RUN: ld.lld %t.o -o %t
|
|
|
|
# RUN: llvm-readelf -r %t | FileCheck --check-prefix=NOREL %s
|
|
|
|
# RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck --check-prefix=LE %s
|
|
|
|
|
|
|
|
# IE-REL: .rela.dyn {
|
[ELF][PPC] Allow PT_LOAD to have overlapping p_offset ranges
This change affects the non-linker script case (precisely, when the
`SECTIONS` command is not used). It deletes 3 alignments at PT_LOAD
boundaries for the default case: the size of a powerpc64 binary can be
decreased by at most 192kb. The technique can be ported to other
targets.
Let me demonstrate the idea with a maxPageSize=65536 example:
When assigning the address to the first output section of a new PT_LOAD,
if the end p_vaddr of the previous PT_LOAD is 0x10020, we advance to
the next multiple of maxPageSize: 0x20000. The new PT_LOAD will thus
have p_vaddr=0x20000. Because p_offset and p_vaddr are congruent modulo
maxPageSize, p_offset will be 0x20000, leaving a p_offset gap [0x10020,
0x20000) in the output.
Alternatively, if we advance to 0x20020, the new PT_LOAD will have
p_vaddr=0x20020. We can pick either 0x10020 or 0x20020 for p_offset!
Obviously 0x10020 is the choice because it leaves no gap. At runtime,
p_vaddr will be rounded down by pagesize (65536 if
pagesize=maxPageSize). This PT_LOAD will load additional initial
contents from p_offset ranges [0x10000,0x10020), which will also be
loaded by the previous PT_LOAD. This is fine if -z noseparate-code is in
effect or if we are not transiting between executable and non-executable
segments.
ld.bfd -z noseparate-code leverages this technique to keep output small.
This patch implements the technique in lld, which is mostly effective on
targets with large defaultMaxPageSize (AArch64/MIPS/PPC: 65536). The 3
removed alignments can save almost 3*65536 bytes.
Two places that rely on p_vaddr%pagesize = 0 have to be updated.
1) We used to round p_memsz(PT_GNU_RELRO) up to commonPageSize (defaults
to 4096 on all targets). Now p_vaddr%commonPageSize may be non-zero.
The updated formula takes account of that factor.
2) Our TP offsets formulae are only correct if p_vaddr%p_align = 0.
Fix them. See the updated comments in InputSection.cpp for details.
On targets that we enable the technique (only PPC64 now),
we can potentially make `p_vaddr(PT_TLS)%p_align(PT_TLS) != 0`
if `sh_addralign(.tdata) < sh_addralign(.tbss)`
This exposes many problems in ld.so implementations, especially the
offsets of dynamic TLS blocks. Known issues:
FreeBSD 13.0-CURRENT rtld-elf (i386/amd64/powerpc/arm64)
glibc (HEAD) i386 and x86_64 https://sourceware.org/bugzilla/show_bug.cgi?id=24606
musl<=1.1.22 on TLS Variant I architectures (aarch64/powerpc64/...)
So, force p_vaddr%p_align = 0 by rounding dot up to p_align(PT_TLS).
The technique will be enabled (with updated tests) for other targets in
subsequent patches.
Reviewed By: ruiu
Differential Revision: https://reviews.llvm.org/D64906
llvm-svn: 369343
2019-08-20 16:34:25 +08:00
|
|
|
# IE-REL-NEXT: 0x204A0 R_PPC64_TPREL64 c 0x0
|
|
|
|
# IE-REL-NEXT: 0x204B0 R_PPC64_TPREL64 i 0x0
|
|
|
|
# IE-REL-NEXT: 0x204B8 R_PPC64_TPREL64 l 0x0
|
|
|
|
# IE-REL-NEXT: 0x204A8 R_PPC64_TPREL64 s 0x0
|
2019-07-18 18:43:07 +08:00
|
|
|
# IE-REL-NEXT: }
|
|
|
|
|
|
|
|
# INPUT-REL: R_PPC64_GOT_TPREL16_HA c 0x0
|
|
|
|
# INPUT-REL: R_PPC64_GOT_TPREL16_LO_DS c 0x0
|
|
|
|
# INPUT-REL: R_PPC64_TLS c 0x0
|
|
|
|
## &.got[0] - .TOC. = -32768
|
|
|
|
# IE-LABEL: test1:
|
|
|
|
# IE-NEXT: addis 3, 2, 0
|
|
|
|
# IE-NEXT: ld 3, -32768(3)
|
|
|
|
# IE-NEXT: lbzx 3, 3, 13
|
|
|
|
# LE-LABEL: test1:
|
|
|
|
# LE-NEXT: nop
|
|
|
|
# LE-NEXT: addis 3, 13, 0
|
|
|
|
# LE-NEXT: lbz 3, -28672(3)
|
|
|
|
test1:
|
|
|
|
addis 3, 2, c@got@tprel@ha
|
|
|
|
ld 3, c@got@tprel@l(3)
|
|
|
|
lbzx 3, 3, c@tls
|
|
|
|
|
|
|
|
# INPUT-REL: R_PPC64_GOT_TPREL16_HA s 0x0
|
|
|
|
# INPUT-REL: R_PPC64_GOT_TPREL16_LO_DS s 0x0
|
|
|
|
# INPUT-REL: R_PPC64_TLS s 0x0
|
|
|
|
## &.got[1] - .TOC. = -32760
|
|
|
|
# IE-LABEL: test2:
|
|
|
|
# IE-NEXT: addis 3, 2, 0
|
|
|
|
# IE-NEXT: ld 3, -32760(3)
|
|
|
|
# IE-NEXT: lhzx 3, 3, 13
|
|
|
|
# LE-LABEL: test2:
|
|
|
|
# LE-NEXT: nop
|
|
|
|
# LE-NEXT: addis 3, 13, 0
|
|
|
|
# LE-NEXT: lhz 3, -28670(3)
|
|
|
|
test2:
|
|
|
|
addis 3, 2, s@got@tprel@ha
|
|
|
|
ld 3, s@got@tprel@l(3)
|
|
|
|
lhzx 3, 3, s@tls
|
|
|
|
|
|
|
|
# INPUT-REL: R_PPC64_GOT_TPREL16_HA i 0x0
|
|
|
|
# INPUT-REL: R_PPC64_GOT_TPREL16_LO_DS i 0x0
|
|
|
|
# INPUT-REL: R_PPC64_TLS i 0x0
|
|
|
|
## &.got[2] - .TOC. = -32752
|
|
|
|
# IE-LABEL: test3:
|
|
|
|
# IE-NEXT: addis 3, 2, 0
|
|
|
|
# IE-NEXT: ld 3, -32752(3)
|
|
|
|
# IE-NEXT: lwzx 3, 3, 13
|
|
|
|
# LE-LABEL: test3:
|
|
|
|
# LE-NEXT: nop
|
|
|
|
# LE-NEXT: addis 3, 13, 0
|
|
|
|
# LE-NEXT: lwz 3, -28668(3)
|
|
|
|
test3:
|
|
|
|
addis 3, 2, i@got@tprel@ha
|
|
|
|
ld 3, i@got@tprel@l(3)
|
|
|
|
lwzx 3, 3, i@tls
|
|
|
|
|
|
|
|
# INPUT-REL: R_PPC64_GOT_TPREL16_HA l 0x0
|
|
|
|
# INPUT-REL: R_PPC64_GOT_TPREL16_LO_DS l 0x0
|
|
|
|
# INPUT-REL: R_PPC64_TLS l 0x0
|
|
|
|
## &.got[3] - .TOC. = -32744
|
|
|
|
# IE-LABEL: test4:
|
|
|
|
# IE-NEXT: addis 3, 2, 0
|
|
|
|
# IE-NEXT: ld 3, -32744(3)
|
|
|
|
# IE-NEXT: ldx 3, 3, 13
|
|
|
|
# LE-LABEL: test4:
|
|
|
|
# LE-NEXT: nop
|
|
|
|
# LE-NEXT: addis 3, 13, 0
|
|
|
|
# LE-NEXT: ld 3, -28664(3)
|
|
|
|
test4:
|
|
|
|
addis 3, 2, l@got@tprel@ha
|
|
|
|
ld 3, l@got@tprel@l(3)
|
|
|
|
ldx 3, 3, l@tls
|
|
|
|
|
|
|
|
# LE-LABEL: test5:
|
|
|
|
# LE-NEXT: nop
|
|
|
|
# LE-NEXT: addis 4, 13, 0
|
|
|
|
# LE-NEXT: stb 3, -28672(4)
|
|
|
|
test5:
|
|
|
|
addis 4, 2, c@got@tprel@ha
|
|
|
|
ld 4, c@got@tprel@l(4)
|
|
|
|
stbx 3, 4, c@tls
|
|
|
|
|
|
|
|
|
|
|
|
# LE-LABEL: test6:
|
|
|
|
# LE-NEXT: nop
|
|
|
|
# LE-NEXT: addis 4, 13, 0
|
|
|
|
# LE-NEXT: sth 3, -28670(4)
|
|
|
|
test6:
|
|
|
|
addis 4, 2, s@got@tprel@ha
|
|
|
|
ld 4, s@got@tprel@l(4)
|
|
|
|
sthx 3, 4, s@tls
|
|
|
|
|
|
|
|
|
|
|
|
# LE-LABEL: test7:
|
|
|
|
# LE-NEXT: nop
|
|
|
|
# LE-NEXT: addis 4, 13, 0
|
|
|
|
# LE-NEXT: stw 3, -28668(4)
|
|
|
|
test7:
|
|
|
|
addis 4, 2, i@got@tprel@ha
|
|
|
|
ld 4, i@got@tprel@l(4)
|
|
|
|
stwx 3, 4, i@tls
|
|
|
|
|
|
|
|
# LE-LABEL: test8:
|
|
|
|
# LE-NEXT: nop
|
|
|
|
# LE-NEXT: addis 4, 13, 0
|
|
|
|
# LE-NEXT: std 3, -28664(4)
|
|
|
|
test8:
|
|
|
|
addis 4, 2, l@got@tprel@ha
|
|
|
|
ld 4, l@got@tprel@l(4)
|
|
|
|
stdx 3, 4, l@tls
|
|
|
|
|
|
|
|
# LE-LABEL: test9:
|
|
|
|
# LE-NEXT: nop
|
|
|
|
# LE-NEXT: addis 3, 13, 0
|
|
|
|
# LE-NEXT: addi 3, 3, -28668
|
|
|
|
test9:
|
|
|
|
addis 3, 2, i@got@tprel@ha
|
|
|
|
ld 3, i@got@tprel@l(3)
|
|
|
|
add 3, 3, i@tls
|
|
|
|
|
|
|
|
# LE-LABEL: test_ds:
|
|
|
|
# LE-NEXT: addis 4, 13, 0
|
|
|
|
# LE-NEXT: std 3, -28664(4)
|
|
|
|
test_ds:
|
|
|
|
ld 4, l@got@tprel(2)
|
|
|
|
stdx 3, 4, l@tls
|
|
|
|
|
|
|
|
# NOREL: There are no relocations in this file.
|
|
|
|
|
|
|
|
.section .tdata,"awT",@progbits
|
|
|
|
.globl c, s, i, l
|
|
|
|
c:
|
|
|
|
.byte 97
|
|
|
|
|
|
|
|
.p2align 1
|
|
|
|
s:
|
|
|
|
.short 55
|
|
|
|
|
|
|
|
.p2align 2
|
|
|
|
i:
|
|
|
|
.long 55
|
|
|
|
|
|
|
|
.p2align 3
|
|
|
|
l:
|
|
|
|
.quad 55
|