[lld] lld: add support for NOCROSSREFS(_TO) (PR #95714)

Pavel Skripkin via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 21 12:27:14 PDT 2024


================
@@ -0,0 +1,149 @@
+// REQUIRES: x86
+
+// RUN: llvm-mc --triple=x86_64-unknown-linux -filetype=obj -o %t.o %s
+// RUN: echo "NOCROSSREFS(.text .text1); \
+// RUN:       SECTIONS { \
+// RUN:         .text  : { *(.text) } \
+// RUN:         .text1 : { *(.text1) } \
+// RUN:         .text2 : { *(.text2) } \
+// RUN: } " > %t.script
+// RUN: not ld.lld %t.o -o %t --script %t.script 2>&1 | FileCheck -check-prefix=ERR %s
+// ERR: ld.lld: error: {{.*}}.o:(.text+{{.*}}): prohibited cross reference from .text to in .text1
+
+// RUN: llvm-mc --triple=x86_64-unknown-linux -filetype=obj -o %t.o %s
+// RUN: echo "NOCROSSREFS_TO(.text1 .text); \
+// RUN:       SECTIONS { \
+// RUN:         .text  : { *(.text) } \
+// RUN:         .text1 : { *(.text1) } \
+// RUN:         .text2 : { *(.text2) } \
+// RUN: } " > %t.script
+// RUN: not ld.lld %t.o -o %t --script %t.script 2>&1 | FileCheck -check-prefix=ERR1 %s
+// ERR1: ld.lld: error: {{.*}}.o:(.text+{{.*}}): prohibited cross reference from .text to in .text1
+
+// RUN: llvm-mc --triple=x86_64-unknown-linux -filetype=obj -o %t.o %s
+// RUN: echo "NOCROSSREFS(.text1 .text .text2); \
+// RUN:       SECTIONS { \
+// RUN:         .text  : { *(.text) } \
+// RUN:         .text1 : { *(.text1) } \
+// RUN:         .text2 : { *(.text2) } \
+// RUN: } " > %t.script
+// RUN: not ld.lld %t.o -o %t --script %t.script 2>&1 | FileCheck -check-prefix=ERR2 %s
+// ERR2: ld.lld: error: {{.*}}.o:(.text+{{.*}}): prohibited cross reference from .text to in .text1
+
+// RUN: llvm-mc --triple=x86_64-unknown-linux -filetype=obj -o %t.o %s
+// RUN: echo "NOCROSSREFS_TO(.text .text1); \
+// RUN:       SECTIONS { \
+// RUN:         .text  : { *(.text) } \
+// RUN:         .text1 : { *(.text1) } \
+// RUN:         .text2 : { *(.text2) } \
+// RUN: } " > %t.script
+// RUN: ld.lld %t.o -o %t --script %t.script 2>&1
+
+// RUN: llvm-mc --triple=x86_64-unknown-linux -filetype=obj -o %t.o %s
+// RUN: echo "NOCROSSREFS_TO(); \
+// RUN:       SECTIONS { \
+// RUN:         .text  : { *(.text) } \
+// RUN:         .text1 : { *(.text1) } \
+// RUN:         .text2 : { *(.text2) } \
+// RUN: } " > %t.script
+// RUN: ld.lld %t.o -o %t --script %t.script 2>&1
+
+// RUN: llvm-mc --triple=x86_64-unknown-linux -filetype=obj -o %t.o %s
+// RUN: echo "NOCROSSREFS(); \
+// RUN:       SECTIONS { \
+// RUN:         .text  : { *(.text) } \
+// RUN:         .text1 : { *(.text1) } \
+// RUN:         .text2 : { *(.text2) } \
+// RUN: } " > %t.script
+// RUN: ld.lld %t.o -o %t --script %t.script 2>&1
+
+// RUN: llvm-mc --triple=x86_64-unknown-linux -filetype=obj -o %t.o %s
+// RUN: echo "NOCROSSREFS(.text); \
+// RUN:       SECTIONS { \
+// RUN:         .text  : { *(.text) } \
+// RUN:         .text1 : { *(.text1) } \
+// RUN:         .text2 : { *(.text2) } \
+// RUN: } " > %t.script
+// RUN: ld.lld %t.o -o %t --script %t.script 2>&1
+
+// RUN: llvm-mc --triple=x86_64-unknown-linux -filetype=obj -o %t.o %s
+// RUN: echo "NOCROSSREFS_TO(.text); \
+// RUN:       SECTIONS { \
+// RUN:         .text  : { *(.text) } \
+// RUN:         .text1 : { *(.text1) } \
+// RUN:         .text2 : { *(.text2) } \
+// RUN: } " > %t.script
+// RUN: ld.lld %t.o -o %t --script %t.script 2>&1
+
+// RUN: llvm-mc --triple=x86_64-unknown-linux -filetype=obj -o %t.o %s
+// RUN: echo "NOCROSSREFS_TO(.text2 .text); \
+// RUN:       SECTIONS { \
+// RUN:         .text  : { *(.text) } \
+// RUN:         .text1 : { *(.text1) } \
+// RUN:         .text2 : { *(.text2) } \
+// RUN: } " > %t.script
+// RUN: ld.lld %t.o -o %t --script %t.script 2>&1
+
+// RUN: llvm-mc --triple=x86_64-unknown-linux -filetype=obj -o %t.o %s
+// RUN: echo "NOCROSSREFS(.text .text2); \
+// RUN:       SECTIONS { \
+// RUN:         .text  : { *(.text) } \
+// RUN:         .text1 : { *(.text1) } \
+// RUN:         .text2 : { *(.text2) } \
+// RUN: } " > %t.script
+// RUN: ld.lld %t.o -o %t --script %t.script 2>&1
+
+// RUN: llvm-mc --triple=x86_64-unknown-linux -filetype=obj -o %t.o %s
+// RUN: echo "NOCROSSREFS(.text .text2); \
+// RUN:       SECTIONS { \
+// RUN:          foo = ABSOLUTE(.); \
+// RUN:         .text  : { *(.text) } \
+// RUN:         .text1 : { *(.text1) } \
+// RUN:         .text2 : { *(.text2) } \
+// RUN: } " > %t.script
+// RUN: ld.lld %t.o -o %t --script %t.script 2>&1
+
+// RUN: llvm-mc --triple=x86_64-unknown-linux -filetype=obj -o %t.o %s
+// RUN: echo "NOCROSSREFS(.text .text2); \
+// RUN:       SECTIONS { \
+// RUN:         .text  : { *(.text) } \
+// RUN:         .text1 : { *(.text1) } \
+// RUN:         .text2 : { *(.text2) } \
+// RUN:         .bss   : { *(.unused) } \
+// RUN: } " > %t.script
+// RUN: ld.lld %t.o -o %t --script %t.script 2>&1
+
+// RUN: llvm-mc --triple=x86_64-unknown-linux -filetype=obj -o %t.o %s
+// RUN: echo "NOCROSSREFS(.text .bss); \
+// RUN:       SECTIONS { \
+// RUN:         .text  : { *(.text) } \
+// RUN:         .text1 : { *(.text1) } \
+// RUN:         .text2 : { *(.text2) } \
+// RUN:         .bss   : { *(.unused) } \
+// RUN: } " > %t.script
+// RUN: not ld.lld %t.o -o %t --script %t.script 2>&1 | FileCheck -check-prefix=ERR3 %s
+// ERR3: ld.lld: error: {{.*}}.o:(.text+{{.*}}): prohibited cross reference from .text to unused in .bss
----------------
pskrgag wrote:

I guess, I get it, thanks for the tip. 
Please check newest version

https://github.com/llvm/llvm-project/pull/95714


More information about the llvm-commits mailing list