llvm-project/lld/test/elf/linkerscript/sections-with-wildcards.test

89 lines
1.8 KiB
Plaintext

/*
Tests a linker script that uses the SECTIONS command with rules containing
wildcards and simple SORT directives. It also tests that the linker script
evaluates the expressions in the same order as the one written in the script
file.
This test uses three X86-64 input objects, prog1.o, prog2.o and prog3.o,
which were created with the following C or assembly code:
*** prog1.o:
(command line clang -c prog1.c -o prog1.o)
const char *prog2();
void write(int, const char *, int);
int main() {
write(1, prog2(), 14);
}
*** prog2.o:
(command line clang -c prog2.c -o prog2.o)
const char *prog2() {
return "Hello, world!\n";
}
*** prog3.o:
(command line clang -c prog3.S -o prog3.o)
.globl write
write:
mov $1, %eax
syscall
ret
.globl _start
_start:
call main
mov $60, %eax
syscall
ret
We use the following linker script for this test:
*/
ENTRY(_start)
SECTIONS
{
my_start_addr = 0x500000;
my_symbol = my_start_addr;
. = my_symbol;
.foo : { SORT(*)(.text .rodata*) }
}
/*
RUN: mkdir -p %T
RUN: yaml2obj -format=elf %p/Inputs/prog1.o.yaml -o=%T/p1.o
RUN: yaml2obj -format=elf %p/Inputs/prog2.o.yaml -o=%T/p2.o
RUN: yaml2obj -format=elf %p/Inputs/prog3.o.yaml -o=%T/p3.o
RUN: cd %T
RUN: lld -flavor gnu -target x86_64 -T %s p1.o p2.o p3.o \
RUN: -static -o %t1
RUN: llvm-readobj -s %t1 | FileCheck -check-prefix CHECKSECTIONS %s
CHECKSECTIONS: Index: 1
CHECKSECTIONS: Name: .foo
CHECKSECTIONS: Address: 0x500000
CHECKSECTIONS: Size: 101
RUN: llvm-readobj -symbols %t1 | FileCheck -check-prefix CHECKSYMS %s
CHECKSYMS: Name: main
CHECKSYMS-NEXT: Value: 0x500000
CHECKSYMS: Name: prog2
CHECKSYMS-NEXT: Value: 0x500030
CHECKSYMS: Name: write
CHECKSYMS-NEXT: Value: 0x500050
CHECKSYMS: Name: _start
CHECKSYMS-NEXT: Value: 0x500058
*/