Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions clang/lib/Driver/ToolChains/Darwin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1645,14 +1645,16 @@ void DarwinClang::AddLinkRuntimeLibArgs(const ArgList &Args,
CmdArgs.push_back("-lSystem");

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

Expand Down
11 changes: 10 additions & 1 deletion clang/test/Driver/darwin-ld.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,15 @@
// RUN: FileCheck -check-prefix=LINK_NO_IOS_ARM64_LIBGCC_S %s < %t.log
// LINK_NO_IOS_ARM64_LIBGCC_S-NOT: lgcc_s.1

// Check that clang links with libgcc_s.1 for Mac OS X 10.5 and earlier, but not arm64
// RUN: %clang -target x86_64-apple-macosx10.5 -mmacosx-version-min=10.5 -### %t.o 2> %t.log
// RUN: FileCheck -check-prefix=LINK_OSX_LIBGCC_S %s < %t.log
// LINK_OSX_LIBGCC_S: lgcc_s.1

// RUN: %clang -target arm64-apple-macosx10.5 -mmacosx-version-min=10.5 -### %t.o 2> %t.log
// RUN: FileCheck -check-prefix=LINK_NO_OSX_ARM64_LIBGCC_S %s < %t.log
// LINK_NO_OSX_ARM64_LIBGCC_S-NOT: lgcc_s.1

// RUN: %clang -target x86_64-apple-darwin12 -rdynamic -### %t.o \
// RUN: -fuse-ld= -mlinker-version=100 2> %t.log
// RUN: FileCheck -check-prefix=LINK_NO_EXPORT_DYNAMIC %s < %t.log
Expand Down Expand Up @@ -385,4 +394,4 @@
// RUN: %clang -target armv7em-apple-darwin -mno-outline -### %t.o 2> %t.log
// RUN: FileCheck -check-prefix=ARMV7EM-MNO_OUTLINE %s < %t.log
// ARMV7EM-MNO_OUTLINE: {{ld(.exe)?"}}
// ARMV7EM-MNO_OUTLINE-SAME: "-mllvm" "-enable-machine-outliner=never" "-mllvm" "-enable-linkonceodr-outlining"
// ARMV7EM-MNO_OUTLINE-SAME: "-mllvm" "-enable-machine-outliner=never" "-mllvm" "-enable-linkonceodr-outlining"