Skip to content

Commit 803c4a9

Browse files
authored
Merge pull request #1553 from hyp/bastille
🇫🇷 Bastille branch 🇫🇷 [darwin] build and link with a separate compiler-rt builtins library for device simulators
2 parents 8ef5bf2 + 6639ca4 commit 803c4a9

File tree

4 files changed

+32
-6
lines changed

4 files changed

+32
-6
lines changed

clang/lib/Driver/ToolChains/Darwin.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,10 +1104,9 @@ void MachO::AddLinkRuntimeLib(const ArgList &Args, ArgStringList &CmdArgs,
11041104
DarwinLibName += Component;
11051105
if (!(Opts & RLO_IsEmbedded))
11061106
DarwinLibName += "_";
1107-
DarwinLibName += getOSLibraryNameSuffix();
1108-
} else
1109-
DarwinLibName += getOSLibraryNameSuffix(true);
1107+
}
11101108

1109+
DarwinLibName += getOSLibraryNameSuffix();
11111110
DarwinLibName += IsShared ? "_dynamic.dylib" : ".a";
11121111
SmallString<128> Dir(getDriver().ResourceDir);
11131112
llvm::sys::path::append(

clang/test/Driver/Inputs/resource_dir/lib/darwin/libclang_rt.iossim.a

Whitespace-only changes.

clang/test/Driver/darwin-ld.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@
163163
// RUN: FileCheck -check-prefix=LINK_IOSSIM_PROFILE %s < %t.log
164164
// LINK_IOSSIM_PROFILE: {{ld(.exe)?"}}
165165
// LINK_IOSSIM_PROFILE: libclang_rt.profile_iossim.a
166-
// LINK_IOSSIM_PROFILE: libclang_rt.ios.a
166+
// LINK_IOSSIM_PROFILE: libclang_rt.iossim.a
167167

168168
// RUN: %clang -target x86_64-apple-ios13-macabi -mlinker-version=400 -fprofile-instr-generate -### %t.o 2> %t.log
169169
// RUN: FileCheck -check-prefix=LINK_MACABI_PROFILE %s < %t.log

compiler-rt/cmake/Modules/CompilerRTDarwinUtils.cmake

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,15 @@ macro(darwin_add_builtin_library name suffix)
289289
endforeach(cflag)
290290
endif()
291291

292+
if ("${LIB_OS}" MATCHES ".*sim$")
293+
# Pass an explicit -simulator environment to the -target option to ensure
294+
# that we don't rely on the architecture to infer whether we're building
295+
# for the simulator.
296+
string(REGEX REPLACE "sim" "" base_os "${LIB_OS}")
297+
list(APPEND builtin_cflags
298+
-target "${LIB_ARCH}-apple-${base_os}${DARWIN_${LIBOS}_BUILTIN_MIN_VER}-simulator")
299+
endif()
300+
292301
set_target_compile_flags(${libname}
293302
${sysroot_flag}
294303
${DARWIN_${LIB_OS}_BUILTIN_MIN_VER_FLAG}
@@ -449,15 +458,33 @@ macro(darwin_add_builtin_libraries)
449458
endif()
450459
endforeach()
451460

452-
# We put the x86 sim slices into the archives for their base OS
453461
foreach (os ${ARGN})
462+
# We put the x86 sim slices into the archives for their base OS
463+
# FIXME: Stop doing that in upstream Phab review (blocked by swift side
464+
# support as well).
454465
if(NOT ${os} MATCHES ".*sim$")
466+
set(sim_flags ${${os}sim_builtins_lipo_flags})
467+
# Do not include the arm64 slice in the `lipo` invocation for the device
468+
# libclang_rt.<os>.a . This ensures that `lipo` uses the device arm64
469+
# slice in libclang_rt.<os>.a. The simulator arm64 slice is present only
470+
# in libclang_rt.<os>sim.a .
471+
if (NOT "${sim_flags}" STREQUAL "")
472+
string(REGEX REPLACE ";-arch;arm64.*" "" sim_flags "${sim_flags}")
473+
message(STATUS "adjusted simulator flags for non-sim builtin lib: ${sim_flags}")
474+
endif()
455475
darwin_lipo_libs(clang_rt.${os}
456476
PARENT_TARGET builtins
457-
LIPO_FLAGS ${${os}_builtins_lipo_flags} ${${os}sim_builtins_lipo_flags}
477+
LIPO_FLAGS ${${os}_builtins_lipo_flags} ${sim_flags}
458478
DEPENDS ${${os}_builtins_libs} ${${os}sim_builtins_libs}
459479
OUTPUT_DIR ${COMPILER_RT_LIBRARY_OUTPUT_DIR}
460480
INSTALL_DIR ${COMPILER_RT_LIBRARY_INSTALL_DIR})
481+
else()
482+
darwin_lipo_libs(clang_rt.${os}
483+
PARENT_TARGET builtins
484+
LIPO_FLAGS ${${os}_builtins_lipo_flags}
485+
DEPENDS ${${os}_builtins_libs}
486+
OUTPUT_DIR ${COMPILER_RT_LIBRARY_OUTPUT_DIR}
487+
INSTALL_DIR ${COMPILER_RT_LIBRARY_INSTALL_DIR})
461488
endif()
462489
endforeach()
463490
darwin_add_embedded_builtin_libraries()

0 commit comments

Comments
 (0)