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