2017-02-18 00:26:13 +08:00
|
|
|
# REQUIRES: x86
|
|
|
|
# RUN: llvm-mc -filetype=obj -triple=x86_64-linux %s -o %t.o
|
2018-05-16 01:02:35 +08:00
|
|
|
# RUN: echo "SECTIONS { .data 0x4000 : {*(.data)} .dynsym 0x2000 : {*(.dynsym)} .dynstr : {*(.dynstr)} }" > %t.script
|
2017-10-06 17:37:44 +08:00
|
|
|
# RUN: ld.lld --hash-style=sysv -o %t.so --script %t.script %t.o -shared
|
2020-03-16 08:47:44 +08:00
|
|
|
# RUN: llvm-objdump --section-headers %t.so | FileCheck %s
|
2017-02-18 00:26:13 +08:00
|
|
|
|
2018-05-16 01:02:35 +08:00
|
|
|
# Note: how the layout is done:
|
|
|
|
# we need to layout 2 segments, each contains sections:
|
|
|
|
# seg1: .data .dynamic
|
|
|
|
# seg2: .dynsym .dynstr .text .hash
|
|
|
|
# for each segment, we start from the first section, regardless
|
|
|
|
# whether it is an orphan or not (sections that are not listed in the
|
|
|
|
# linkerscript are orphans):
|
|
|
|
# for seg1, we assign address: .data(0x4000), .dynamic(0x4008)
|
|
|
|
# for seg2, we assign address: .dynsym(0x2000), .dynstr(0x2018) ...
|
|
|
|
# .dynsym is not an orphan, so we take address from script, we assign
|
|
|
|
# .dynstr current address cursor, which is the end # of .dynsym and so
|
|
|
|
# on for later sections.
|
|
|
|
|
|
|
|
# Also note, it is absolutely *illegal* to have section addresses of
|
|
|
|
# the same segment in none-increasing order, authors of linker scripts
|
|
|
|
# must take responsibility to make sure this does not happen.
|
|
|
|
|
2017-07-12 22:50:25 +08:00
|
|
|
# CHECK: Sections:
|
2019-01-28 23:03:47 +08:00
|
|
|
# CHECK-NEXT: Idx Name Size VMA Type
|
2017-07-12 22:50:25 +08:00
|
|
|
# CHECK-NEXT: 0 00000000 0000000000000000
|
[ELF] Simplify RelRo, TLS, NOBITS section ranks and make RW PT_LOAD start with RelRo
Old: PT_LOAD(.data | PT_GNU_RELRO(.data.rel.ro .bss.rel.ro) | .bss)
New: PT_LOAD(PT_GNU_RELRO(.data.rel.ro .bss.rel.ro) | .data .bss)
The placement of | indicates page alignment caused by PT_GNU_RELRO. The
new layout has simpler rules and saves space for many cases.
Old size: roundup(.data) + roundup(.data.rel.ro)
New size: roundup(.data.rel.ro + .bss.rel.ro) + .data
Other advantages:
* At runtime the 3 memory mappings decrease to 2.
* start(PT_TLS) = start(PT_GNU_RELRO) = start(RW PT_LOAD). This
simplifies binary manipulation tools.
GNU strip before 2.31 discards PT_GNU_RELRO if its
address is not equal to the start of its associated PT_LOAD.
This has been fixed by https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=f2731e0c374e5323ce4cdae2bcc7b7fe22da1a6f
But with this change, we will be compatible with GNU strip before 2.31
* Before, .got.plt (non-relro by default) was placed before .got (relro
by default), which made it impossible to have _GLOBAL_OFFSET_TABLE_
(start of .got.plt on x86-64) equal to the end of .got (R_GOT*_FROM_END)
(https://bugs.llvm.org/show_bug.cgi?id=36555). With the new ordering, we
can improve on this regard if we'd like to.
Reviewers: ruiu, espindola, pcc
Subscribers: emaste, arichardson, llvm-commits, joerg, jdoerfert
Differential Revision: https://reviews.llvm.org/D56828
llvm-svn: 356117
2019-03-14 11:47:45 +08:00
|
|
|
# CHECK-NEXT: 1 .dynamic 00000060 0000000000000000
|
|
|
|
# CHECK-NEXT: 2 .data 00000008 0000000000004000
|
2018-06-27 01:04:47 +08:00
|
|
|
# CHECK-NEXT: 3 .dynsym 00000018 0000000000002000
|
2018-05-16 01:02:35 +08:00
|
|
|
# CHECK-NEXT: 4 .dynstr 00000001 0000000000002018
|
2018-06-27 01:04:47 +08:00
|
|
|
# CHECK-NEXT: 5 .hash 00000010 000000000000201c
|
|
|
|
# CHECK-NEXT: 6 .text 00000008 000000000000202c
|
2017-02-18 00:26:13 +08:00
|
|
|
|
|
|
|
.quad 0
|
|
|
|
.data
|
|
|
|
.quad 0
|
2018-05-16 01:02:35 +08:00
|
|
|
|