[lld] 4b50014 - [ELF] Improve LTO tests
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 19 23:44:46 PST 2024
Author: Fangrui Song
Date: 2024-01-19T23:44:40-08:00
New Revision: 4b500147f071d5ee4abb968f55fc4f411a2d5283
URL: https://github.com/llvm/llvm-project/commit/4b500147f071d5ee4abb968f55fc4f411a2d5283
DIFF: https://github.com/llvm/llvm-project/commit/4b500147f071d5ee4abb968f55fc4f411a2d5283.diff
LOG: [ELF] Improve LTO tests
Make it easy to change --save-temps filenames to follow COFF
(https://reviews.llvm.org/D137217).
Added:
Modified:
lld/test/ELF/lto/emit-asm.ll
lld/test/ELF/lto/obj-path.ll
lld/test/ELF/lto/parallel-internalize.ll
lld/test/ELF/lto/parallel.ll
lld/test/ELF/lto/thinlto.ll
Removed:
lld/test/ELF/lto/thinlto-obj-path.ll
################################################################################
diff --git a/lld/test/ELF/lto/emit-asm.ll b/lld/test/ELF/lto/emit-asm.ll
index 3f635b8dbe7f76..03cf32d904520f 100644
--- a/lld/test/ELF/lto/emit-asm.ll
+++ b/lld/test/ELF/lto/emit-asm.ll
@@ -1,12 +1,13 @@
; REQUIRES: x86
-; RUN: llvm-as %s -o %t.o
-; RUN: ld.lld --lto-emit-asm -shared %t.o -o - | FileCheck %s
-; RUN: ld.lld --plugin-opt=emit-asm --plugin-opt=lto-partitions=2 -shared %t.o -o %t2.s
-; RUN: cat %t2.s %t2.s1 | FileCheck %s
+; RUN: rm -rf %t && mkdir %t && cd %t
+; RUN: llvm-as %s -o a.bc
+; RUN: ld.lld --lto-emit-asm -shared a.bc -o - | FileCheck %s
+; RUN: ld.lld --plugin-opt=emit-asm --plugin-opt=lto-partitions=2 -shared a.bc -o out.s
+; RUN: cat out.s out.s1 | FileCheck %s
-; RUN: ld.lld --lto-emit-asm --save-temps -shared %t.o -o %t3.s
-; RUN: FileCheck --input-file %t3.s %s
-; RUN: llvm-dis %t3.s.0.4.opt.bc -o - | FileCheck --check-prefix=OPT %s
+; RUN: ld.lld --lto-emit-asm --save-temps -shared a.bc -o out.s
+; RUN: FileCheck --input-file out.s %s
+; RUN: llvm-dis out.s.0.4.opt.bc -o - | FileCheck --check-prefix=OPT %s
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
diff --git a/lld/test/ELF/lto/obj-path.ll b/lld/test/ELF/lto/obj-path.ll
index 69c0a21fb79abe..23b593bd36fa8f 100644
--- a/lld/test/ELF/lto/obj-path.ll
+++ b/lld/test/ELF/lto/obj-path.ll
@@ -2,18 +2,19 @@
;; Test --lto-obj-path= for regular LTO.
; RUN: rm -rf %t && split-file %s %t && cd %t
+; RUN: mkdir d
; RUN: opt 1.ll -o 1.bc
-; RUN: opt 2.ll -o 2.bc
+; RUN: opt 2.ll -o d/2.bc
-; RUN: rm -f 4.o
-; RUN: ld.lld --lto-obj-path=4.o -shared 1.bc 2.bc -o 3
+; RUN: rm -f objpath.o
+; RUN: ld.lld --lto-obj-path=objpath.o -shared 1.bc d/2.bc -o 3
; RUN: llvm-nm 3 | FileCheck %s --check-prefix=NM
-; RUN: llvm-objdump -d 4.o | FileCheck %s
-; RUN: ls 3* 4* | count 2
+; RUN: llvm-objdump -d objpath.o | FileCheck %s
+; RUN: ls 3* objpath* | count 2
-; RUN: rm -f 3 4.o
-; RUN: ld.lld --thinlto-index-only=3.txt --lto-obj-path=4.o -shared 1.bc 2.bc -o 3
-; RUN: llvm-objdump -d 4.o | FileCheck %s
+; RUN: rm -f 3 objpath.o
+; RUN: ld.lld --thinlto-index-only=3.txt --lto-obj-path=objpath.o -shared 1.bc d/2.bc -o 3
+; RUN: llvm-objdump -d objpath.o | FileCheck %s
; RUN: not ls 3
; NM: T f
@@ -23,6 +24,59 @@
; CHECK: <f>:
; CHECK: <g>:
+;; Test --lto-obj-path= for ThinLTO.
+; RUN: opt -module-summary 1.ll -o 1.bc
+; RUN: opt -module-summary 2.ll -o d/2.bc
+
+; RUN: ld.lld --plugin-opt=obj-path=objpath.o -shared 1.bc d/2.bc -o 3
+; RUN: llvm-nm 3 | FileCheck %s --check-prefix=NM3
+; RUN: llvm-objdump -d objpath.o1 | FileCheck %s --check-prefix=CHECK1
+; RUN: llvm-objdump -d objpath.o2 | FileCheck %s --check-prefix=CHECK2
+
+; NM3: T f
+; NM3-NEXT: T g
+
+; CHECK1: file format elf64-x86-64
+; CHECK1-EMPTY:
+; CHECK1-NEXT: Disassembly of section .text.f:
+; CHECK1-EMPTY:
+; CHECK1-NEXT: <f>:
+; CHECK1-NEXT: retq
+; CHECK1-NOT: {{.}}
+
+; CHECK2: file format elf64-x86-64
+; CHECK2-EMPTY:
+; CHECK2-NEXT: Disassembly of section .text.g:
+; CHECK2-EMPTY:
+; CHECK2-NEXT: <g>:
+; CHECK2-NEXT: retq
+; CHECK2-NOT: {{.}}
+
+;; With --thinlto-index-only, --lto-obj-path= creates just one file.
+; RUN: rm -f objpath.o objpath.o1 objpath.o2
+; RUN: ld.lld --thinlto-index-only --lto-obj-path=objpath.o -shared 1.bc d/2.bc -o /dev/null
+; RUN: llvm-objdump -d objpath.o | FileCheck %s --check-prefix=EMPTY
+; RUN: not ls objpath.o1
+; RUN: not ls objpath.o2
+
+;; Test --plugin-opt=obj-path=.
+; RUN: rm -f objpath.o
+; RUN: ld.lld --plugin-opt=thinlto-index-only --plugin-opt=obj-path=objpath.o -shared 1.bc d/2.bc -o /dev/null
+; RUN: llvm-objdump -d objpath.o | FileCheck %s --check-prefix=EMPTY
+
+;; Ensure lld emits empty combined module if specific obj-path.
+; RUN: mkdir obj
+; RUN: ld.lld --plugin-opt=obj-path=objpath.o -shared 1.bc d/2.bc -o obj/out --save-temps
+; RUN: ls obj/out.lto.o obj/out1.lto.o obj/out2.lto.o
+
+;; Ensure lld does not emit empty combined module by default.
+; RUN: rm -fr obj && mkdir obj
+; RUN: ld.lld -shared 1.bc d/2.bc -o obj/out --save-temps
+; RUN: ls obj/out*.lto.* | count 2
+
+; EMPTY: file format elf64-x86-64
+; EMPTY-NOT: {{.}}
+
;--- 1.ll
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
diff --git a/lld/test/ELF/lto/parallel-internalize.ll b/lld/test/ELF/lto/parallel-internalize.ll
index 1d3399b92b8257..9cd080360d396b 100644
--- a/lld/test/ELF/lto/parallel-internalize.ll
+++ b/lld/test/ELF/lto/parallel-internalize.ll
@@ -1,11 +1,10 @@
; REQUIRES: x86
-; RUN: llvm-as -o %t.bc %s
-; RUN: rm -f %t.lto.o %t1.lto.o
-; RUN: ld.lld --lto-partitions=2 -save-temps -o %t %t.bc \
-; RUN: -e foo --lto-O0
-; RUN: llvm-readobj --symbols --dyn-syms %t | FileCheck %s
-; RUN: llvm-nm %t.lto.o | FileCheck --check-prefix=CHECK0 %s
-; RUN: llvm-nm %t1.lto.o | FileCheck --check-prefix=CHECK1 %s
+; RUN: rm -rf %t && mkdir %t && cd %t
+; RUN: llvm-as -o a.bc %s
+; RUN: ld.lld --lto-partitions=2 -save-temps -o out a.bc -e foo --lto-O0
+; RUN: llvm-readobj --symbols --dyn-syms out | FileCheck %s
+; RUN: llvm-nm out.lto.o | FileCheck --check-prefix=CHECK0 %s
+; RUN: llvm-nm out1.lto.o | FileCheck --check-prefix=CHECK1 %s
; CHECK: Symbols [
; CHECK-NEXT: Symbol {
diff --git a/lld/test/ELF/lto/parallel.ll b/lld/test/ELF/lto/parallel.ll
index d89431e8b4a16d..c6c9a185677b83 100644
--- a/lld/test/ELF/lto/parallel.ll
+++ b/lld/test/ELF/lto/parallel.ll
@@ -1,11 +1,11 @@
; REQUIRES: x86
-; RUN: llvm-as -o %t.bc %s
-; RUN: rm -f %t.lto.o %t1.lto.o
-; RUN: ld.lld --lto-partitions=2 -save-temps -o %t %t.bc -shared
-; RUN: llvm-nm %t.lto.o | FileCheck --check-prefix=CHECK0 %s
-; RUN: llvm-nm %t1.lto.o | FileCheck --check-prefix=CHECK1 %s
+; RUN: rm -rf %t && mkdir %t && cd %t
+; RUN: llvm-as -o a.bc %s
+; RUN: ld.lld --lto-partitions=2 -save-temps -o out a.bc -shared
+; RUN: llvm-nm out.lto.o | FileCheck --check-prefix=CHECK0 %s
+; RUN: llvm-nm out1.lto.o | FileCheck --check-prefix=CHECK1 %s
-; RUN: not ld.lld --lto-partitions=0 %t.bc -o /dev/null 2>&1 | FileCheck --check-prefix=INVALID %s
+; RUN: not ld.lld --lto-partitions=0 a.bc -o /dev/null 2>&1 | FileCheck --check-prefix=INVALID %s
; INVALID: --lto-partitions: number of threads must be > 0
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
diff --git a/lld/test/ELF/lto/thinlto-obj-path.ll b/lld/test/ELF/lto/thinlto-obj-path.ll
deleted file mode 100644
index 4058dd0f1156a8..00000000000000
--- a/lld/test/ELF/lto/thinlto-obj-path.ll
+++ /dev/null
@@ -1,65 +0,0 @@
-; REQUIRES: x86
-
-; RUN: rm -rf %t && mkdir %t && cd %t
-; RUN: opt -module-summary %s -o 1.bc
-; RUN: opt -module-summary %p/Inputs/thinlto.ll -o 2.bc
-
-; RUN: ld.lld --plugin-opt=obj-path=4.o -shared 1.bc 2.bc -o 3
-; RUN: llvm-nm 3 | FileCheck %s --check-prefix=NM3
-; RUN: llvm-objdump -d 4.o1 | FileCheck %s --check-prefix=CHECK1
-; RUN: llvm-objdump -d 4.o2 | FileCheck %s --check-prefix=CHECK2
-
-; NM3: T f
-; NM3-NEXT: T g
-
-; CHECK1: file format elf64-x86-64
-; CHECK1-EMPTY:
-; CHECK1-NEXT: Disassembly of section .text.f:
-; CHECK1-EMPTY:
-; CHECK1-NEXT: <f>:
-; CHECK1-NEXT: retq
-; CHECK1-NOT: {{.}}
-
-; CHECK2: file format elf64-x86-64
-; CHECK2-EMPTY:
-; CHECK2-NEXT: Disassembly of section .text.g:
-; CHECK2-EMPTY:
-; CHECK2-NEXT: <g>:
-; CHECK2-NEXT: retq
-; CHECK2-NOT: {{.}}
-
-;; With --thinlto-index-only, --lto-obj-path= creates just one file.
-; RUN: rm -f 4.o 4.o1 4.o2
-; RUN: ld.lld --thinlto-index-only --lto-obj-path=4.o -shared 1.bc 2.bc -o /dev/null
-; RUN: llvm-objdump -d 4.o | FileCheck %s --check-prefix=EMPTY
-; RUN: not ls 4.o1
-; RUN: not ls 4.o2
-
-;; Test --plugin-opt=obj-path=.
-; RUN: rm -f 4.o
-; RUN: ld.lld --plugin-opt=thinlto-index-only --plugin-opt=obj-path=4.o -shared 1.bc 2.bc -o /dev/null
-; RUN: llvm-objdump -d 4.o | FileCheck %s --check-prefix=EMPTY
-
-;; Ensure lld emits empty combined module if specific obj-path.
-; RUN: rm -fr objpath && mkdir objpath
-; RUN: ld.lld --plugin-opt=obj-path=4.o -shared 1.bc 2.bc -o objpath/a.out --save-temps
-; RUN: ls objpath/a.out*.lto.* | count 3
-
-;; Ensure lld does not emit empty combined module in default.
-; RUN: rm -fr objpath && mkdir objpath
-; RUN: ld.lld -shared 1.bc 2.bc -o objpath/a.out --save-temps
-; RUN: ls objpath/a.out*.lto.* | count 2
-
-; EMPTY: file format elf64-x86-64
-; EMPTY-NOT: {{.}}
-
-target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
-target triple = "x86_64-unknown-linux-gnu"
-
-declare void @g(...)
-
-define void @f() {
-entry:
- call void (...) @g()
- ret void
-}
diff --git a/lld/test/ELF/lto/thinlto.ll b/lld/test/ELF/lto/thinlto.ll
index 5d5df641566b11..4145007d9b2016 100644
--- a/lld/test/ELF/lto/thinlto.ll
+++ b/lld/test/ELF/lto/thinlto.ll
@@ -1,68 +1,69 @@
; REQUIRES: x86
; Basic ThinLTO tests.
-; RUN: opt -module-summary %s -o %t1.o
-; RUN: opt -module-summary %p/Inputs/thinlto.ll -o %t2.o
+; RUN: rm -rf %t && mkdir %t && cd %t
+; RUN: mkdir d e
+; RUN: opt -module-summary %s -o 1.o
+; RUN: opt -module-summary %p/Inputs/thinlto.ll -o d/2.o
; First force single-threaded mode
-; RUN: rm -f %t31.lto.o %t32.lto.o
-; RUN: ld.lld -save-temps --thinlto-jobs=1 -shared %t1.o %t2.o -o %t3
-; RUN: llvm-nm %t31.lto.o | FileCheck %s --check-prefix=NM1
-; RUN: llvm-nm %t32.lto.o | FileCheck %s --check-prefix=NM2
+; RUN: rm -f e/out1.lto.o e/out2.lto.o
+; RUN: ld.lld -save-temps --thinlto-jobs=1 -shared 1.o d/2.o -o e/out
+; RUN: llvm-nm e/out1.lto.o | FileCheck %s --check-prefix=NM1
+; RUN: llvm-nm e/out2.lto.o | FileCheck %s --check-prefix=NM2
; Next force multi-threaded mode
-; RUN: rm -f %t31.lto.o %t32.lto.o
-; RUN: ld.lld -save-temps --thinlto-jobs=2 -shared %t1.o %t2.o -o %t3
-; RUN: llvm-nm %t31.lto.o | FileCheck %s --check-prefix=NM1
-; RUN: llvm-nm %t32.lto.o | FileCheck %s --check-prefix=NM2
+; RUN: rm -f e/out1.lto.o e/out2.lto.o
+; RUN: ld.lld -save-temps --thinlto-jobs=2 -shared 1.o d/2.o -o e/out
+; RUN: llvm-nm e/out1.lto.o | FileCheck %s --check-prefix=NM1
+; RUN: llvm-nm e/out2.lto.o | FileCheck %s --check-prefix=NM2
;; --plugin-opt=jobs= is an alias.
-; RUN: rm -f %t31.lto.o %t32.lto.o
-; RUN: ld.lld -save-temps --plugin-opt=jobs=2 -shared %t1.o %t2.o -o %t3
-; RUN: llvm-nm %t31.lto.o | FileCheck %s --check-prefix=NM1
-; RUN: llvm-nm %t32.lto.o | FileCheck %s --check-prefix=NM2
+; RUN: rm -f e/out1.lto.o e/out2.lto.o
+; RUN: ld.lld -save-temps --plugin-opt=jobs=2 -shared 1.o d/2.o -o e/out
+; RUN: llvm-nm e/out1.lto.o | FileCheck %s --check-prefix=NM1
+; RUN: llvm-nm e/out2.lto.o | FileCheck %s --check-prefix=NM2
;; --thinlto-jobs= defaults to --threads=.
-; RUN: rm -f %t31.lto.o %t32.lto.o
-; RUN: ld.lld -save-temps --threads=2 -shared %t1.o %t2.o -o %t3
-; RUN: llvm-nm %t31.lto.o | FileCheck %s --check-prefix=NM1
-; RUN: llvm-nm %t32.lto.o | FileCheck %s --check-prefix=NM2
+; RUN: rm -f e/out1.lto.o e/out2.lto.o
+; RUN: ld.lld -save-temps --threads=2 -shared 1.o d/2.o -o e/out
+; RUN: llvm-nm e/out1.lto.o | FileCheck %s --check-prefix=NM1
+; RUN: llvm-nm e/out2.lto.o | FileCheck %s --check-prefix=NM2
;; --thinlto-jobs= overrides --threads=.
-; RUN: rm -f %t31.lto.o %t32.lto.o
-; RUN: ld.lld -save-temps --threads=1 --plugin-opt=jobs=2 -shared %t1.o %t2.o -o %t3
-; RUN: llvm-nm %t31.lto.o | FileCheck %s --check-prefix=NM1
-; RUN: llvm-nm %t32.lto.o | FileCheck %s --check-prefix=NM2
+; RUN: rm -f e/out1.lto.o e/out2.lto.o
+; RUN: ld.lld -save-temps --threads=1 --plugin-opt=jobs=2 -shared 1.o d/2.o -o e/out
+; RUN: llvm-nm e/out1.lto.o | FileCheck %s --check-prefix=NM1
+; RUN: llvm-nm e/out2.lto.o | FileCheck %s --check-prefix=NM2
; Test with all threads, on all cores, on all CPU sockets
-; RUN: rm -f %t31.lto.o %t32.lto.o
-; RUN: ld.lld -save-temps --thinlto-jobs=all -shared %t1.o %t2.o -o %t3
-; RUN: llvm-nm %t31.lto.o | FileCheck %s --check-prefix=NM1
-; RUN: llvm-nm %t32.lto.o | FileCheck %s --check-prefix=NM2
+; RUN: rm -f e/out1.lto.o e/out2.lto.o
+; RUN: ld.lld -save-temps --thinlto-jobs=all -shared 1.o d/2.o -o e/out
+; RUN: llvm-nm e/out1.lto.o | FileCheck %s --check-prefix=NM1
+; RUN: llvm-nm e/out2.lto.o | FileCheck %s --check-prefix=NM2
; Test with many more threads than the system has
-; RUN: rm -f %t31.lto.o %t32.lto.o
-; RUN: ld.lld -save-temps --thinlto-jobs=100 -shared %t1.o %t2.o -o %t3
-; RUN: llvm-nm %t31.lto.o | FileCheck %s --check-prefix=NM1
-; RUN: llvm-nm %t32.lto.o | FileCheck %s --check-prefix=NM2
+; RUN: rm -f e/out1.lto.o e/out2.lto.o
+; RUN: ld.lld -save-temps --thinlto-jobs=100 -shared 1.o d/2.o -o e/out
+; RUN: llvm-nm e/out1.lto.o | FileCheck %s --check-prefix=NM1
+; RUN: llvm-nm e/out2.lto.o | FileCheck %s --check-prefix=NM2
; Test with a bad value
-; RUN: rm -f %t31.lto.o %t32.lto.o
-; RUN: not ld.lld -save-temps --thinlto-jobs=foo -shared %t1.o %t2.o -o %t3 2>&1 | FileCheck %s --check-prefix=BAD-JOBS
+; RUN: rm -f e/out1.lto.o e/out2.lto.o
+; RUN: not ld.lld -save-temps --thinlto-jobs=foo -shared 1.o d/2.o -o e/out 2>&1 | FileCheck %s --check-prefix=BAD-JOBS
; BAD-JOBS: error: --thinlto-jobs: invalid job count: foo
; Then check without --thinlto-jobs (which currently defaults to heavyweight_hardware_concurrency, meanning one thread per hardware core -- not SMT)
-; RUN: ld.lld -shared -save-temps %t1.o %t2.o -o %t3
-; RUN: llvm-nm %t31.lto.o | FileCheck %s --check-prefix=NM1
-; RUN: llvm-nm %t32.lto.o | FileCheck %s --check-prefix=NM2
+; RUN: ld.lld -shared -save-temps 1.o d/2.o -o e/out
+; RUN: llvm-nm e/out1.lto.o | FileCheck %s --check-prefix=NM1
+; RUN: llvm-nm e/out2.lto.o | FileCheck %s --check-prefix=NM2
; Check that -save-temps is usable with thin archives
-; RUN: rm -fr %t.dir
-; RUN: mkdir -p %t.dir
-; RUN: cp %t2.o %t.dir/t.o
-; RUN: llvm-ar rcsT %t.dir/t.a %t.dir/t.o
-; RUN: ld.lld -save-temps %t1.o %t.dir/t.a -o %t.null
-; RUN: ls %t.dir/t.a*.0.preopt.bc
+; RUN: mkdir dir
+; RUN: cp d/2.o dir/t.o
+; RUN: llvm-ar rcsT dir/t.a dir/t.o
+; RUN: ld.lld -save-temps 1.o dir/t.a -o %t.null
+; RUN: ls dir/t.a*.0.preopt.bc
; NM1: T f
; NM2: T g
More information about the llvm-commits
mailing list