137 lines · plain
1# REQUIRES: x862# RUN: rm -rf %t && split-file --leading-lines %s %t3# RUN: llvm-mc -filetype=obj -triple=x86_64 %t/a.s -o %t/a.o4 5## There is no main linker script. OVERWRITE_SECTIONS defines output section6## descriptions and follows the usual orphan placement rules.7 8# RUN: ld.lld %t/overwrite1.lds %t/a.o -o %t19# RUN: llvm-readelf -S %t1 | FileCheck %s --check-prefix=CHECK110 11# CHECK1: Name Type Address Off Size ES Flg Lk Inf Al12# CHECK1-NEXT: NULL [[#%x,]] [[#%x,]] 00000013# CHECK1-NEXT: .text PROGBITS [[#%x,]] [[#%x,]] 000001 00 AX 0 0 414# CHECK1-NEXT: .foo.text PROGBITS [[#%x,]] [[#%x,]] 000002 00 WAX 0 0 815# CHECK1-NEXT: .data PROGBITS [[#%x,]] [[#%x,]] 000001 00 WA 0 0 116# CHECK1-NEXT: .comment PROGBITS {{.*}}17 18# RUN: ld.lld %t/overwrite1.lds %t/overwrite1.lds %t/a.o -o /dev/null 2>&1 | FileCheck %s --check-prefix=WARN119 20# WARN1: warning: OVERWRITE_SECTIONS specifies duplicate .foo.text21 22## The output section description order (.foo.data .foo.text) does not affect23## the output order.24 25# RUN: ld.lld %t/overwrite2.lds %t/a.o -o %t226# RUN: llvm-readelf -S -s %t2 | FileCheck %s --check-prefix=CHECK227 28# CHECK2: [Nr] Name Type Address Off Size ES Flg Lk Inf Al29# CHECK2-NEXT: [ 0] NULL [[#%x,]] [[#%x,]] 00000030# CHECK2-NEXT: [ 1] .text PROGBITS [[#%x,]] [[#%x,]] 000001 00 AX 0 0 431# CHECK2-NEXT: [ 2] .foo.text PROGBITS [[#%x,]] [[#%x,]] 000001 00 AX 0 0 132# CHECK2-NEXT: [ 3] .data PROGBITS [[#%x,]] [[#%x,]] 000001 00 WA 0 0 133# CHECK2-NEXT: [ 4] .foo.data PROGBITS [[#%x,]] [[#%x,]] 000001 00 WA 0 0 134# CHECK2-NEXT: [ 5] .comment PROGBITS {{.*}}35 36# CHECK2: Num: Value Size Type Bind Vis Ndx Name37# CHECK2: [[#]]: [[#%x,ADDR:]] 0 NOTYPE GLOBAL DEFAULT 4 FOO_DATA_START38# CHECK2-NEXT: [[#]]: {{0*}}[[#ADDR+1]] 0 NOTYPE GLOBAL DEFAULT 4 FOO_DATA_END39# CHECK2-NEXT: [[#]]: [[#%x,ADDR:]] 0 NOTYPE GLOBAL DEFAULT 2 FOO_TEXT_START40# CHECK2-NEXT: [[#]]: {{0*}}[[#ADDR+1]] 0 NOTYPE GLOBAL DEFAULT 2 FOO_TEXT_END41 42## OVERWRITE_SECTIONS is processed before the main script. The main script43## specifies the output order. The alignment of .foo.text is specified by44## OVERWRITE_SECTIONS insteaad of the main script.45 46# RUN: ld.lld -T %t/main.lds %t/overwrite1.lds %t/a.o -o %t3 2>&1 | count 047# RUN: llvm-readelf -S %t3 | FileCheck %s --check-prefix=CHECK348# RUN: ld.lld %t/overwrite1.lds -T %t/main.lds %t/a.o -o %t3 2>&1 | count 049# RUN: llvm-readelf -S %t3 | FileCheck %s --check-prefix=CHECK350 51# CHECK3: Name Type Address Off Size ES Flg Lk Inf Al52# CHECK3-NEXT: NULL [[#%x,]] [[#%x,]] 00000053# CHECK3-NEXT: .data PROGBITS [[#%x,]] [[#%x,]] 000001 00 WA 0 0 154# CHECK3-NEXT: .text PROGBITS [[#%x,]] [[#%x,]] 000001 00 AX 0 0 455# CHECK3-NEXT: .foo.text PROGBITS [[#%x,]] [[#%x,]] 000002 00 WAX 0 0 856# CHECK3-NEXT: .comment PROGBITS {{.*}}57 58# RUN: ld.lld -T %t/main.lds %t/overwrite1.lds %t/a.o -o %t3 --verbose 2>&1 | FileCheck %s --check-prefix=VERBOSE359 60# VERBOSE3: {{.*}}overwrite1.lds:[[#]] overwrites .foo.text61 62## If INSERT commands are specified, INSERT commands are processed after overwrite sections.63# RUN: ld.lld %t/insert.lds %t/overwrite2.lds %t/a.o -o %t464# RUN: llvm-readelf -S -s %t4 | FileCheck %s --check-prefix=CHECK465 66# CHECK4: [Nr] Name Type Address Off Size ES Flg Lk Inf Al67# CHECK4-NEXT: [ 0] NULL [[#%x,]] [[#%x,]] 00000068# CHECK4-NEXT: [ 1] .text PROGBITS [[#%x,]] [[#%x,]] 000001 00 AX 0 0 469# CHECK4-NEXT: [ 2] .data PROGBITS [[#%x,]] [[#%x,]] 000001 00 WA 0 0 170# CHECK4-NEXT: [ 3] .foo.data PROGBITS [[#%x,]] [[#%x,]] 000001 00 WA 0 0 171# CHECK4-NEXT: [ 4] .foo.text PROGBITS [[#%x,]] [[#%x,]] 000001 00 AX 0 0 172# CHECK4-NEXT: [ 5] .comment PROGBITS {{.*}}73 74# CHECK4: Num: Value Size Type Bind Vis Ndx Name75# CHECK4: [[#]]: [[#%x,ADDR:]] 0 NOTYPE GLOBAL DEFAULT 4 FOO_TEXT_START76# CHECK4-NEXT: [[#]]: {{0*}}[[#ADDR+1]] 0 NOTYPE GLOBAL DEFAULT 4 FOO_TEXT_END77# CHECK4-NEXT: [[#]]: [[#%x,ADDR:]] 0 NOTYPE GLOBAL DEFAULT 3 FOO_DATA_START78# CHECK4-NEXT: [[#]]: {{0*}}[[#ADDR+1]] 0 NOTYPE GLOBAL DEFAULT 3 FOO_DATA_END79 80## OVERWRITE_SECTIONS describes a section used as an anchor of an insert command.81## Place .foo.data as an orphan, then insert .foo.text after .foo.data.82# RUN: ld.lld %t/insert.lds %t/overwrite3.lds %t/a.o -o %t583# RUN: llvm-readelf -S -s %t4 | FileCheck %s --check-prefix=CHECK584 85# CHECK5: [Nr] Name Type Address Off Size ES Flg Lk Inf Al86# CHECK5-NEXT: [ 0] NULL [[#%x,]] [[#%x,]] 00000087# CHECK5-NEXT: [ 1] .text PROGBITS [[#%x,]] [[#%x,]] 000001 00 AX 0 0 488# CHECK5-NEXT: [ 2] .data PROGBITS [[#%x,]] [[#%x,]] 000001 00 WA 0 0 189# CHECK5-NEXT: [ 3] .foo.data PROGBITS [[#%x,]] [[#%x,]] 000001 00 WA 0 0 190# CHECK5-NEXT: [ 4] .foo.text PROGBITS [[#%x,]] [[#%x,]] 000001 00 AX 0 0 191# CHECK5-NEXT: [ 5] .comment PROGBITS {{.*}}92 93 94#--- a.s95.globl _start96_start:97 98.section .foo.text,"ax"; .byte 199.section .foo.data,"aw"; .byte 2100.section .text.1,"ax"; .byte 3101.section .data.1,"aw"; .byte 4102 103#--- main.lds104SECTIONS {105 .data : { *(.data*) }106 .foo.data : { *(.foo.data) }107 .text : { *(.text*) }108 .foo.text : ALIGN(16) { *(.foo.text) }109}110 111#--- overwrite1.lds112OVERWRITE_SECTIONS {113 .foo.text : ALIGN(8) { *(.foo.data .foo.text) }114}115 116#--- overwrite2.lds117OVERWRITE_SECTIONS {118 .foo.data : { FOO_DATA_START = .; *(.foo.data) FOO_DATA_END = .; }119 .foo.text : { FOO_TEXT_START = .; *(.foo.text) FOO_TEXT_END = .; }120}121 122#--- overwrite3.lds123OVERWRITE_SECTIONS {124 .foo.data : {}125}126 127#--- insert.lds128SECTIONS { .foo.text : {} } INSERT AFTER .foo.data;129 130#--- err1.lds131## TODO Fix the diagnostic 'malformed number'132# RUN: not ld.lld %t/err1.lds %t/a.o -o /dev/null 2>&1 | FileCheck %s -DFILE=%t/err1.lds --check-prefix=ERR1133# ERR1: error: [[FILE]]:[[#@LINE+2]]: malformed number: =134OVERWRITE_SECTIONS {135 A = 1;136}137