Skip to content

[ThinLTO] Don't mark calloc function dead #72673

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lld/test/ELF/lto/libcall-archive-calloc.ll
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
; RUN: llvm-dis < t.0.4.opt.bc | FileCheck %s
; RUN: llvm-nm t | FileCheck %s --check-prefix=NM

; CHECK: declare noalias noundef ptr @calloc(i64 noundef, i64 noundef)
; CHECK: define dso_local void @calloc

; NM-NOT: {{.}}
; NM: {{.*}} T _start
;; TODO: Currently the symbol is lazy, which lowers to a SHN_ABS symbol at address 0.
; NM-NEXT: {{.*}} A calloc
; NM-NEXT: {{.*}} T calloc
; NM-NEXT: {{.*}} T foo
; NM-NEXT: {{.*}} T malloc
; NM-NEXT: {{.*}} T memset
Expand Down
2 changes: 2 additions & 0 deletions llvm/include/llvm/IR/RuntimeLibcalls.def
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,8 @@ HANDLE_LIBCALL(UO_PPCF128, "__gcc_qunord")
HANDLE_LIBCALL(MEMCPY, "memcpy")
HANDLE_LIBCALL(MEMMOVE, "memmove")
HANDLE_LIBCALL(MEMSET, "memset")
// DSEPass can emit calloc if it finds a pair of malloc/memset
HANDLE_LIBCALL(CALLOC, "calloc")
HANDLE_LIBCALL(BZERO, nullptr)

// Element-wise unordered-atomic memory of different sizes
Expand Down
13 changes: 11 additions & 2 deletions llvm/test/ThinLTO/X86/builtin-nostrip.ll
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
; RUN: llvm-lto2 run %t1.bc -o %t.out -save-temps \
; RUN: -r %t1.bc,bar,pl \
; RUN: -r %t1.bc,__stack_chk_guard,pl \
; RUN: -r %t1.bc,__stack_chk_fail,pl
; RUN: -r %t1.bc,__stack_chk_fail,pl \
; RUN: -r %t1.bc,calloc,pl
; RUN: llvm-nm %t.out.1 | FileCheck %s --check-prefix=CHECK-NM

; Re-compile, this time without the thinlto indices.
Expand All @@ -20,7 +21,8 @@
; RUN: llvm-lto2 run %t4.bc -o %t5.out -save-temps \
; RUN: -r %t4.bc,bar,pl \
; RUN: -r %t4.bc,__stack_chk_guard,pl \
; RUN: -r %t4.bc,__stack_chk_fail,pl
; RUN: -r %t4.bc,__stack_chk_fail,pl \
; RUN: -r %t4.bc,calloc,pl
; RUN: llvm-nm %t5.out.0 | FileCheck %s --check-prefix=CHECK-NM

; Test the old lto interface without thinlto.
Expand All @@ -30,6 +32,9 @@
; CHECK-NM-NOT: bar
; CHECK-NM: T __stack_chk_fail
; CHECK-NM: D __stack_chk_guard
; Allow calloc to be internalized so --gc-sections can
; still eliminate it if it's not really used anywhere.
; CHECK-NM: {{[Tt]}} calloc
; CHECK-NM-NOT: bar

target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
Expand All @@ -44,3 +49,7 @@ define void @bar() {
define void @__stack_chk_fail() {
ret void
}

define ptr @calloc(i64, i64) {
ret ptr null
}