From 152b023b975eb89d1ad75522f29f629fa82a9978 Mon Sep 17 00:00:00 2001 From: Evgeniy Stepanov Date: Wed, 28 May 2014 12:53:34 +0000 Subject: [PATCH] -pthread does not translate to -lpthread on Android. There is no libpthread.so, and pthread interface is implemented in libc.so. This mirrors gcc behavior. llvm-svn: 209731 --- clang/lib/Driver/Tools.cpp | 5 ++- clang/test/Driver/linux-ld.c | 75 ++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+), 2 deletions(-) diff --git a/clang/lib/Driver/Tools.cpp b/clang/lib/Driver/Tools.cpp index 76b7962cd559..19816f745dce 100644 --- a/clang/lib/Driver/Tools.cpp +++ b/clang/lib/Driver/Tools.cpp @@ -7169,8 +7169,9 @@ void gnutools::Link::ConstructJob(Compilation &C, const JobAction &JA, } AddRunTimeLibs(ToolChain, D, CmdArgs, Args); - if (Args.hasArg(options::OPT_pthread) || - Args.hasArg(options::OPT_pthreads) || UsedOpenMPLib != LibUnknown) + if (!isAndroid && + (Args.hasArg(options::OPT_pthread) || + Args.hasArg(options::OPT_pthreads) || UsedOpenMPLib != LibUnknown)) CmdArgs.push_back("-lpthread"); CmdArgs.push_back("-lc"); diff --git a/clang/test/Driver/linux-ld.c b/clang/test/Driver/linux-ld.c index 5509e5341962..019e7e92f77d 100644 --- a/clang/test/Driver/linux-ld.c +++ b/clang/test/Driver/linux-ld.c @@ -820,6 +820,81 @@ // CHECK-ANDROID-32: "-dynamic-linker" "/system/bin/linker" // CHECK-ANDROID-64: "-dynamic-linker" "/system/bin/linker64" // +// Test that -pthread does not add -lpthread on Android. +// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \ +// RUN: --target=arm-linux-androideabi -pthread \ +// RUN: --sysroot=%S/Inputs/basic_android_tree/sysroot \ +// RUN: | FileCheck --check-prefix=CHECK-ANDROID-PTHREAD %s +// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \ +// RUN: --target=arm-linux-android -pthread \ +// RUN: --sysroot=%S/Inputs/basic_android_tree/sysroot \ +// RUN: | FileCheck --check-prefix=CHECK-ANDROID-PTHREAD %s +// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \ +// RUN: --target=aarch64-linux-android -pthread \ +// RUN: --sysroot=%S/Inputs/basic_android_tree/sysroot \ +// RUN: | FileCheck --check-prefix=CHECK-ANDROID-PTHREAD %s +// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \ +// RUN: --target=arm64-linux-android -pthread \ +// RUN: --sysroot=%S/Inputs/basic_android_tree/sysroot \ +// RUN: | FileCheck --check-prefix=CHECK-ANDROID-PTHREAD %s +// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \ +// RUN: --target=mipsel-linux-android -pthread \ +// RUN: --sysroot=%S/Inputs/basic_android_tree/sysroot \ +// RUN: | FileCheck --check-prefix=CHECK-ANDROID-PTHREAD %s +// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \ +// RUN: --target=mips64el-linux-android -pthread \ +// RUN: --sysroot=%S/Inputs/basic_android_tree/sysroot \ +// RUN: | FileCheck --check-prefix=CHECK-ANDROID-PTHREAD %s +// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \ +// RUN: --target=i686-linux-android -pthread \ +// RUN: --sysroot=%S/Inputs/basic_android_tree/sysroot \ +// RUN: | FileCheck --check-prefix=CHECK-ANDROID-PTHREAD %s +// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \ +// RUN: --target=x86_64-linux-android -pthread \ +// RUN: --sysroot=%S/Inputs/basic_android_tree/sysroot \ +// RUN: | FileCheck --check-prefix=CHECK-ANDROID-PTHREAD %s +// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \ +// RUN: --target=arm-linux-androideabi -pthread \ +// RUN: --sysroot=%S/Inputs/basic_android_tree/sysroot \ +// RUN: -shared \ +// RUN: | FileCheck --check-prefix=CHECK-ANDROID-PTHREAD %s +// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \ +// RUN: --target=arm-linux-android -pthread \ +// RUN: --sysroot=%S/Inputs/basic_android_tree/sysroot \ +// RUN: -shared \ +// RUN: | FileCheck --check-prefix=CHECK-ANDROID-PTHREAD %s +// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \ +// RUN: --target=aarch64-linux-android -pthread \ +// RUN: --sysroot=%S/Inputs/basic_android_tree/sysroot \ +// RUN: -shared \ +// RUN: | FileCheck --check-prefix=CHECK-ANDROID-PTHREAD %s +// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \ +// RUN: --target=arm64-linux-android -pthread \ +// RUN: --sysroot=%S/Inputs/basic_android_tree/sysroot \ +// RUN: -shared \ +// RUN: | FileCheck --check-prefix=CHECK-ANDROID-PTHREAD %s +// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \ +// RUN: --target=mipsel-linux-android -pthread \ +// RUN: --sysroot=%S/Inputs/basic_android_tree/sysroot \ +// RUN: -shared \ +// RUN: | FileCheck --check-prefix=CHECK-ANDROID-PTHREAD %s +// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \ +// RUN: --target=mips64el-linux-android -pthread \ +// RUN: --sysroot=%S/Inputs/basic_android_tree/sysroot \ +// RUN: -shared \ +// RUN: | FileCheck --check-prefix=CHECK-ANDROID-PTHREAD %s +// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \ +// RUN: --target=i686-linux-android -pthread \ +// RUN: --sysroot=%S/Inputs/basic_android_tree/sysroot \ +// RUN: -shared \ +// RUN: | FileCheck --check-prefix=CHECK-ANDROID-PTHREAD %s +// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \ +// RUN: --target=x86_64-linux-android -pthread \ +// RUN: --sysroot=%S/Inputs/basic_android_tree/sysroot \ +// RUN: -shared \ +// RUN: | FileCheck --check-prefix=CHECK-ANDROID-PTHREAD %s +// CHECK-ANDROID-PTHREAD-NOT: -lpthread +// // Check linker invocation on Debian 6 MIPS 32/64-bit. // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \ // RUN: --target=mipsel-linux-gnu \