| 1 |
; Test to ensure we don't internalize or treat as dead a global value |
| 2 |
; with a valid C identifier section name. Otherwise, ELF linker generation of |
| 3 |
; __start_"sectionname" and __stop_"sectionname" symbols would not occur and |
| 4 |
; we can end up with undefined references at link time. |
| 5 |
|
| 6 |
; First try RegularLTO |
| 7 |
; RUN: opt %s -o %t.o |
| 8 |
; RUN: llvm-lto2 dump-symtab %t.o | FileCheck %s --check-prefix=SYMTAB |
| 9 |
; RUN: opt %p/Inputs/global_with_section.ll -o %t2.o |
| 10 |
; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold%shlibext \ |
| 11 |
; RUN: --plugin-opt=save-temps \ |
| 12 |
; RUN: -o %t3.o %t.o %t2.o |
| 13 |
; Check results of internalization |
| 14 |
; RUN: llvm-dis %t3.o.0.2.internalize.bc -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK2-REGULARLTO |
| 15 |
|
| 16 |
; Next try ThinLTO |
| 17 |
; RUN: opt -module-summary %s -o %t.o |
| 18 |
; RUN: llvm-lto2 dump-symtab %t.o | FileCheck %s --check-prefix=SYMTAB |
| 19 |
; RUN: opt -module-summary %p/Inputs/global_with_section.ll -o %t2.o |
| 20 |
; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold%shlibext \ |
| 21 |
; RUN: --plugin-opt=thinlto \ |
| 22 |
; RUN: --plugin-opt=save-temps \ |
| 23 |
; RUN: -o %t3.o %t.o %t2.o |
| 24 |
; Check results of internalization |
| 25 |
; RUN: llvm-dis %t.o.2.internalize.bc -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-THINLTO |
| 26 |
; RUN: llvm-dis %t2.o.2.internalize.bc -o - | FileCheck %s --check-prefix=CHECK2-THINLTO |
| 27 |
|
| 28 |
; SYMTAB: deadfunc_with_section |
| 29 |
; SYMTAB-NEXT: section some_other_section |
| 30 |
; SYMTAB-NEXT: deadfunc_with_nonC_section |
| 31 |
; SYMTAB-NEXT: section .nonCsection |
| 32 |
; SYMTAB-NEXT: deadfunc2_called_from_section |
| 33 |
; SYMTAB-NEXT: deadfunc2_called_from_nonC_section |
| 34 |
; SYMTAB-NEXT: var_with_section |
| 35 |
; SYMTAB-NEXT: section some_section |
| 36 |
; SYMTAB-NEXT: var_with_nonC_section |
| 37 |
; SYMTAB-NEXT: section .nonCsection |
| 38 |
|
| 39 |
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" |
| 40 |
target triple = "x86_64-unknown-linux-gnu" |
| 41 |
|
| 42 |
; We should not internalize @var_with_section due to section |
| 43 |
; CHECK-DAG: @var_with_section = dso_local global i32 0, section "some_section" |
| 44 |
@var_with_section = global i32 0, section "some_section" |
| 45 |
|
| 46 |
; Confirm via a variable with a non-C identifier section that we are getting |
| 47 |
; the expected internalization. |
| 48 |
; CHECK-REGULARLTO-DAG: @var_with_nonC_section = internal global i32 0, section ".nonCsection" |
| 49 |
; Check we dropped definition of dead variable. |
| 50 |
; CHECK-THINLTO-NOT: @var_with_nonC_section |
| 51 |
@var_with_nonC_section = global i32 0, section ".nonCsection" |
| 52 |
|
| 53 |
; We should not internalize @deadfunc_with_section due to section |
| 54 |
; CHECK-DAG: define dso_local void @deadfunc_with_section() section "some_other_section" |
| 55 |
define void @deadfunc_with_section() section "some_other_section" { |
| 56 |
call void @deadfunc2_called_from_section() |
| 57 |
ret void |
| 58 |
} |
| 59 |
|
| 60 |
; Confirm via a function with a non-C identifier section that we are getting |
| 61 |
; the expected internalization. |
| 62 |
; CHECK2-REGULARLTO-DAG: define internal void @deadfunc_with_nonC_section() section ".nonCsection" |
| 63 |
; Check dead function converted to declaration. |
| 64 |
; CHECK-THINLTO-NOT: @deadfunc_with_nonC_section() |
| 65 |
define void @deadfunc_with_nonC_section() section ".nonCsection" { |
| 66 |
call void @deadfunc2_called_from_nonC_section() |
| 67 |
ret void |
| 68 |
} |
| 69 |
|
| 70 |
; In RegularLTO mode, where we have combined all the IR, |
| 71 |
; @deadfunc2_called_from_section can be internalized. |
| 72 |
; CHECK2-REGULARLTO: define internal void @deadfunc2_called_from_section |
| 73 |
; In ThinLTO mode, we can't internalize it as it needs to be preserved |
| 74 |
; (due to the access from @deadfunc_with_section which must be preserved), and |
| 75 |
; can't be internalized since the reference is from a different module. |
| 76 |
; CHECK2-THINLTO: define dso_local void @deadfunc2_called_from_section |
| 77 |
declare void @deadfunc2_called_from_section() |
| 78 |
|
| 79 |
; Confirm when called from a function with a non-C identifier section that we |
| 80 |
; are getting the expected internalization. |
| 81 |
; CHECK2-REGULARLTO: define internal void @deadfunc2_called_from_nonC_section |
| 82 |
; Check dead function converted to declaration. |
| 83 |
; CHECK2-THINLTO-NOT: @deadfunc2_called_from_nonC_section |
| 84 |
declare void @deadfunc2_called_from_nonC_section() |