Skip to content
Open
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
54 changes: 54 additions & 0 deletions arm-software/embedded/arm-runtimes/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,60 @@ if(ENABLE_COMPILER_RT_TESTS)
add_dependencies(check-compiler-rt compiler_rt-check-compiler-rt)
endif()

# Build compiler-rt profile library after the C library is available.
ExternalProject_Add(
compiler_rt_profile
STAMP_DIR ${PROJECT_PREFIX}/compiler_rt_profile/${VARIANT_BUILD_ID}/stamp
BINARY_DIR ${PROJECT_PREFIX}/compiler_rt_profile/${VARIANT_BUILD_ID}/build
DOWNLOAD_DIR ${PROJECT_PREFIX}/compiler_rt_profile/${VARIANT_BUILD_ID}/dl
TMP_DIR ${PROJECT_PREFIX}/compiler_rt_profile/${VARIANT_BUILD_ID}/tmp
SOURCE_DIR ${llvmproject_src_dir}/runtimes
INSTALL_DIR compiler-rt-profile/install
DEPENDS compiler_rt-install clib-install
CMAKE_ARGS
${compiler_launcher_cmake_args}
-DCMAKE_AR=${LLVM_BINARY_DIR}/bin/llvm-ar${CMAKE_EXECUTABLE_SUFFIX}
-DCMAKE_ASM_COMPILER_TARGET=${target_triple}
-DCMAKE_ASM_FLAGS=${lib_compile_flags}
-DCMAKE_BUILD_TYPE=${LIBRARY_CMAKE_BUILD_TYPE}
-DCMAKE_CXX_COMPILER=${LLVM_BINARY_DIR}/bin/clang++${CMAKE_EXECUTABLE_SUFFIX}
-DCMAKE_CXX_COMPILER_TARGET=${target_triple}
-DCMAKE_CXX_FLAGS=${lib_compile_flags}
-DCMAKE_C_COMPILER=${LLVM_BINARY_DIR}/bin/clang${CMAKE_EXECUTABLE_SUFFIX}
-DCMAKE_C_COMPILER_TARGET=${target_triple}
-DCMAKE_C_FLAGS=${lib_compile_flags}
-DCMAKE_INSTALL_MESSAGE=${CMAKE_INSTALL_MESSAGE}
-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>
-DCMAKE_NM=${LLVM_BINARY_DIR}/bin/llvm-nm${CMAKE_EXECUTABLE_SUFFIX}
-DCMAKE_RANLIB=${LLVM_BINARY_DIR}/bin/llvm-ranlib${CMAKE_EXECUTABLE_SUFFIX}
-DCMAKE_SYSTEM_NAME=Generic
Copy link
Contributor

@vhscampos vhscampos Dec 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where do all these options come from? Did you base it on something else?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the same as compiler_rt invocation for builtins

except that:

  • it is named compiler-rt-profile
  • it turns builtins OFF
  • it turns profile library ON and baremetal profile ON
  • it depends on builtins and C library

The profile library cannot be built in one go with builtins, because of dependencies: profile needs C library that needs builtins.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not know if there is a sensible way to move common part out to avoid duplication - hopefully, someone with more CMake experience can advise.

Copy link
Contributor

@vhscampos vhscampos Dec 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you could take all the common arguments and place them into another variable. It's not a major issue anyway, do it only if you want.

Example: the compiler_rt_cmake_args variable

-DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY
${compiler_rt_cmake_args}
-DCOMPILER_RT_BAREMETAL_BUILD=ON
-DCOMPILER_RT_BUILD_BUILTINS=OFF
-DCOMPILER_RT_BUILD_LIBFUZZER=OFF
-DCOMPILER_RT_BUILD_PROFILE=ON
-DCOMPILER_RT_PROFILE_BAREMETAL=ON
-DCOMPILER_RT_BUILD_SANITIZERS=OFF
-DCOMPILER_RT_BUILD_XRAY=OFF
-DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON
-DLLVM_ENABLE_RUNTIMES=compiler-rt
-DRUNTIME_VARIANT_NAME=${VARIANT}
-DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON
STEP_TARGETS configure build install
USES_TERMINAL_CONFIGURE TRUE
USES_TERMINAL_BUILD TRUE
USES_TERMINAL_INSTALL TRUE
LIST_SEPARATOR ,
CONFIGURE_HANDLED_BY_BUILD TRUE
INSTALL_COMMAND ${CMAKE_COMMAND} --install .
COMMAND
${CMAKE_COMMAND}
-E copy_directory
<INSTALL_DIR>/lib/${normalized_target_triple}
"${TEMP_LIB_DIR}/lib"
)

###############################################################################
# picolibc
###############################################################################
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ build: hello.elf
hello.elf: *.cpp
$(BIN_PATH)/clang -E -P -x c -DLIBC_LD_FILE=$(LIBC_LD_FILE) ../../ldscripts/microbit.ld.in -o microbit.ld
$(BIN_PATH)/clang $(CFG_FILE) $(MICROBIT_TARGET) -g -c proflib.c
$(BIN_PATH)/clang++ $(CFG_FILE) $(MICROBIT_TARGET) $(CRT_SEMIHOST) $(CPP_FLAGS) -g -T microbit.ld -fprofile-instr-generate -fcoverage-mapping -o hello.elf hello.cpp proflib.o
$(BIN_PATH)/clang++ $(CFG_FILE) $(MICROBIT_TARGET) $(CRT_SEMIHOST) $(CPP_FLAGS) -g -T microbit.ld -fprofile-instr-generate -fcoverage-mapping -o hello.elf hello.cpp proflib.o -lclang_rt.profile

%.hex: %.elf
$(BIN_PATH)/llvm-objcopy -O ihex $< $@
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,3 @@ and use it to show code coverage.

Use `make run` to build with instrumentation, run and collect the raw profile data,
then output a visualization of the code coverage.

NOTE: The upstream runtime implementation changes regularly,
thus `proflib.c` file needs to be updated to keep in sync.
Loading
Loading