Skip to content

Commit 5848166

Browse files
committed
Disable LibFuncs for stpcpy and stpncpy for Android < 21
These functions don't exist in android API levels < 21. A change in llvm-12 (rG6dbf0cfcf789) caused Oz builds to emit this symbol assuming it's available and thus is causing link errors. Simply disable it here. Differential Revision: https://reviews.llvm.org/D107509
1 parent fb0a929 commit 5848166

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

llvm/lib/Analysis/TargetLibraryInfo.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,11 @@ static void initialize(TargetLibraryInfoImpl &TLI, const Triple &T,
589589
TLI.setAvailable(LibFunc_fgets_unlocked);
590590
}
591591

592+
if (T.isAndroid() && T.isAndroidVersionLT(21)) {
593+
TLI.setUnavailable(LibFunc_stpcpy);
594+
TLI.setUnavailable(LibFunc_stpncpy);
595+
}
596+
592597
// As currently implemented in clang, NVPTX code has no standard library to
593598
// speak of. Headers provide a standard-ish library implementation, but many
594599
// of the signatures are wrong -- for example, many libm functions are not

llvm/test/Transforms/InstCombine/sprintf-1.ll

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
; RUN: opt < %s -mtriple xcore-xmos-elf -instcombine -S | FileCheck %s -check-prefixes=CHECK,CHECK-IPRINTF
66
; RUN: opt < %s -mtriple=i386-pc-windows-msvc -instcombine -S | FileCheck %s --check-prefixes=CHECK,WIN
77
; RUN: opt < %s -mtriple=i386-mingw32 -instcombine -S | FileCheck %s --check-prefixes=CHECK,WIN
8+
; RUN: opt < %s -mtriple=armv7-none-linux-android16 -instcombine -S | FileCheck %s --check-prefixes=CHECK,ANDROID
89

910
target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
1011

@@ -108,6 +109,12 @@ define i32 @test_simplify7(i8* %dst, i8* %str) {
108109
; WIN-NEXT: [[LENINC:%.*]] = add i32 [[STRLEN]], 1
109110
; WIN-NEXT: call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 1 [[DST:%.*]], i8* align 1 [[STR]], i32 [[LENINC]], i1 false)
110111
; WIN-NEXT: ret i32 [[STRLEN]]
112+
;
113+
; ANDROID-LABEL: @test_simplify7(
114+
; ANDROID-NEXT: [[STRLEN:%.*]] = call i32 @strlen(i8* noundef nonnull dereferenceable(1) [[STR:%.*]])
115+
; ANDROID-NEXT: [[LENINC:%.*]] = add i32 [[STRLEN]], 1
116+
; ANDROID-NEXT: call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 1 [[DST:%.*]], i8* align 1 [[STR]], i32 [[LENINC]], i1 false)
117+
; ANDROID-NEXT: ret i32 [[STRLEN]]
111118
;
112119
%fmt = getelementptr [3 x i8], [3 x i8]* @percent_s, i32 0, i32 0
113120
%r = call i32 (i8*, i8*, ...) @sprintf(i8* %dst, i8* %fmt, i8* %str)

0 commit comments

Comments
 (0)