brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.9 KiB · 2ba0a16 Raw
85 lines · plain
1; Test to ensure we don't internalize or treat as dead a global value2; with a valid C identifier section name. Otherwise, ELF linker generation of3; __start_"sectionname" and __stop_"sectionname" symbols would not occur and4; we can end up with undefined references at link time.5 6; First try RegularLTO7; RUN: opt %s -o %t.o8; RUN: llvm-lto2 dump-symtab %t.o | FileCheck %s --check-prefix=SYMTAB9; RUN: opt %p/Inputs/global_with_section.ll -o %t2.o10; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold%shlibext \11; RUN:     --plugin-opt=save-temps \12; RUN:     -o %t3.o %t.o %t2.o13; Check results of internalization14; RUN: llvm-dis %t3.o.0.2.internalize.bc -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK2-REGULARLTO15 16; Next try ThinLTO17; RUN: opt -module-summary %s -o %t.o18; RUN: llvm-lto2 dump-symtab %t.o | FileCheck %s --check-prefix=SYMTAB19; RUN: opt -module-summary %p/Inputs/global_with_section.ll -o %t2.o20; 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.o24; Check results of internalization25; RUN: llvm-dis %t.o.2.internalize.bc -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-THINLTO26; RUN: llvm-dis %t2.o.2.internalize.bc -o - | FileCheck %s --check-prefix=CHECK2-THINLTO27 28; SYMTAB: deadfunc_with_section29; SYMTAB-NEXT: section some_other_section30; SYMTAB-NEXT: deadfunc_with_nonC_section31; SYMTAB-NEXT: section .nonCsection32; SYMTAB-NEXT: deadfunc2_called_from_section33; SYMTAB-NEXT: deadfunc2_called_from_nonC_section34; SYMTAB-NEXT: var_with_section35; SYMTAB-NEXT: section some_section36; SYMTAB-NEXT: var_with_nonC_section37; SYMTAB-NEXT: section .nonCsection38 39target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"40target triple = "x86_64-unknown-linux-gnu"41 42; We should not internalize @var_with_section due to section43; 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 getting47; 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_section51@var_with_nonC_section = global i32 0, section ".nonCsection"52 53; We should not internalize @deadfunc_with_section due to section54; CHECK-DAG: define dso_local void @deadfunc_with_section() section "some_other_section"55define void @deadfunc_with_section() section "some_other_section" {56  call void @deadfunc2_called_from_section()57  ret void58}59 60; Confirm via a function with a non-C identifier section that we are getting61; 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()65define void @deadfunc_with_nonC_section() section ".nonCsection" {66  call void @deadfunc2_called_from_nonC_section()67  ret void68}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_section73; In ThinLTO mode, we can't internalize it as it needs to be preserved74; (due to the access from @deadfunc_with_section which must be preserved), and75; can't be internalized since the reference is from a different module.76; CHECK2-THINLTO: define dso_local void @deadfunc2_called_from_section77declare void @deadfunc2_called_from_section()78 79; Confirm when called from a function with a non-C identifier section that we80; are getting the expected internalization.81; CHECK2-REGULARLTO: define internal void @deadfunc2_called_from_nonC_section82; Check dead function converted to declaration.83; CHECK2-THINLTO-NOT: @deadfunc2_called_from_nonC_section84declare void @deadfunc2_called_from_nonC_section()85