Skip to content

Commit 579326c

Browse files
Un1q32tomtor
authored andcommitted
[Clang] Link libgcc_s.1.dylib when building for macOS 10.5 and older (llvm#141401)
1 parent 350c785 commit 579326c

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

clang/lib/Driver/ToolChains/Darwin.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1642,14 +1642,16 @@ void DarwinClang::AddLinkRuntimeLibArgs(const ArgList &Args,
16421642
CmdArgs.push_back("-lSystem");
16431643

16441644
// Select the dynamic runtime library and the target specific static library.
1645-
if (isTargetIOSBased()) {
1646-
// If we are compiling as iOS / simulator, don't attempt to link libgcc_s.1,
1647-
// it never went into the SDK.
1648-
// Linking against libgcc_s.1 isn't needed for iOS 5.0+
1649-
if (isIPhoneOSVersionLT(5, 0) && !isTargetIOSSimulator() &&
1650-
getTriple().getArch() != llvm::Triple::aarch64)
1651-
CmdArgs.push_back("-lgcc_s.1");
1652-
}
1645+
// Some old Darwin versions put builtins, libunwind, and some other stuff in
1646+
// libgcc_s.1.dylib. MacOS X 10.6 and iOS 5 moved those functions to
1647+
// libSystem, and made libgcc_s.1.dylib a stub. We never link libgcc_s when
1648+
// building for aarch64 or iOS simulator, since libgcc_s was made obsolete
1649+
// before either existed.
1650+
if (getTriple().getArch() != llvm::Triple::aarch64 &&
1651+
((isTargetIOSBased() && isIPhoneOSVersionLT(5, 0) &&
1652+
!isTargetIOSSimulator()) ||
1653+
(isTargetMacOSBased() && isMacosxVersionLT(10, 6))))
1654+
CmdArgs.push_back("-lgcc_s.1");
16531655
AddLinkRuntimeLib(Args, CmdArgs, "builtins");
16541656
}
16551657

clang/test/Driver/darwin-ld.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,15 @@
240240
// RUN: FileCheck -check-prefix=LINK_NO_IOS_ARM64_LIBGCC_S %s < %t.log
241241
// LINK_NO_IOS_ARM64_LIBGCC_S-NOT: lgcc_s.1
242242

243+
// Check that clang links with libgcc_s.1 for Mac OS X 10.5 and earlier, but not arm64
244+
// RUN: %clang -target x86_64-apple-macosx10.5 -mmacosx-version-min=10.5 -### %t.o 2> %t.log
245+
// RUN: FileCheck -check-prefix=LINK_OSX_LIBGCC_S %s < %t.log
246+
// LINK_OSX_LIBGCC_S: lgcc_s.1
247+
248+
// RUN: %clang -target arm64-apple-macosx10.5 -mmacosx-version-min=10.5 -### %t.o 2> %t.log
249+
// RUN: FileCheck -check-prefix=LINK_NO_OSX_ARM64_LIBGCC_S %s < %t.log
250+
// LINK_NO_OSX_ARM64_LIBGCC_S-NOT: lgcc_s.1
251+
243252
// RUN: %clang -target x86_64-apple-darwin12 -rdynamic -### %t.o \
244253
// RUN: -fuse-ld= -mlinker-version=100 2> %t.log
245254
// RUN: FileCheck -check-prefix=LINK_NO_EXPORT_DYNAMIC %s < %t.log
@@ -385,4 +394,4 @@
385394
// RUN: %clang -target armv7em-apple-darwin -mno-outline -### %t.o 2> %t.log
386395
// RUN: FileCheck -check-prefix=ARMV7EM-MNO_OUTLINE %s < %t.log
387396
// ARMV7EM-MNO_OUTLINE: {{ld(.exe)?"}}
388-
// ARMV7EM-MNO_OUTLINE-SAME: "-mllvm" "-enable-machine-outliner=never" "-mllvm" "-enable-linkonceodr-outlining"
397+
// ARMV7EM-MNO_OUTLINE-SAME: "-mllvm" "-enable-machine-outliner=never" "-mllvm" "-enable-linkonceodr-outlining"

0 commit comments

Comments
 (0)