Skip to content

Commit c6daf73

Browse files
committed
Restore clang_rt library name on i686-android.
Summary: Recent changes canonicalized clang_rt library names to refer to "i386" on all x86 targets. Android historically uses i686. This change adds a special case to keep i686 in all clang_rt libraries when targeting Android. Reviewers: hans, mgorny, beanz Subscribers: srhines, cfe-commits, llvm-commits Differential Revision: https://reviews.llvm.org/D37278 llvm-svn: 312048
1 parent ba2e61b commit c6daf73

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

clang/lib/Driver/ToolChain.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,10 @@ static StringRef getArchNameForCompilerRTLib(const ToolChain &TC,
305305
? "armhf"
306306
: "arm";
307307

308+
// For historic reasons, Android library is using i686 instead of i386.
309+
if (TC.getArch() == llvm::Triple::x86 && Triple.isAndroid())
310+
return "i686";
311+
308312
return llvm::Triple::getArchTypeName(TC.getArch());
309313
}
310314

clang/test/Driver/sanitizer-ld.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,18 @@
133133
// CHECK-ASAN-ANDROID-NOT: "-lpthread"
134134
//
135135
// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
136+
// RUN: -target i686-linux-android -fuse-ld=ld -fsanitize=address \
137+
// RUN: --sysroot=%S/Inputs/basic_android_tree/sysroot \
138+
// RUN: | FileCheck --check-prefix=CHECK-ASAN-ANDROID-X86 %s
139+
//
140+
// CHECK-ASAN-ANDROID-X86: "{{(.*[^.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
141+
// CHECK-ASAN-ANDROID-X86-NOT: "-lc"
142+
// CHECK-ASAN-ANDROID-X86: "-pie"
143+
// CHECK-ASAN-ANDROID-X86-NOT: "-lpthread"
144+
// CHECK-ASAN-ANDROID-X86: libclang_rt.asan-i686-android.so"
145+
// CHECK-ASAN-ANDROID-X86-NOT: "-lpthread"
146+
//
147+
// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
136148
// RUN: -target arm-linux-androideabi -fsanitize=address \
137149
// RUN: --sysroot=%S/Inputs/basic_android_tree/sysroot \
138150
// RUN: -shared-libasan \

compiler-rt/cmake/Modules/AddCompilerRT.cmake

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,14 @@ function(add_compiler_rt_component name)
8686
add_dependencies(compiler-rt ${name})
8787
endfunction()
8888

89+
macro(set_output_name output name arch)
90+
if(ANDROID AND ${arch} STREQUAL "i386")
91+
set(${output} "${name}-i686${COMPILER_RT_OS_SUFFIX}")
92+
else()
93+
set(${output} "${name}-${arch}${COMPILER_RT_OS_SUFFIX}")
94+
endif()
95+
endmacro()
96+
8997
# Adds static or shared runtime for a list of architectures and operating
9098
# systems and puts it in the proper directory in the build and install trees.
9199
# add_compiler_rt_runtime(<name>
@@ -142,15 +150,15 @@ function(add_compiler_rt_runtime name type)
142150
endif()
143151
if(type STREQUAL "STATIC")
144152
set(libname "${name}-${arch}")
145-
set(output_name_${libname} ${libname}${COMPILER_RT_OS_SUFFIX})
153+
set_output_name(output_name_${libname} ${name} ${arch})
146154
else()
147155
set(libname "${name}-dynamic-${arch}")
148156
set(extra_cflags_${libname} ${TARGET_${arch}_CFLAGS} ${LIB_CFLAGS})
149157
set(extra_link_flags_${libname} ${TARGET_${arch}_LINK_FLAGS} ${LIB_LINK_FLAGS})
150158
if(WIN32)
151-
set(output_name_${libname} ${name}_dynamic-${arch}${COMPILER_RT_OS_SUFFIX})
159+
set_output_name(output_name_${libname} ${name}_dynamic ${arch})
152160
else()
153-
set(output_name_${libname} ${name}-${arch}${COMPILER_RT_OS_SUFFIX})
161+
set_output_name(output_name_${libname} ${name} ${arch})
154162
endif()
155163
endif()
156164
set(sources_${libname} ${LIB_SOURCES})

0 commit comments

Comments
 (0)