xref: /llvm-project/lld/test/ELF/lto/libcall-archive-calloc.ll (revision 28ad007927a4126e12b7aec7daa7f10bc1e29ae1)
1; REQUIRES: x86
2;; malloc+memset references can be combined to a calloc reference.
3;; Test that we extract calloc defined in a lazy bitcode file to satisfy
4;; possible references from LTO generated object files.
5
6; RUN: rm -rf %t && split-file %s %t && cd %t
7; RUN: llvm-as a.ll -o a.bc
8; RUN: llvm-as calloc.ll -o calloc.bc
9; RUN: llvm-mc -filetype=obj -triple=x86_64 lib.s -o lib.o
10; RUN: ld.lld -u foo a.bc --start-lib calloc.bc lib.o --end-lib -o t --save-temps
11; RUN: llvm-dis < t.0.4.opt.bc | FileCheck %s
12; RUN: llvm-nm t | FileCheck %s --check-prefix=NM
13
14; CHECK: define dso_local void @calloc
15
16; NM-NOT:  {{.}}
17; NM:      {{.*}} T _start
18;; TODO: Currently the symbol is lazy, which lowers to a SHN_ABS symbol at address 0.
19; NM-NEXT: {{.*}} T calloc
20; NM-NEXT: {{.*}} T foo
21; NM-NEXT: {{.*}} T malloc
22; NM-NEXT: {{.*}} T memset
23; NM-NOT:  {{.}}
24
25;--- a.ll
26target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
27target triple = "x86_64-unknown-linux-gnu"
28
29define ptr @foo() noinline {
30entry:
31  %call = tail call noalias ptr @malloc(i64 400)
32  tail call void @llvm.memset.p0.i64(ptr %call, i8 0, i64 400, i1 false)
33  ret ptr %call
34}
35
36define void @_start(ptr %a, ptr %b) {
37entry:
38  call ptr @foo()
39  ret void
40}
41
42declare ptr @malloc(i64)
43declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg)
44
45;--- calloc.ll
46target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
47target triple = "x86_64-unknown-linux-gnu"
48
49define void @calloc(i64, i64) {
50entry:
51  ret void
52}
53
54;--- lib.s
55.globl malloc, memset
56malloc:
57memset:
58