Skip to content

Commit

Permalink
pw_toolchain: Support replacing GNU libs for ARM
Browse files Browse the repository at this point in the history
For projects that wish to completely move away from GNU libraries such
as newlib and prefer prebuilt LLVM libraries shipped with toolchain,
provide alternative configs that do not use the python script
`clang_arm_toolchain.py`.

Bug: b/322360978
Change-Id: I83bd1d7830b5749c3fb0dafe25e0e09dc527cbaa
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/250572
Commit-Queue: Prabhu Karthikeyan Rajasekaran <[email protected]>
Lint: Lint 🤖 <[email protected]>
Docs-Not-Needed: Prabhu Karthikeyan Rajasekaran <[email protected]>
Reviewed-by: Armando Montanez <[email protected]>
  • Loading branch information
Prabhuk authored and CQ Bot Account committed Dec 2, 2024
1 parent f7a18a2 commit 807a3aa
Showing 1 changed file with 56 additions and 14 deletions.
70 changes: 56 additions & 14 deletions pw_toolchain/arm_clang/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ import("//build_overrides/pigweed.gni")

import("clang_config.gni")

declare_args() {
pw_toolchain_USE_LLVM_PREBUILT_LIBRARIES = false
}

cortex_m_common_flags = [
"-mabi=aapcs",
"-mthumb",
Expand Down Expand Up @@ -49,12 +53,58 @@ config("enable_float_printf") {
ldflags = [ "-Wl,-u_printf_float" ]
}

pw_clang_arm_config("cortex_m0plus") {
cflags = [ "-mcpu=cortex-m0plus" ]
cflags += cortex_m_common_flags
cflags += cortex_m_software_fpu_flags
asmflags = cflags
ldflags = cflags
if (pw_toolchain_USE_LLVM_PREBUILT_LIBRARIES) {
cortex_m_common_link_flags = [
"-nostartfiles",
"-nostdlib++",
]
cortex_m_common_defines = [
# This macro is used by libc++ headers and normally would expand to std::_libcpp_verbose_abort,
# but we don't define that since we don't build with libc++ at the moment. For now, we can
# have this lower to a trap instruction.
"_LIBCPP_VERBOSE_ABORT(...)=__builtin_trap()",
]
config("cortex_m0plus") {
cflags = [
"-mcpu=cortex-m0plus",
"--target=armv6m-none-eabi",
]
cflags += cortex_m_common_flags
cflags += cortex_m_software_fpu_flags
asmflags = cflags
ldflags = cflags
ldflags += cortex_m_common_link_flags
defines = cortex_m_common_defines
}

config("cortex_m4") {
cflags = [
"-mcpu=cortex-m4",
"--target=armv7m-none-eabi",
]
cflags += cortex_m_common_flags
cflags += cortex_m_software_fpu_flags
asmflags = cflags
ldflags = cflags
ldflags += cortex_m_common_link_flags
defines = cortex_m_common_defines
}
} else {
pw_clang_arm_config("cortex_m0plus") {
cflags = [ "-mcpu=cortex-m0plus" ]
cflags += cortex_m_common_flags
cflags += cortex_m_software_fpu_flags
asmflags = cflags
ldflags = cflags
}

pw_clang_arm_config("cortex_m4") {
cflags = [ "-mcpu=cortex-m4" ]
cflags += cortex_m_common_flags
cflags += cortex_m_software_fpu_flags
asmflags = cflags
ldflags = cflags
}
}

pw_clang_arm_config("cortex_m3") {
Expand All @@ -66,14 +116,6 @@ pw_clang_arm_config("cortex_m3") {
rustflags = [ "--target=thumbv7m-none-eabi" ]
}

pw_clang_arm_config("cortex_m4") {
cflags = [ "-mcpu=cortex-m4" ]
cflags += cortex_m_common_flags
cflags += cortex_m_software_fpu_flags
asmflags = cflags
ldflags = cflags
}

pw_clang_arm_config("cortex_m4f") {
cflags = [ "-mcpu=cortex-m4" ]
cflags += cortex_m_common_flags
Expand Down

0 comments on commit 807a3aa

Please sign in to comment.