From 82482e709f028d78c584be884b29f8e55d5aeb44 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Fri, 13 May 2022 11:53:03 -0700 Subject: [PATCH] [ELF][test] Clean up linkerscript/{filename-spec.s,group.s} --- .../ELF/linkerscript/Inputs/filename-spec.s | 2 - lld/test/ELF/linkerscript/filename-spec.s | 107 +++++++++--------- lld/test/ELF/linkerscript/group.s | 70 ++++++------ 3 files changed, 88 insertions(+), 91 deletions(-) delete mode 100644 lld/test/ELF/linkerscript/Inputs/filename-spec.s diff --git a/lld/test/ELF/linkerscript/Inputs/filename-spec.s b/lld/test/ELF/linkerscript/Inputs/filename-spec.s deleted file mode 100644 index a688b4db4b60..000000000000 --- a/lld/test/ELF/linkerscript/Inputs/filename-spec.s +++ /dev/null @@ -1,2 +0,0 @@ -.section .foo,"a" - .quad 0x11 diff --git a/lld/test/ELF/linkerscript/filename-spec.s b/lld/test/ELF/linkerscript/filename-spec.s index 82fc4f4c7465..25f899eec03e 100644 --- a/lld/test/ELF/linkerscript/filename-spec.s +++ b/lld/test/ELF/linkerscript/filename-spec.s @@ -1,80 +1,79 @@ # REQUIRES: x86 -# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %tx.o -# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux \ -# RUN: %p/Inputs/filename-spec.s -o %ty.o +# RUN: rm -rf %t && split-file %s %t +# RUN: cd %t && mkdir dir0 dir1 dir2 +# RUN: llvm-mc -filetype=obj -triple=x86_64 tx.s -o tx.o +# RUN: llvm-mc -filetype=obj -triple=x86_64 ty.s -o ty.o -# RUN: echo "SECTIONS{.foo :{ KEEP(*x.o(.foo)) KEEP(*y.o(.foo)) }}" > %t1.script -# RUN: ld.lld -o %t1 --script %t1.script %tx.o %ty.o -# RUN: llvm-objdump -s %t1 | FileCheck --check-prefix=FIRSTY %s +# RUN: echo 'SECTIONS{.foo :{ KEEP(*x.o(.foo)) KEEP(*y.o(.foo)) }}' > 1.t +# RUN: ld.lld -o 1 -T 1.t tx.o ty.o +# RUN: llvm-objdump -s 1 | FileCheck --check-prefix=FIRSTY %s # FIRSTY: Contents of section .foo: # FIRSTY-NEXT: 01000000 00000000 11000000 00000000 -# RUN: echo "SECTIONS{.foo :{ KEEP(*y.o(.foo)) KEEP(*x.o(.foo)) }}" > %t2.script -# RUN: ld.lld -o %t2 --script %t2.script %tx.o %ty.o -# RUN: llvm-objdump -s %t2 | FileCheck --check-prefix=SECONDFIRST %s +# RUN: echo 'SECTIONS{.foo :{ KEEP(*y.o(.foo)) KEEP(*x.o(.foo)) }}' > 2.t +# RUN: ld.lld -o 2 -T 2.t tx.o ty.o +# RUN: llvm-objdump -s 2 | FileCheck --check-prefix=SECONDFIRST %s # SECONDFIRST: Contents of section .foo: # SECONDFIRST-NEXT: 11000000 00000000 01000000 00000000 ## Now the same tests but without KEEP. Checking that file name inside ## KEEP is parsed fine. -# RUN: echo "SECTIONS{.foo :{ *x.o(.foo) *y.o(.foo) }}" > %t3.script -# RUN: ld.lld -o %t3 --script %t3.script %tx.o %ty.o -# RUN: llvm-objdump -s %t3 | FileCheck --check-prefix=FIRSTY %s +# RUN: echo 'SECTIONS{.foo :{ *x.o(.foo) *y.o(.foo) }}' > 3.t +# RUN: ld.lld -o 3 -T 3.t tx.o ty.o +# RUN: llvm-objdump -s 3 | FileCheck --check-prefix=FIRSTY %s -# RUN: echo "SECTIONS{.foo :{ *y.o(.foo) *x.o(.foo) }}" > %t4.script -# RUN: ld.lld -o %t4 --script %t4.script %tx.o %ty.o -# RUN: llvm-objdump -s %t4 | FileCheck --check-prefix=SECONDFIRST %s +# RUN: echo 'SECTIONS{.foo :{ *y.o(.foo) *x.o(.foo) }}' > 4.t +# RUN: ld.lld -o 4 -T 4.t tx.o ty.o +# RUN: llvm-objdump -s 4 | FileCheck --check-prefix=SECONDFIRST %s -# RUN: rm -rf %t.dir && mkdir -p %t.dir -# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.dir/filename-spec1.o -# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux \ -# RUN: %p/Inputs/filename-spec.s -o %t.dir/filename-spec2.o +# RUN: cp tx.o dir0/filename-spec1.o +# RUN: cp ty.o dir0/filename-spec2.o -# RUN: echo "SECTIONS{.foo :{ \"%/t.dir/filename-spec2.o\"(.foo) \"%/t.dir/filename-spec1.o\"(.foo) }}" > %t5.script -# RUN: ld.lld -o %t5 --script %t5.script \ -# RUN: %/t.dir/filename-spec1.o %/t.dir/filename-spec2.o -# RUN: llvm-objdump -s %t5 | FileCheck --check-prefix=SECONDFIRST %s +# RUN: echo 'SECTIONS{.foo :{ "dir0/filename-spec2.o"(.foo) "dir0/filename-spec1.o"(.foo) }}' > 5.t +# RUN: ld.lld -o 5 -T 5.t dir0/filename-spec1.o dir0/filename-spec2.o +# RUN: llvm-objdump -s 5 | FileCheck --check-prefix=SECONDFIRST %s -# RUN: echo "SECTIONS{.foo :{ \"%/t.dir/filename-spec1.o\"(.foo) \"%/t.dir/filename-spec2.o\"(.foo) }}" > %t6.script -# RUN: ld.lld -o %t6 --script %t6.script \ -# RUN: %/t.dir/filename-spec1.o %/t.dir/filename-spec2.o -# RUN: llvm-objdump -s %t6 | FileCheck --check-prefix=FIRSTY %s +# RUN: echo 'SECTIONS{.foo :{ "dir0/filename-spec1.o"(.foo) "dir0/filename-spec2.o"(.foo) }}' > 6.t +# RUN: ld.lld -o 6 -T 6.t dir0/filename-spec1.o dir0/filename-spec2.o +# RUN: llvm-objdump -s 6 | FileCheck --check-prefix=FIRSTY %s -# RUN: mkdir -p %t.testdir1 %t.testdir2 -# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.testdir1/filename-spec1.o -# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux \ -# RUN: %p/Inputs/filename-spec.s -o %t.testdir2/filename-spec2.o -# RUN: rm -f %t.testdir1/lib1.a %t.testdir2/lib2.a -# RUN: llvm-ar rsc %t.testdir1/lib1.a %t.testdir1/filename-spec1.o -# RUN: llvm-ar rsc %t.testdir2/lib2.a %t.testdir2/filename-spec2.o +# RUN: cp tx.o dir1/filename-spec1.o +# RUN: cp ty.o dir2/filename-spec2.o +# RUN: llvm-ar rc dir1/lib1.a dir1/filename-spec1.o +# RUN: llvm-ar rc dir2/lib2.a dir2/filename-spec2.o -# Verify matching of archive library names. -# RUN: echo "SECTIONS{.foo :{ *lib2*(.foo) *lib1*(.foo) }}" > %t7.script -# RUN: ld.lld -o %t7 --script %t7.script --whole-archive \ -# RUN: %t.testdir1/lib1.a %t.testdir2/lib2.a -# RUN: llvm-objdump -s %t7 | FileCheck --check-prefix=SECONDFIRST %s +## Verify matching of archive library names. +# RUN: echo 'SECTIONS{.foo :{ *lib2*(.foo) *lib1*(.foo) }}' > 7.t +# RUN: ld.lld -o 7 -T 7.t --whole-archive \ +# RUN: dir1/lib1.a dir2/lib2.a +# RUN: llvm-objdump -s 7 | FileCheck --check-prefix=SECONDFIRST %s -# Verify matching directories. -# RUN: echo "SECTIONS{.foo :{ *testdir2*(.foo) *testdir1*(.foo) }}" > %t8.script -# RUN: ld.lld -o %t8 --script %t8.script --whole-archive \ -# RUN: %t.testdir1/lib1.a %t.testdir2/lib2.a -# RUN: llvm-objdump -s %t8 | FileCheck --check-prefix=SECONDFIRST %s +## Verify matching directories. +# RUN: echo 'SECTIONS{.foo :{ *dir2*(.foo) *dir1*(.foo) }}' > 8.t +# RUN: ld.lld -o 8 -T 8.t --whole-archive \ +# RUN: dir1/lib1.a dir2/lib2.a +# RUN: llvm-objdump -s 8 | FileCheck --check-prefix=SECONDFIRST %s -# Verify matching of archive library names in KEEP. -# RUN: echo "SECTIONS{.foo :{ KEEP(*lib2*(.foo)) KEEP(*lib1*(.foo)) }}" > %t9.script -# RUN: ld.lld -o %t9 --script %t9.script --whole-archive \ -# RUN: %t.testdir1/lib1.a %t.testdir2/lib2.a -# RUN: llvm-objdump -s %t9 | FileCheck --check-prefix=SECONDFIRST %s +## Verify matching of archive library names in KEEP. +# RUN: echo 'SECTIONS{.foo :{ KEEP(*lib2*(.foo)) KEEP(*lib1*(.foo)) }}' > 9.t +# RUN: ld.lld -o 9 -T 9.t --whole-archive \ +# RUN: dir1/lib1.a dir2/lib2.a +# RUN: llvm-objdump -s 9 | FileCheck --check-prefix=SECONDFIRST %s -# Verify matching directories in KEEP. -# RUN: echo "SECTIONS{.foo :{ KEEP(*testdir2*(.foo)) KEEP(*testdir1*(.foo)) }}" > %t10.script -# RUN: ld.lld -o %t10 --script %t10.script --whole-archive \ -# RUN: %t.testdir1/lib1.a %t.testdir2/lib2.a -# RUN: llvm-objdump -s %t10 | FileCheck --check-prefix=SECONDFIRST %s +## Verify matching directories in KEEP. +# RUN: echo 'SECTIONS{.foo :{ KEEP(*dir2*(.foo)) KEEP(*dir1*(.foo)) }}' > 10.t +# RUN: ld.lld -o 10 -T 10.t --whole-archive \ +# RUN: dir1/lib1.a dir2/lib2.a +# RUN: llvm-objdump -s 10 | FileCheck --check-prefix=SECONDFIRST %s +#--- tx.s .global _start _start: nop .section .foo,"a" .quad 1 + +#--- ty.s +.section .foo,"a" + .quad 0x11 diff --git a/lld/test/ELF/linkerscript/group.s b/lld/test/ELF/linkerscript/group.s index 14d39559de71..89b09e529f46 100644 --- a/lld/test/ELF/linkerscript/group.s +++ b/lld/test/ELF/linkerscript/group.s @@ -1,64 +1,64 @@ # REQUIRES: x86 # UNSUPPORTED: system-windows -# RUN: mkdir -p %t.dir -# RUN: rm -f %t.dir/libxyz.a -# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t -# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux \ -# RUN: %p/Inputs/libsearch-st.s -o %t2.o -# RUN: llvm-ar rcs %t.dir/libxyz.a %t2.o +# RUN: rm -rf %t.dir && mkdir %t.dir +# RUN: rm -rf %t && split-file %s %t && cd %t +# RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o a.o +# RUN: llvm-mc -filetype=obj -triple=x86_64 %p/Inputs/libsearch-st.s -o b.o +# RUN: llvm-ar rc %t.dir/libxyz.a b.o -# RUN: echo "GROUP(\"%t\")" > %t.script -# RUN: ld.lld -o %t2 %t.script +# RUN: echo 'GROUP("a.o")' > %t.t +# RUN: ld.lld -o %t2 %t.t # RUN: llvm-readobj %t2 > /dev/null -# RUN: echo "INPUT(\"%t\")" > %t.script -# RUN: ld.lld -o %t2 %t.script +# RUN: echo 'INPUT("a.o")' > %t.t +# RUN: ld.lld -o %t2 %t.t # RUN: llvm-readobj %t2 > /dev/null -# RUN: echo "GROUP(\"%t\" libxyz.a )" > %t.script -# RUN: not ld.lld -o /dev/null %t.script 2>/dev/null -# RUN: ld.lld -o %t2 %t.script -L%t.dir +# RUN: echo 'GROUP("a.o" libxyz.a )' > %t.t +# RUN: not ld.lld -o /dev/null %t.t 2>/dev/null +# RUN: ld.lld -o %t2 %t.t -L%t.dir # RUN: llvm-readobj %t2 > /dev/null -# RUN: echo "GROUP(\"%t\" =libxyz.a )" > %t.script -# RUN: not ld.lld -o /dev/null %t.script 2>/dev/null -# RUN: ld.lld -o %t2 %t.script --sysroot=%t.dir +# RUN: echo 'GROUP("a.o" =libxyz.a )' > %t.t +# RUN: not ld.lld -o /dev/null %t.t 2>/dev/null +# RUN: ld.lld -o %t2 %t.t --sysroot=%t.dir # RUN: llvm-readobj %t2 > /dev/null -# RUN: echo "GROUP(\"%t\" -lxyz )" > %t.script -# RUN: not ld.lld -o /dev/null %t.script 2>/dev/null -# RUN: ld.lld -o %t2 %t.script -L%t.dir +# RUN: echo 'GROUP("a.o" -lxyz )' > %t.t +# RUN: not ld.lld -o /dev/null %t.t 2>/dev/null +# RUN: ld.lld -o %t2 %t.t -L%t.dir # RUN: llvm-readobj %t2 > /dev/null -# RUN: echo "GROUP(\"%t\" libxyz.a )" > %t.script -# RUN: not ld.lld -o /dev/null %t.script 2>/dev/null -# RUN: ld.lld -o %t2 %t.script -L%t.dir +# RUN: echo 'GROUP("a.o" libxyz.a )' > %t.t +# RUN: not ld.lld -o /dev/null %t.t 2>/dev/null +# RUN: ld.lld -o %t2 %t.t -L%t.dir # RUN: llvm-readobj %t2 > /dev/null -# RUN: echo "GROUP(\"%t\" /libxyz.a )" > %t.script -# RUN: echo "GROUP(\"%t\" /libxyz.a )" > %t.dir/xyz.script -# RUN: not ld.lld -o /dev/null %t.script 2>&1 | FileCheck %s --check-prefix=CANNOT_OPEN -DFILE=/libxyz.a -# RUN: not ld.lld -o /dev/null %t.script --sysroot=%t.dir 2>&1 | FileCheck %s --check-prefix=CANNOT_OPEN -DFILE=/libxyz.a +# RUN: echo 'GROUP("a.o" /libxyz.a )' > %t.t +# RUN: echo 'GROUP("%t/a.o" /libxyz.a )' > %t.dir/xyz.t +# RUN: not ld.lld -o /dev/null %t.t 2>&1 | FileCheck %s --check-prefix=CANNOT_OPEN -DFILE=/libxyz.a +# RUN: not ld.lld -o /dev/null %t.t --sysroot=%t.dir 2>&1 | FileCheck %s --check-prefix=CANNOT_OPEN -DFILE=/libxyz.a ## Since %t.dir/%t does not exist, report an error, instead of falling back to %t ## without the syroot prefix. -# RUN: not ld.lld -o /dev/null %t.dir/xyz.script --sysroot=%t.dir 2>&1 | FileCheck %s --check-prefix=CANNOT_FIND_SYSROOT -DTMP=%t +# RUN: not ld.lld -o /dev/null %t.dir/xyz.t --sysroot=%t.dir 2>&1 | FileCheck %s --check-prefix=CANNOT_FIND_SYSROOT -DTMP=%t/a.o -# CANNOT_FIND_SYSROOT: error: {{.*}}xyz.script:1: cannot find [[TMP]] inside [[TMP]].dir +# CANNOT_FIND_SYSROOT: error: {{.*}}xyz.t:1: cannot find [[TMP]] inside {{.*}}.dir # CANNOT_FIND_SYSROOT-NEXT: >>> GROUP({{.*}} -# RUN: echo "GROUP(\"%t.script2\")" > %t.script1 -# RUN: echo "GROUP(\"%t\")" > %t.script2 -# RUN: ld.lld -o %t2 %t.script1 -# RUN: llvm-readobj %t2 > /dev/null +# RUN: echo 'GROUP("2.t")' > 1.t +# RUN: echo 'GROUP("a.o")' > 2.t +# RUN: ld.lld 1.t +# RUN: llvm-readobj a.out > /dev/null -# RUN: echo "GROUP(AS_NEEDED(\"%t\"))" > %t.script -# RUN: ld.lld -o %t2 %t.script -# RUN: llvm-readobj %t2 > /dev/null +# RUN: echo 'GROUP(AS_NEEDED("a.o"))' > 1.t +# RUN: ld.lld 1.t +# RUN: llvm-readobj a.out > /dev/null # CANNOT_OPEN: error: cannot open [[FILE]]: {{.*}} +#--- a.s .globl _start _start: ret