1# REQUIRES: x86 2# RUN: split-file %s %t 3# RUN: llvm-mc -filetype=obj -triple=x86_64 %t/t.s -o %t.o 4 5## PR52534: https://bugs.llvm.org/show_bug.cgi?id=52534 6## Check case where .preinit_array would be discarded in the absence of the 7## start/stop symbols. 8## Link should succeed without causing an out of range relocation error. 9# RUN: ld.lld -T %t/discarded.script %t.o -o %t1 --image-base=0x80000000 10# RUN: llvm-readelf -s %t1 | FileCheck --check-prefixes=CHECK,DISCARDED %s 11 12## Check case where .preinit_array is emitted but empty. 13# RUN: ld.lld -T %t/empty.script %t.o -o %t2 14# RUN: llvm-readelf -s %t2 | FileCheck --check-prefixes=CHECK,EMPTY %s 15 16# CHECK: [[#%x,ADDR:]] 0 NOTYPE LOCAL HIDDEN [[#]] __preinit_array_start 17# CHECK-NEXT: [[#ADDR]] 0 NOTYPE LOCAL HIDDEN [[#]] __preinit_array_end 18 19# DISCARDED-NEXT: {{0*}}[[#ADDR-14]] 0 NOTYPE GLOBAL DEFAULT [[#]] _start 20 21# EMPTY-NOT: [[#ADDR]] 0 NOTYPE GLOBAL DEFAULT [[#]] _start 22# EMPTY: [[#ADDR]] 0 NOTYPE GLOBAL DEFAULT [[#]] ADDR 23 24#--- t.s 25.global _start 26_start: 27 movq __preinit_array_start@GOTPCREL(%rip),%rax 28 movq __preinit_array_end@GOTPCREL(%rip),%rax 29 30.section .rodata,"a" 31.byte 0 32 33#--- discarded.script 34SECTIONS { 35 .rodata : { *(.rodata); } 36 .text : { *(.text); } 37 .preinit_array : { *(.preinit_array); } 38} 39 40#--- empty.script 41SECTIONS { 42 .text : { *(.text); } 43 .preinit_array : { ADDR = .; *(.preinit_array); } 44} 45