brintos

brintos / llvm-project-archived public Read only

0
0
Text · 6.7 KiB · 453017e Raw
113 lines · plain
1# REQUIRES: x862 3# RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t1.o4# RUN: echo '.globl foo; foo:' | llvm-mc -filetype=obj -triple=x86_64 - -o %t2.o5# RUN: rm -f %t2.a6# RUN: llvm-ar rcs %t2.a %t2.o7# RUN: ld.lld -shared %t2.o -o %t2.so8 9## A forward reference is accepted by a traditional Unix linker.10# RUN: ld.lld --fatal-warnings %t1.o %t2.a -o /dev/null11# RUN: ld.lld --fatal-warnings --warn-backrefs %t1.o %t2.a -o /dev/null12# RUN: ld.lld --fatal-warnings --warn-backrefs %t1.o --start-lib %t2.o --end-lib -o /dev/null13 14# RUN: echo 'INPUT("%t1.o" "%t2.a")' > %t1.lds15# RUN: ld.lld --fatal-warnings --warn-backrefs %t1.lds -o /dev/null16 17## A backward reference from %t1.o to %t2.a18## Warn unless the archive is excluded by --warn-backrefs-exclude19# RUN: ld.lld --fatal-warnings %t2.a %t1.o -o /dev/null20# RUN: ld.lld --warn-backrefs %t2.a %t1.o -o /dev/null 2>&1 | FileCheck %s21# RUN: ld.lld --warn-backrefs --no-warn-backrefs %t2.a %t1.o -o /dev/null 2>&1 | count 022# RUN: ld.lld --warn-backrefs %t2.a '-(' %t1.o '-)' -o /dev/null 2>&1 | FileCheck %s23# RUN: ld.lld --warn-backrefs --warn-backrefs-exclude='*3.a' %t2.a %t1.o -o /dev/null 2>&1 | FileCheck %s24# RUN: ld.lld --fatal-warnings --warn-backrefs --warn-backrefs-exclude='*2.a(*2.o)' %t2.a %t1.o -o /dev/null25# RUN: ld.lld --fatal-warnings --warn-backrefs --warn-backrefs-exclude '*2.a(*2.o)' \26# RUN:   --warn-backrefs-exclude not_exist %t2.a %t1.o -o /dev/null27## Without --warn-backrefs, --warn-backrefs-exclude is ignored.28# RUN: ld.lld --fatal-warnings --warn-backrefs-exclude=not_exist %t2.a %t1.o -o /dev/null29 30## Placing the definition and the backward reference in a group can suppress the warning.31# RUN: echo 'GROUP("%t2.a" "%t1.o")' > %t2.lds32# RUN: ld.lld --fatal-warnings --warn-backrefs %t2.lds -o /dev/null33# RUN: ld.lld --fatal-warnings --warn-backrefs '-(' %t2.a %t1.o '-)' -o /dev/null34# RUN: ld.lld --fatal-warnings --warn-backrefs --start-group %t2.a %t1.o --end-group -o /dev/null35 36## A backward reference from %t1.o to %t2.a (added by %t3.lds).37# RUN: echo 'GROUP("%t2.a")' > %t3.lds38# RUN: ld.lld --warn-backrefs %t3.lds %t1.o -o /dev/null 2>&1 | FileCheck %s39# RUN: ld.lld --fatal-warnings --warn-backrefs '-(' %t3.lds %t1.o '-)' -o /dev/null40# RUN: ld.lld --fatal-warnings --warn-backrefs --warn-backrefs-exclude='*2.a(*2.o)' -o /dev/null %t3.lds %t1.o41## If a lazy definition appears after the backward reference, don't warn.42# RUN: ld.lld --fatal-warnings --warn-backrefs %t3.lds %t1.o %t3.lds -o /dev/null43 44# CHECK: warning: backward reference detected: foo in {{.*}}1.o refers to {{.*}}2.a45 46## A backward reference from %t1.o to %t2.o47## --warn-backrefs-exclude= applies to --start-lib covered object files.48# RUN: ld.lld --warn-backrefs --start-lib %t2.o --end-lib %t1.o -o /dev/null 2>&1 | \49# RUN:   FileCheck --check-prefix=OBJECT %s50# RUN: ld.lld --fatal-warnings --warn-backrefs --warn-backrefs-exclude=%/t2.o --start-lib %/t2.o --end-lib %t1.o -o /dev/null51## If a lazy definition appears after the backward reference, don't warn.52# RUN: ld.lld --fatal-warnings --warn-backrefs --start-lib %t2.o --end-lib %t1.o --start-lib %t2.o --end-lib -o /dev/null53 54# OBJECT: warning: backward reference detected: foo in {{.*}}1.o refers to {{.*}}2.o55 56## Back reference from an fetched --start-lib to a previous --start-lib.57# RUN: ld.lld -m elf_x86_64 -u _start --warn-backrefs --start-lib %/t2.o --end-lib \58# RUN:   --start-lib %t1.o --end-lib -o /dev/null 2>&1 | FileCheck --check-prefix=OBJECT %s59## --warn-backrefs-exclude=%/t2.o can be used for a fetched --start-lib.60# RUN: ld.lld --fatal-warnings -m elf_x86_64 -u _start --warn-backrefs --warn-backrefs-exclude=%/t2.o --start-lib %/t2.o --end-lib --start-lib %t1.o --end-lib -o /dev/null61 62## Don't warn if the definition and the backward reference are in a group.63# RUN: echo '.globl bar; bar:' | llvm-mc -filetype=obj -triple=x86_64 - -o %t3.o64# RUN: echo '.globl foo; foo: call bar' | llvm-mc -filetype=obj -triple=x86_64 - -o %t4.o65# RUN: ld.lld --fatal-warnings --warn-backrefs %t1.o --start-lib %t3.o %t4.o --end-lib -o /dev/null66# RUN: rm -f %t34.a && llvm-ar rcS %t34.a %t3.o %t4.o67# RUN: ld.lld --fatal-warnings --warn-backrefs %t1.o %t34.a -o /dev/null68 69## We don't report backward references to weak symbols as they can be overridden later.70# RUN: echo '.weak foo; foo:' | llvm-mc -filetype=obj -triple=x86_64 - -o %tweak.o71# RUN: ld.lld --fatal-warnings --warn-backrefs --start-lib %tweak.o --end-lib %t1.o %t2.o -o /dev/null72 73## Check common symbols. A common sym might later be replaced by a non-common definition.74# RUN: echo '.comm obj, 4' | llvm-mc -filetype=obj -triple=x86_64 -o %tcomm.o75# RUN: echo '.type obj,@object; .data; .globl obj; .p2align 2; obj: .long 55; .size obj, 4' | llvm-mc -filetype=obj -triple=x86_64 -o %tstrong.o76# RUN: echo '.globl foo; foo: movl obj(%rip), %eax' | llvm-mc -triple=x86_64 -filetype=obj -o %t5.o77# RUN: llvm-ar rcs %tcomm.a %tcomm.o78# RUN: llvm-ar rcs %tstrong.a %tstrong.o79# RUN: ld.lld --warn-backrefs %tcomm.a %t1.o %t5.o 2>&1 -o /dev/null | FileCheck --check-prefix=COMM %s80# RUN: ld.lld --fatal-warnings --fortran-common --warn-backrefs %tcomm.a %t1.o %t5.o %tstrong.a 2>&1 -o /dev/null81# RUN: ld.lld --warn-backrefs --no-fortran-common %tcomm.a %t1.o %t5.o %tstrong.a 2>&1 -o /dev/null | FileCheck --check-prefix=COMM %s82 83# COMM: ld.lld: warning: backward reference detected: obj in {{.*}}5.o refers to {{.*}}comm.a84 85## If a lazy definition appears after the backward reference, don't warn.86## A traditional Unix linker will resolve the reference to the later definition.87# RUN: ld.lld --fatal-warnings --warn-backrefs %t2.a %t1.o %t2.a -o /dev/null88 89## lld fetches the archive while GNU ld resolves the reference to the shared definition.90## Warn because the resolution rules are different.91# RUN: ld.lld --warn-backrefs %t2.a %t1.o %t2.so -o /dev/null 2>&1 | FileCheck %s92 93## This is a limitation. The resolution rules are different but94## --warn-backrefs does not warn.95# RUN: ld.lld --fatal-warnings --warn-backrefs %t2.a %t1.o %t2.so %t2.a -o /dev/null96 97## In GNU linkers, -u does not make a backward reference.98# RUN: ld.lld --fatal-warnings --warn-backrefs -u foo %t2.a %t1.o -o /dev/null99 100## -u does not make a backward reference.101# RUN: ld.lld --fatal-warnings --warn-backrefs -u foo %t2.a %t1.o -o /dev/null102 103## --defsym does not make a backward reference, but it does not suppress the warning due to another file.104# RUN: ld.lld --fatal-warnings --warn-backrefs --defsym=x=foo -e 0 %t2.a -o /dev/null105# RUN: ld.lld --warn-backrefs --defsym=x=foo %t2.a %t1.o -o /dev/null 2>&1 | FileCheck %s106 107# RUN: not ld.lld --warn-backrefs-exclude='[' 2>&1 | FileCheck --check-prefix=INVALID %s108# INVALID: error: --warn-backrefs-exclude: invalid glob pattern, unmatched '[': [109 110.globl _start, foo111_start:112  call foo113