Skip to content

Commit a72d462

Browse files
committed
Re-apply "[CMake][compiler-rt][AArch64] Avoid preprocessing LSE builtins separately"
aa772fc (D92530) has landed fixing relocations on Darwin. 3000c19 (D93236) has landed working around an assembly parser bug on Darwin. Previous quick-fix d9697c2 (D93198) included in this commit. Invoking the preprocessor ourselves is fragile and would require us to replicate CMake's handling of definitions, compiler flags, etc for proper compatibility. In my toolchain builds this notably resulted in a bunch of warnings from unused flags as my CMAKE_C_FLAGS includes CPU-specific optimization options. Notably this part was already duplicating the logic for VISIBILITY_HIDDEN define. Instead, symlink the files and set the proper set of defines on each. This should also be faster as we avoid invoking the compiler multiple times. Fixes https://llvm.org/PR48494 Differential Revision: https://reviews.llvm.org/D93278
1 parent 3000c19 commit a72d462

File tree

3 files changed

+14
-17
lines changed

3 files changed

+14
-17
lines changed

compiler-rt/cmake/Modules/CompilerRTDarwinUtils.cmake

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,9 @@ macro(darwin_add_builtin_libraries)
395395
set(CMAKE_CXX_FLAGS "")
396396
set(CMAKE_ASM_FLAGS "")
397397

398-
set(PROFILE_SOURCES ../profile/InstrProfiling
398+
append_string_if(COMPILER_RT_HAS_ASM_LSE " -DHAS_ASM_LSE" CFLAGS)
399+
400+
set(PROFILE_SOURCES ../profile/InstrProfiling
399401
../profile/InstrProfilingBuffer
400402
../profile/InstrProfilingPlatformDarwin
401403
../profile/InstrProfilingWriter

compiler-rt/lib/builtins/CMakeLists.txt

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -509,31 +509,24 @@ set(aarch64_SOURCES
509509
)
510510

511511
# Generate outline atomics helpers from lse.S base
512-
set(CUSTOM_FLAGS ${CMAKE_C_FLAGS})
513-
if(NOT ANDROID)
514-
append_list_if(COMPILER_RT_HAS_VISIBILITY_HIDDEN_FLAG -DVISIBILITY_HIDDEN CUSTOM_FLAGS)
515-
endif()
516-
append_list_if(COMPILER_RT_HAS_ASM_LSE -DHAS_ASM_LSE CUSTOM_FLAGS)
517-
string(REPLACE " " "\t" CUSTOM_FLAGS "${CUSTOM_FLAGS}")
518512
set(OA_HELPERS_DIR "${CMAKE_CURRENT_BINARY_DIR}/outline_atomic_helpers.dir")
519-
file(MAKE_DIRECTORY ${OA_HELPERS_DIR})
513+
file(MAKE_DIRECTORY "${OA_HELPERS_DIR}")
520514

521515
foreach(pat cas swp ldadd ldclr ldeor ldset)
522516
foreach(size 1 2 4 8 16)
523517
foreach(model 1 2 3 4)
524518
if(pat STREQUAL "cas" OR NOT size STREQUAL "16")
525-
set(helper_asm ${OA_HELPERS_DIR}/outline_atomic_${pat}${size}_${model}.S)
519+
set(helper_asm "${OA_HELPERS_DIR}/outline_atomic_${pat}${size}_${model}.S")
526520
add_custom_command(
527521
OUTPUT ${helper_asm}
528-
COMMAND ${CMAKE_C_COMPILER} -E ${CUSTOM_FLAGS} -DL_${pat} -DSIZE=${size} -DMODEL=${model}
529-
${CMAKE_CURRENT_SOURCE_DIR}/aarch64/lse.S -o ${helper_asm}
530-
DEPENDS aarch64/lse.S assembly.h
522+
COMMAND ${CMAKE_COMMAND} -E create_symlink "${CMAKE_CURRENT_SOURCE_DIR}/aarch64/lse.S" "${helper_asm}"
531523
)
532-
set_source_files_properties(${helper_asm} PROPERTIES GENERATED TRUE)
533-
set(aarch64_SOURCES
534-
${aarch64_SOURCES}
535-
${helper_asm}
524+
set_source_files_properties("${helper_asm}"
525+
PROPERTIES
526+
COMPILE_DEFINITIONS "L_${pat};SIZE=${size};MODEL=${model}"
527+
INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}"
536528
)
529+
list(APPEND aarch64_SOURCES "${helper_asm}")
537530
endif()
538531
endforeach(model)
539532
endforeach(size)
@@ -687,6 +680,8 @@ else ()
687680
append_list_if(COMPILER_RT_HAS_VISIBILITY_HIDDEN_FLAG VISIBILITY_HIDDEN BUILTIN_DEFS)
688681
endif()
689682

683+
append_list_if(COMPILER_RT_HAS_ASM_LSE HAS_ASM_LSE BUILTIN_DEFS)
684+
690685
foreach (arch ${BUILTIN_SUPPORTED_ARCH})
691686
if (CAN_TARGET_${arch})
692687
# For ARM archs, exclude any VFP builtins if VFP is not supported

compiler-rt/lib/builtins/aarch64/lse.S

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// See https://llvm.org/LICENSE.txt for license information.
33
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
44

5-
#include "../assembly.h"
5+
#include "assembly.h"
66

77
// Out-of-line LSE atomics helpers. Ported from libgcc library.
88
// N = {1, 2, 4, 8}

0 commit comments

Comments
 (0)