Skip to content

Commit

Permalink
Fix two bugs for musl-libc on ARM
Browse files Browse the repository at this point in the history
Bug 1: triples like armv7-pc-linux-musl use the wrong linker name
ld-musl-armv7.so.1; the right name should be ld-musl-arm.so.1, disregarding the
subarch field.

Bug 2: when compiler option -mhard-float is used, we should use the "hardfloat"
linker, no matter whether the triple itself mentions "hardfloat".

Patch by Lei Zhang!

Differential Revision: https://reviews.llvm.org/D22904

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@277985 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
rovka committed Aug 8, 2016
1 parent c231913 commit 1812aa0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
13 changes: 11 additions & 2 deletions lib/Driver/ToolChains.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4274,19 +4274,28 @@ std::string Linux::getDynamicLinker(const ArgList &Args) const {

if (Triple.isAndroid())
return Triple.isArch64Bit() ? "/system/bin/linker64" : "/system/bin/linker";
else if (Triple.isMusl()) {

if (Triple.isMusl()) {
std::string ArchName;
bool IsArm = false;

switch (Arch) {
case llvm::Triple::arm:
case llvm::Triple::thumb:
ArchName = "arm";
IsArm = true;
break;
case llvm::Triple::armeb:
case llvm::Triple::thumbeb:
ArchName = "armeb";
IsArm = true;
break;
default:
ArchName = Triple.getArchName().str();
}
if (Triple.getEnvironment() == llvm::Triple::MuslEABIHF)
if (IsArm &&
(Triple.getEnvironment() == llvm::Triple::MuslEABIHF ||
tools::arm::getARMFloatABI(*this, Args) == tools::arm::FloatABI::Hard))
ArchName += "hf";

return "/lib/ld-musl-" + ArchName + ".so.1";
Expand Down
12 changes: 12 additions & 0 deletions test/Driver/linux-ld.c
Original file line number Diff line number Diff line change
Expand Up @@ -1613,24 +1613,36 @@
// RUN: --target=thumb-pc-linux-musleabihf \
// RUN: | FileCheck --check-prefix=CHECK-MUSL-ARMHF %s
// RUN: %clang %s -### -o %t.o 2>&1 \
// RUN: --target=thumbv7-pc-linux-musleabi -mhard-float \
// RUN: | FileCheck --check-prefix=CHECK-MUSL-ARMHF %s
// RUN: %clang %s -### -o %t.o 2>&1 \
// RUN: --target=thumbeb-pc-linux-musleabi \
// RUN: | FileCheck --check-prefix=CHECK-MUSL-ARMEB %s
// RUN: %clang %s -### -o %t.o 2>&1 \
// RUN: --target=thumbeb-pc-linux-musleabihf \
// RUN: | FileCheck --check-prefix=CHECK-MUSL-ARMEBHF %s
// RUN: %clang %s -### -o %t.o 2>&1 \
// RUN: --target=thumbv7eb-pc-linux-musleabi -mhard-float \
// RUN: | FileCheck --check-prefix=CHECK-MUSL-ARMEBHF %s
// RUN: %clang %s -### -o %t.o 2>&1 \
// RUN: --target=arm-pc-linux-musleabi \
// RUN: | FileCheck --check-prefix=CHECK-MUSL-ARM %s
// RUN: %clang %s -### -o %t.o 2>&1 \
// RUN: --target=arm-pc-linux-musleabihf \
// RUN: | FileCheck --check-prefix=CHECK-MUSL-ARMHF %s
// RUN: %clang %s -### -o %t.o 2>&1 \
// RUN: --target=armv7-pc-linux-musleabi -mhard-float \
// RUN: | FileCheck --check-prefix=CHECK-MUSL-ARMHF %s
// RUN: %clang %s -### -o %t.o 2>&1 \
// RUN: --target=armeb-pc-linux-musleabi \
// RUN: | FileCheck --check-prefix=CHECK-MUSL-ARMEB %s
// RUN: %clang %s -### -o %t.o 2>&1 \
// RUN: --target=armeb-pc-linux-musleabihf \
// RUN: | FileCheck --check-prefix=CHECK-MUSL-ARMEBHF %s
// RUN: %clang %s -### -o %t.o 2>&1 \
// RUN: --target=armv7eb-pc-linux-musleabi -mhard-float \
// RUN: | FileCheck --check-prefix=CHECK-MUSL-ARMEBHF %s
// RUN: %clang %s -### -o %t.o 2>&1 \
// RUN: --target=aarch64-pc-linux-musleabi \
// RUN: | FileCheck --check-prefix=CHECK-MUSL-AARCH64 %s
// RUN: %clang %s -### -o %t.o 2>&1 \
Expand Down

0 comments on commit 1812aa0

Please sign in to comment.