llvm-project/lld/test/ELF/sectionstart.s
Fangrui Song 4dc2fb123d [ELF] Error if -Ttext-segment is specified
In GNU ld, -Ttext sets the address of the .text section and -Ttext-segment sets the address of the text segment (RX).

gold only supports the -Ttext-segment semantic and treats -Ttext as an alias for -Ttext-segment.

lld only supports the -Ttext semantic and treats -Ttext-segment as an
alias for -Ttext.  The text segment will be assigned to an address less
than the specified -Ttext-segment value.

This patch drops the -Ttext-segment alias.

The text segment is traditionally the first segment. Users who specify
-Ttext-segment may actually want to specify --image-base, the lld way to
express this. Unfortunately currently this is supported by GNU ld's
COFF port but not by its ELF port. gold does not support this option.
With -z separate-code, the behavior of GNU ld -Ttext-segment is weird (see https://sourceware.org/bugzilla/show_bug.cgi?id=25207)

rL289827 introduced the alias for linking qemu's non-pie user mode
binaries. As explained previously, this actually assigns the text
segment to an address less than 0x60000000. I feel that a better fix is
on the qemu side:
https://lists.nongnu.org/archive/html/qemu-devel/2019-11/msg02480.html

Reviewed By: grimar, ruiu

Differential Revision: https://reviews.llvm.org/D70468
2019-11-21 09:41:55 -08:00

62 lines
2.1 KiB
ArmAsm

# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
# RUN: ld.lld %t.o --section-start .text=0x100000 \
# RUN: --section-start=.data=0x110000 --section-start .bss=0x200000 -o %t
# RUN: llvm-objdump -section-headers %t | FileCheck %s
# CHECK: Sections:
# CHECK-NEXT: Idx Name Size VMA Type
# CHECK-NEXT: 0 00000000 0000000000000000
# CHECK-NEXT: 1 .text 00000001 0000000000100000 TEXT
# CHECK-NEXT: 2 .data 00000004 0000000000110000 DATA
# CHECK-NEXT: 3 .bss 00000004 0000000000200000 BSS
## The same, but dropped "0x" prefix.
# RUN: ld.lld %t.o --section-start .text=100000 \
# RUN: --section-start .data=110000 --section-start .bss=0x200000 -o %t1
# RUN: llvm-objdump -section-headers %t1 | FileCheck %s
## Use -Ttext, -Tdata, -Tbss as replacement for --section-start:
# RUN: ld.lld %t.o -Ttext=0x100000 -Tdata=0x110000 -Tbss=0x200000 -o %t4
# RUN: llvm-objdump -section-headers %t4 | FileCheck %s
## The same, but dropped "0x" prefix.
# RUN: ld.lld %t.o -Ttext=100000 -Tdata=110000 -Tbss=200000 -o %t5
# RUN: llvm-objdump -section-headers %t5 | FileCheck %s
## Check form without assignment:
# RUN: ld.lld %t.o -Ttext 0x100000 -Tdata 0x110000 -Tbss 0x200000 -o %t4
# RUN: llvm-objdump -section-headers %t4 | FileCheck %s
## Errors:
# RUN: not ld.lld %t.o --section-start .text100000 -o /dev/null 2>&1 \
# RUN: | FileCheck -check-prefix=ERR1 %s
# ERR1: invalid argument: --section-start .text100000
# RUN: not ld.lld %t.o --section-start .text=1Q0000 -o /dev/null 2>&1 \
# RUN: | FileCheck -check-prefix=ERR2 %s
# ERR2: invalid argument: --section-start .text=1Q0000
# RUN: not ld.lld %t.o -Ttext=1w0000 -o %t6 2>&1 \
# RUN: | FileCheck -check-prefix=ERR3 %s
# ERR3: invalid argument: -Ttext=1w0000
# RUN: not ld.lld %t.o -Tbss=1w0000 -o %t6 2>&1 \
# RUN: | FileCheck -check-prefix=ERR4 %s
# ERR4: invalid argument: -Tbss=1w0000
# RUN: not ld.lld %t.o -Tdata=1w0000 -o %t6 2>&1 \
# RUN: | FileCheck -check-prefix=ERR5 %s
# ERR5: invalid argument: -Tdata=1w0000
.text
.globl _start
_start:
nop
.data
.long 0
.bss
.zero 4