/* Tests a simple linker script that changes the order of output sections and also changes the address of output sections by using simple expressions. 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 { . = 0x500000; .text : { prog1.o(.text) } .mystring : { prog2.o(.rodata.str1.1) } . = . + 0x6000; .text.2 : {prog3.o(.text) prog2.o(.text) } } /* RUN: mkdir -p %T RUN: yaml2obj -format=elf %p/Inputs/prog1.o.yaml -o=%T/prog1.o RUN: yaml2obj -format=elf %p/Inputs/prog2.o.yaml -o=%T/prog2.o RUN: yaml2obj -format=elf %p/Inputs/prog3.o.yaml -o=%T/prog3.o RUN: cd %T RUN: lld -flavor gnu -target x86_64 -T %s prog1.o prog2.o prog3.o \ RUN: -static -o %t1 RUN: llvm-readobj -s %t1 | FileCheck -check-prefix CHECKSECTIONS %s CHECKSECTIONS: Index: 1 CHECKSECTIONS: Name: .text CHECKSECTIONS: Address: 0x500000 CHECKSECTIONS: Size: 33 CHECKSECTIONS: Index: 2 CHECKSECTIONS: Name: .mystring CHECKSECTIONS: Address: 0x500021 CHECKSECTIONS: Size: 15 CHECKSECTIONS: Index: 3 CHECKSECTIONS: Name: .text.2 CHECKSECTIONS: Address: 0x506030 CHECKSECTIONS: Size: 48 RUN: llvm-readobj -symbols %t1 | FileCheck -check-prefix CHECKSYMS %s CHECKSYMS: Name: main CHECKSYMS-NEXT: Value: 0x500000 CHECKSYMS: Name: write CHECKSYMS-NEXT: Value: 0x506030 CHECKSYMS: Name: _start CHECKSYMS-NEXT: Value: 0x506038 CHECKSYMS: Name: prog2 CHECKSYMS-NEXT: Value: 0x506050 RUN: llvm-readobj -program-headers %t1 | FileCheck -check-prefix CHECKPHDRS %s CHECKPHDRS: Type: PT_LOAD (0x1) CHECKPHDRS: Offset: 0x1000 CHECKPHDRS-NEXT: VirtualAddress: 0x500000 CHECKPHDRS-NEXT: PhysicalAddress: 0x500000 CHECKPHDRS-NEXT: FileSize: 48 CHECKPHDRS-NEXT: MemSize: 48 CHECKPHDRS: Type: PT_LOAD (0x1) CHECKPHDRS: Offset: 0x2030 CHECKPHDRS-NEXT: VirtualAddress: 0x506030 CHECKPHDRS-NEXT: PhysicalAddress: 0x506030 CHECKPHDRS-NEXT: FileSize: 168 CHECKPHDRS-NEXT: MemSize: 168 */