1# REQUIRES: x86 2## SHF_GNU_RETAIN is a generic feature defined in the OS specific range. The 3## flag marks a section as a GC root. 4 5# RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t.o 6# RUN: ld.lld --gc-sections --print-gc-sections %t.o -o %t | count 0 7# RUN: llvm-readobj -hS %t | FileCheck %s 8# RUN: ld.lld -r -e _start --gc-sections --print-gc-sections %t.o -o %t.ro | count 0 9# RUN: llvm-readobj -hS %t.ro | FileCheck %s 10 11# CHECK: Name: .retain 12# CHECK-NEXT: Type: SHT_PROGBITS 13# CHECK-NEXT: Flags [ 14# CHECK-NEXT: SHF_ALLOC 15# CHECK-NEXT: SHF_GNU_RETAIN 16# CHECK-NEXT: ] 17 18# RUN: llvm-mc -filetype=obj -triple=x86_64 --defsym NONALLOC=1 %s -o %t1.o 19# RUN: not ld.lld --gc-sections %t1.o -o /dev/null 2>&1 | FileCheck %s --check-prefix=ERR 20 21# ERR: error: {{.*}}.o:(.nonalloc): sh_link points to discarded section {{.*}}.o:(.discard) 22 23.global _start 24_start: 25 26.section .retain,"aR",@progbits 27.quad .foo 28 29.section .foo,"a",@progbits 30.quad 0 31 32.ifdef NONALLOC 33.section .discard,"a",@progbits 34 35## With SHF_GNU_RETAIN, .nonalloc is retained while its linked-to section 36## .discard is discarded, so there will be an error. 37.section .nonalloc,"oR",@progbits,.discard 38.quad .text 39.endif 40