From 963d7b4b2a0a80e29d4a862c3629a21de0af975f Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Fri, 19 Jan 2024 22:02:21 -0800 Subject: [ELF] Improve --thinlto-index-only and --thinlto-emit-index-files tests --- lld/test/ELF/lto/thinlto-emit-imports.ll | 36 +--------- lld/test/ELF/lto/thinlto-emit-index.ll | 50 +++++++------- lld/test/ELF/lto/thinlto-index-file.ll | 27 -------- lld/test/ELF/lto/thinlto-index-only.ll | 112 +++++++++++++++++++++---------- 4 files changed, 106 insertions(+), 119 deletions(-) delete mode 100644 lld/test/ELF/lto/thinlto-index-file.ll (limited to 'lld') diff --git a/lld/test/ELF/lto/thinlto-emit-imports.ll b/lld/test/ELF/lto/thinlto-emit-imports.ll index fcddd18..6d0e1e6 100644 --- a/lld/test/ELF/lto/thinlto-emit-imports.ll +++ b/lld/test/ELF/lto/thinlto-emit-imports.ll @@ -1,32 +1,10 @@ ; REQUIRES: x86 +;; Test a few properties not tested by thinlto-index-only.ll -; Generate summary sections and test lld handling. ; RUN: opt -module-summary %s -o %t1.o ; RUN: opt -module-summary %p/Inputs/thinlto.ll -o %t2.o - -; Include a file with an empty module summary index, to ensure that the expected -; output files are created regardless, for a distributed build system. ; RUN: opt -module-summary %p/Inputs/thinlto_empty.ll -o %t3.o -; Ensure lld generates imports files if requested for distributed backends. -; RUN: rm -f %t3.o.imports %t3.o.thinlto.bc -; RUN: ld.lld --plugin-opt=thinlto-index-only --plugin-opt=thinlto-emit-imports-files -shared %t1.o %t2.o %t3.o -o %t4 - -; The imports file for this module contains the bitcode file for -; Inputs/thinlto.ll -; RUN: count 1 < %t1.o.imports -; RUN: FileCheck %s --check-prefix=IMPORTS1 < %t1.o.imports -; IMPORTS1: thinlto-emit-imports.ll.tmp2.o - -; The imports file for Input/thinlto.ll is empty as it does not import anything. -; RUN: count 0 < %t2.o.imports - -; The imports file for Input/thinlto_empty.ll is empty but should exist. -; RUN: count 0 < %t3.o.imports - -; The index file should be created even for the input with an empty summary. -; RUN: ls %t3.o.thinlto.bc - ; Ensure lld generates error if unable to write to imports file. ; RUN: rm -f %t3.o.imports ; RUN: touch %t3.o.imports @@ -34,22 +12,12 @@ ; RUN: not ld.lld --plugin-opt=thinlto-index-only --plugin-opt=thinlto-emit-imports-files -shared %t1.o %t2.o %t3.o -o /dev/null 2>&1 | FileCheck -DMSG=%errc_EACCES %s --check-prefix=ERR ; ERR: cannot open {{.*}}3.o.imports: [[MSG]] -; Ensure lld doesn't generate import files when thinlto-index-only is not enabled -; RUN: rm -f %t1.o.imports -; RUN: rm -f %t2.o.imports -; RUN: rm -f %t3.o.imports +; RUN: rm -f %t1.o.imports %t2.o.imports rm -f %t3.o.imports ; RUN: ld.lld --plugin-opt=thinlto-emit-imports-files -shared %t1.o %t2.o %t3.o -o %t4 ; RUN: not ls %t1.o.imports ; RUN: not ls %t2.o.imports ; RUN: not ls %t3.o.imports -; Check that imports files are generated also when --thinlto-index-only -; is specified without --plugin-opt=. -; RUN: rm -f %t1.o.imports -; RUN: ld.lld --thinlto-index-only --thinlto-emit-imports-files -shared %t1.o %t2.o %t3.o -o %t4 -; RUN: count 1 < %t1.o.imports -; RUN: FileCheck %s --check-prefix=IMPORTS1 < %t1.o.imports - 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/thinlto-emit-index.ll b/lld/test/ELF/lto/thinlto-emit-index.ll index ae8b4dd..ba2ac2c 100644 --- a/lld/test/ELF/lto/thinlto-emit-index.ll +++ b/lld/test/ELF/lto/thinlto-emit-index.ll @@ -3,40 +3,40 @@ ;; Mostly copied/updated from thinlto-index-only.ll ;; First ensure that the ThinLTO handling in lld handles ;; bitcode without summary sections gracefully and generates index file. -; RUN: rm -rf %t.dir && mkdir %t.dir && cd %t.dir +; RUN: rm -rf %t && mkdir %t && cd %t +; RUN: mkdir d ; RUN: llvm-as %s -o 1.o -; RUN: llvm-as %p/Inputs/thinlto.ll -o 2.o -; RUN: ld.lld --thinlto-emit-index-files -shared 1.o 2.o -o 3 -; RUN: ls 2.o.thinlto.bc +; RUN: llvm-as %p/Inputs/thinlto.ll -o d/2.o +; RUN: ld.lld --thinlto-emit-index-files -shared 1.o d/2.o -o 3 +; RUN: ls d/2.o.thinlto.bc ; RUN: ls 3 -; RUN: ld.lld -shared 1.o 2.o -o 3 +; RUN: ld.lld -shared 1.o d/2.o -o 3 ; RUN: llvm-nm 3 | FileCheck %s --check-prefix=NM ;; Basic ThinLTO tests. ; RUN: opt -module-summary %s -o 1.o -; RUN: opt -module-summary %p/Inputs/thinlto.ll -o 2.o +; RUN: opt -module-summary %p/Inputs/thinlto.ll -o d/2.o ; RUN: opt -module-summary %p/Inputs/thinlto_empty.ll -o 3.o +; RUN: cp 3.o 4.o ;; Ensure lld generates an index and also a binary if requested. -; RUN: ld.lld --thinlto-emit-index-files -shared 1.o 2.o -o 4 -; RUN: llvm-bcanalyzer -dump 1.o.thinlto.bc | FileCheck %s --check-prefix=BACKEND1 -; RUN: llvm-bcanalyzer -dump 2.o.thinlto.bc | FileCheck %s --check-prefix=BACKEND2 +; RUN: ld.lld --thinlto-emit-index-files -shared 1.o --start-lib d/2.o 3.o --end-lib 4.o -o 4 ; RUN: ls 4 +; RUN: llvm-bcanalyzer -dump 1.o.thinlto.bc | FileCheck %s --check-prefix=BACKEND1 +; RUN: llvm-bcanalyzer -dump d/2.o.thinlto.bc | FileCheck %s --check-prefix=BACKEND2 +; RUN: llvm-dis < 3.o.thinlto.bc | FileCheck %s --check-prefix=BACKEND3 +; RUN: llvm-dis < 4.o.thinlto.bc | FileCheck %s --check-prefix=BACKEND4 + +; IMPORTS1: d/2.o ;; Ensure lld generates an index and not a binary if both emit-index and index-only are present. -; RUN: ld.lld --thinlto-emit-index-files --thinlto-index-only -shared 1.o 2.o -o 5 +; RUN: ld.lld --thinlto-emit-index-files --thinlto-index-only -shared 1.o d/2.o -o 5 ; RUN: not ls 5 -;; Ensure lld generates an index even if the file is wrapped in --start-lib/--end-lib -; RUN: rm -f 2.o.thinlto.bc -; RUN: ld.lld --thinlto-emit-index-files -shared 1.o 3.o --start-lib 2.o --end-lib -o 6 -; RUN: llvm-dis < 2.o.thinlto.bc | grep -q '\^0 = module:' -; RUN: ls 6 - ;; Test that LLD generates an empty index even for lazy object file that is not added to link. ;; Test that LLD also generates empty imports file with the --thinlto-emit-imports-files option. ; RUN: rm -f 1.o.thinlto.bc 1.o.imports -; RUN: ld.lld --thinlto-emit-index-files -shared 2.o --start-lib 1.o --end-lib \ +; RUN: ld.lld --thinlto-emit-index-files -shared d/2.o --start-lib 1.o --end-lib \ ; RUN: --thinlto-emit-imports-files -o 7 ; RUN: ls 7 ; RUN: ls 1.o.thinlto.bc @@ -50,19 +50,19 @@ ; RUN: ls 1.o.thinlto.bc ;; Test that LLD errors out when run with suffix replacement, or prefix replacement -; RUN: not ld.lld --thinlto-emit-index-files -shared 2.o --start-lib 1.o --end-lib \ +; RUN: not ld.lld --thinlto-emit-index-files -shared d/2.o --start-lib 1.o --end-lib \ ; RUN: --thinlto-prefix-replace="abc;xyz" 2>&1 | FileCheck %s --check-prefix=ERR1 ; ERR1: --thinlto-prefix-replace is not supported with --thinlto-emit-index-files -; RUN: not ld.lld --thinlto-emit-index-files -shared 2.o --start-lib 1.o --end-lib \ +; RUN: not ld.lld --thinlto-emit-index-files -shared d/2.o --start-lib 1.o --end-lib \ ; RUN: --thinlto-object-suffix-replace="abc;xyz" 2>&1 | FileCheck %s --check-prefix=ERR2 ; ERR2: --thinlto-object-suffix-replace is not supported with --thinlto-emit-index-files ;; But not when passed with index only as well -; RUN: ld.lld --thinlto-emit-index-files -shared 2.o --start-lib 1.o --end-lib \ +; RUN: ld.lld --thinlto-emit-index-files -shared d/2.o --start-lib 1.o --end-lib \ ; RUN: --thinlto-prefix-replace="abc;xyz" --thinlto-index-only -; RUN: ld.lld --thinlto-emit-index-files -shared 2.o --start-lib 1.o --end-lib \ +; RUN: ld.lld --thinlto-emit-index-files -shared d/2.o --start-lib 1.o --end-lib \ ; RUN: --thinlto-object-suffix-replace="abc;xyz" --thinlto-index-only ; NM: T f @@ -71,7 +71,7 @@ ;; Inputs/thinlto.ll, as it imports from the latter. ; BACKEND1: