[lld] 1f3bb2d - [ELF] Improve --obj-path tests

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 3 15:48:22 PST 2023


Author: Fangrui Song
Date: 2023-01-03T15:48:17-08:00
New Revision: 1f3bb2d483ad82e9cae3583e5d08ac4d85235874

URL: https://github.com/llvm/llvm-project/commit/1f3bb2d483ad82e9cae3583e5d08ac4d85235874
DIFF: https://github.com/llvm/llvm-project/commit/1f3bb2d483ad82e9cae3583e5d08ac4d85235874.diff

LOG: [ELF] Improve --obj-path tests

Combine two ThinLTO --obj-path tests and improve checks.
Add a --obj-path test for regular LTO.

Added: 
    

Modified: 
    lld/test/ELF/lto/obj-path.ll
    lld/test/ELF/lto/thinlto-obj-path.ll

Removed: 
    


################################################################################
diff  --git a/lld/test/ELF/lto/obj-path.ll b/lld/test/ELF/lto/obj-path.ll
index 1fbffe7932fe..69c0a21fb79a 100644
--- a/lld/test/ELF/lto/obj-path.ll
+++ b/lld/test/ELF/lto/obj-path.ll
@@ -1,26 +1,29 @@
 ; REQUIRES: x86
+;; Test --lto-obj-path= for regular LTO.
 
-; RUN: opt -module-summary %s -o %t1.o
-; RUN: opt -module-summary %p/Inputs/obj-path.ll -o %t2.o
+; RUN: rm -rf %t && split-file %s %t && cd %t
+; RUN: opt 1.ll -o 1.bc
+; RUN: opt 2.ll -o 2.bc
 
-; Test to ensure that obj-path creates the ELF file.
-; RUN: rm -f %t4.o
-; RUN: ld.lld --plugin-opt=obj-path=%t4.o -shared %t1.o %t2.o -o %t3
-; RUN: llvm-nm %t3 | FileCheck %s
-; RUN: llvm-readobj -h %t4.o1 | FileCheck %s -check-prefix=ELF1
-; RUN: llvm-readobj -h %t4.o2 | FileCheck %s -check-prefix=ELF2
-; RUN: llvm-nm %t4.o1 2>&1 | FileCheck %s -check-prefix=NM1
-; RUN: llvm-nm %t4.o2 2>&1 | FileCheck %s -check-prefix=NM2
+; RUN: rm -f 4.o
+; RUN: ld.lld --lto-obj-path=4.o -shared 1.bc 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
 
-; CHECK:      T f
-; CHECK-NEXT: T g
+; 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: not ls 3
 
-; NM1: T f
-; ELF1: Format: elf64-x86-64
+; NM: T f
+; NM: T g
 
-; NM2: T g
-; ELF2: Format: elf64-x86-64
+; CHECK: file format elf64-x86-64
+; CHECK: <f>:
+; CHECK: <g>:
 
+;--- 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"
 
@@ -31,3 +34,12 @@ entry:
   call void (...) @g()
   ret void
 }
+
+;--- 2.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"
+
+define void @g() {
+entry:
+  ret void
+}

diff  --git a/lld/test/ELF/lto/thinlto-obj-path.ll b/lld/test/ELF/lto/thinlto-obj-path.ll
index 7311774416d2..20cfed7480ce 100644
--- a/lld/test/ELF/lto/thinlto-obj-path.ll
+++ b/lld/test/ELF/lto/thinlto-obj-path.ll
@@ -1,30 +1,57 @@
 ; REQUIRES: x86
 
-; 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: opt -module-summary %s -o 1.bc
+; RUN: opt -module-summary %p/Inputs/thinlto.ll -o 2.bc
 
-; Test to ensure that thinlto-index-only with obj-path creates the file.
-; RUN: rm -f %t4.o
-; RUN: ld.lld --plugin-opt=thinlto-index-only --plugin-opt=obj-path=%t4.o -shared %t1.o %t2.o -o /dev/null
-; RUN: llvm-readobj -h %t4.o | FileCheck %s
-; RUN: llvm-nm %t4.o 2>&1 | count 0
+; 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
 
-; Check that this also works without the --plugin-opt= prefix.
-; RUN: rm -f %t4.o
-; RUN: ld.lld --thinlto-index-only --lto-obj-path=%t4.o -shared %t1.o %t2.o -o /dev/null
-; RUN: llvm-readobj -h %t4.o | FileCheck %s
+; 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 %t.dir/objpath && mkdir -p %t.dir/objpath
-; RUN: ld.lld --plugin-opt=obj-path=%t4.o -shared %t1.o %t2.o -o %t.dir/objpath/a.out --save-temps
-; RUN: ls %t.dir/objpath/a.out*.lto.* | count 3
+; 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 %t.dir/objpath && mkdir -p %t.dir/objpath
-; RUN: ld.lld %t1.o %t2.o -o %t.dir/objpath/a.out --save-temps
-; RUN: ls %t.dir/objpath/a.out*.lto.* | count 2
+; RUN: rm -fr objpath && mkdir objpath
+; RUN: ld.lld 1.bc 2.bc -o objpath/a.out --save-temps
+; RUN: ls objpath/a.out*.lto.* | count 2
 
-; CHECK: Format: elf64-x86-64
+; 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"


        


More information about the llvm-commits mailing list