Files
clang-p2996/lld/test/ELF/linkerscript/section-align2.test
Fangrui Song fbf41b5267 [ELF] Simplify sh_addr computation and warn if sh_addr is not a multiple of sh_addralign
See `docs/ELF/linker_script.rst` for the new computation for sh_addr and sh_addralign.
`ALIGN(section_align)` now means: "increase alignment to section_align"
(like yet another input section requirement).

The "start of section .foo changes from 0x11 to 0x20" warning no longer
makes sense. Change it to warn if sh_addr%sh_addralign!=0.

To decrease the alignment from the default max_input_align,
use `.output ALIGN(8) : {}` instead of `.output : ALIGN(8) {}`
See linkerscript/section-address-align.test as an example.

When both an output section address and ALIGN are set (can be seen as an
"undefined behavior" https://sourceware.org/ml/binutils/2020-03/msg00115.html),
lld may align more than GNU ld, but it makes a linker script working
with GNU ld hard to break with lld.

This patch can be considered as restoring part of the behavior before D74736.

Differential Revision: https://reviews.llvm.org/D75724
2020-03-11 09:35:42 -07:00

44 lines
2.2 KiB
Plaintext

# REQUIRES: aarch64
## Test ALIGN and its interaction with explicit output section addresses.
# RUN: echo '.globl _start; _start: ret; .data.rel.ro; .balign 8; .byte 0; .data; .byte 0; \
# RUN: .section .data2,"aw"; .balign 8; .byte 0; \
# RUN: .section .data3,"aw"; .balign 32; .byte 0; \
# RUN: .bss; .balign 32; .byte 0' | \
# RUN: llvm-mc -filetype=obj -triple=aarch64 - -o %t.o
# RUN: ld.lld -T %s %t.o -o %t 2>&1 | FileCheck --check-prefix=WARN %s --implicit-check-not=warning:
# RUN: llvm-readelf -S %t | FileCheck %s
## Check we don't warn in the absence of SECTIONS.
# RUN: ld.lld --fatal-warnings -Ttext=0x10000 %t.o -o /dev/null
# WARN: warning: address (0x10004) of section .data.rel.ro is not a multiple of alignment (16)
# WARN: warning: address (0x20001) of section .data2 is not a multiple of alignment (8)
# WARN: warning: address (0x20021) of section .bss is not a multiple of alignment (32)
# CHECK: Name Type Address Off Size ES Flg Lk Inf Al
# CHECK-NEXT: NULL 0000000000000000 000000 000000 00 0 0 0
# CHECK-NEXT: .text PROGBITS 0000000000010000 010000 000004 00 AX 0 0 4
# CHECK-NEXT: .data.rel.ro PROGBITS 0000000000010004 010004 000005 00 WA 0 0 16
# CHECK-NEXT: .data PROGBITS 0000000000020000 020000 000001 00 WA 0 0 1
# CHECK-NEXT: .data2 PROGBITS 0000000000020001 020001 000008 00 WA 0 0 8
# CHECK-NEXT: .data3 PROGBITS 0000000000020020 020020 000001 00 WA 0 0 32
# CHECK-NEXT: .bss NOBITS 0000000000020021 020021 000020 00 WA 0 0 32
SECTIONS {
.text 0x10000 : { *(.text) }
## sh_addr is aligned to 16.
.data.rel.ro . : ALIGN(16) { *(.data.rel.ro) }
.data 0x20000 : { *(.data) }
## The output section address is set without ALIGN. sh_addr is set to Dot, ignoring alignment.
## sh_addralign is the maximum of input section alignments, 8.
.data2 . : { *(.data2) }
## sh_addr is aligned to 32.
## The input section has a larger alignment and is thus preceded by a gap.
.data3 : ALIGN(16) { *(.data3) }
## sh_addr is aligned to 16.
## The input section has a larger alignment and is thus preceded by a gap.
.bss . : ALIGN(16) { *(.bss) }
}