Skip to content

Commit c9e0e86

Browse files
authored
Merge pull request #1552 from hyp/bowie-compiler-rt-arm64-sim
Bowie branch [darwin] build and link with a separate compiler-rt builtins library for device simulators
2 parents f41550a + a7c6eee commit c9e0e86

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
@@ -1078,10 +1078,9 @@ void MachO::AddLinkRuntimeLib(const ArgList &Args, ArgStringList &CmdArgs,
10781078
DarwinLibName += Component;
10791079
if (!(Opts & RLO_IsEmbedded))
10801080
DarwinLibName += "_";
1081-
DarwinLibName += getOSLibraryNameSuffix();
1082-
} else
1083-
DarwinLibName += getOSLibraryNameSuffix(true);
1081+
}
10841082

1083+
DarwinLibName += getOSLibraryNameSuffix();
10851084
DarwinLibName += IsShared ? "_dynamic.dylib" : ".a";
10861085
SmallString<128> Dir(getDriver().ResourceDir);
10871086
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
@@ -286,6 +286,15 @@ macro(darwin_add_builtin_library name suffix)
286286
endforeach(cflag)
287287
endif()
288288

289+
if ("${LIB_OS}" MATCHES ".*sim$")
290+
# Pass an explicit -simulator environment to the -target option to ensure
291+
# that we don't rely on the architecture to infer whether we're building
292+
# for the simulator.
293+
string(REGEX REPLACE "sim" "" base_os "${LIB_OS}")
294+
list(APPEND builtin_cflags
295+
-target "${LIB_ARCH}-apple-${base_os}${DARWIN_${LIBOS}_BUILTIN_MIN_VER}-simulator")
296+
endif()
297+
289298
set_target_compile_flags(${libname}
290299
${sysroot_flag}
291300
${DARWIN_${LIB_OS}_BUILTIN_MIN_VER_FLAG}
@@ -412,15 +421,33 @@ macro(darwin_add_builtin_libraries)
412421
endif()
413422
endforeach()
414423

415-
# We put the x86 sim slices into the archives for their base OS
416424
foreach (os ${ARGN})
425+
# We put the x86 sim slices into the archives for their base OS
426+
# FIXME: Stop doing that in upstream Phab review (blocked by swift side
427+
# support as well).
417428
if(NOT ${os} MATCHES ".*sim$")
429+
set(sim_flags ${${os}sim_builtins_lipo_flags})
430+
# Do not include the arm64 slice in the `lipo` invocation for the device
431+
# libclang_rt.<os>.a . This ensures that `lipo` uses the device arm64
432+
# slice in libclang_rt.<os>.a. The simulator arm64 slice is present only
433+
# in libclang_rt.<os>sim.a .
434+
if (NOT "${sim_flags}" STREQUAL "")
435+
string(REGEX REPLACE ";-arch;arm64.*" "" sim_flags "${sim_flags}")
436+
message(STATUS "adjusted simulator flags for non-sim builtin lib: ${sim_flags}")
437+
endif()
418438
darwin_lipo_libs(clang_rt.${os}
419439
PARENT_TARGET builtins
420-
LIPO_FLAGS ${${os}_builtins_lipo_flags} ${${os}sim_builtins_lipo_flags}
440+
LIPO_FLAGS ${${os}_builtins_lipo_flags} ${sim_flags}
421441
DEPENDS ${${os}_builtins_libs} ${${os}sim_builtins_libs}
422442
OUTPUT_DIR ${COMPILER_RT_LIBRARY_OUTPUT_DIR}
423443
INSTALL_DIR ${COMPILER_RT_LIBRARY_INSTALL_DIR})
444+
else()
445+
darwin_lipo_libs(clang_rt.${os}
446+
PARENT_TARGET builtins
447+
LIPO_FLAGS ${${os}_builtins_lipo_flags}
448+
DEPENDS ${${os}_builtins_libs}
449+
OUTPUT_DIR ${COMPILER_RT_LIBRARY_OUTPUT_DIR}
450+
INSTALL_DIR ${COMPILER_RT_LIBRARY_INSTALL_DIR})
424451
endif()
425452
endforeach()
426453
darwin_add_embedded_builtin_libraries()

0 commit comments

Comments
 (0)