xref: /aosp_15_r20/external/pigweed/pw_toolchain/arm_gcc/BUILD.gn (revision 61c4878ac05f98d0ceed94b57d316916de578985)
1# Copyright 2020 The Pigweed Authors
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may not
4# use this file except in compliance with the License. You may obtain a copy of
5# the License at
6#
7#     https://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations under
13# the License.
14
15import("//build_overrides/pigweed.gni")
16import("//build_overrides/pigweed_environment.gni")
17
18import("$dir_pw_build/target_types.gni")
19import("$dir_pw_toolchain/generate_toolchain.gni")
20
21# Disable obnoxious ABI warning.
22#
23# GCC 7.1 adds an over-zealous ABI warning with little useful information
24# on how to resolve the issue. The warning you get is:
25#
26#   note: parameter passing for argument of type '...' changed in GCC 7.1
27#
28# There is no other information, and searching for the error is needed to
29# understand what is happening. For upstream Pigweed, we compile from
30# source so this is irrelevant; so disable it.
31#
32# See: https://gcc.gnu.org/gcc-7/changes.html (search for "psabi").
33#      https://gcc.gnu.org/ml/gcc/2017-05/msg00073.html
34config("disable_psabi_warning") {
35  cflags = [ "-Wno-psabi" ]
36}
37
38# binutils 2.39 introduced new warnings that trigger on embedded ARM GCC builds:
39#
40#   warning: *.elf has a LOAD segment with RWX permissions
41#
42# Disable these warnings --no-warn-rwx-segment. For details see:
43# https://www.redhat.com/en/blog/linkers-warnings-about-executable-stacks-and-segments
44config("disable_rwx_segment_warning") {
45  ldflags = [ "-Wl,--no-warn-rwx-segment" ]
46}
47
48config("cortex_common") {
49  asmflags = [
50    "-mabi=aapcs",
51    "-mthumb",
52  ]
53  cflags = asmflags + [
54             "--sysroot=" + rebase_path(pw_env_setup_CIPD_ARM, root_build_dir),
55             "-specs=nano.specs",
56             "-specs=nosys.specs",
57           ]
58  ldflags = cflags + [
59              "-lnosys",
60              "-lc",
61            ]
62}
63
64config("enable_float_printf") {
65  cflags = [ "-u_printf_float" ]
66  ldflags = cflags
67}
68
69config("cortex_m0plus") {
70  cflags = [ "-mcpu=cortex-m0plus" ]
71  asmflags = cflags
72  ldflags = cflags
73}
74
75config("cortex_m3") {
76  cflags = [ "-mcpu=cortex-m3" ]
77  asmflags = cflags
78  ldflags = cflags
79}
80
81config("cortex_m4") {
82  cflags = [ "-mcpu=cortex-m4" ]
83  asmflags = cflags
84  ldflags = cflags
85}
86
87config("cortex_m7") {
88  cflags = [ "-mcpu=cortex-m7" ]
89  asmflags = cflags
90  ldflags = cflags
91}
92
93config("cortex_m33") {
94  cflags = [ "-mcpu=cortex-m33" ]
95  asmflags = cflags
96  ldflags = cflags
97}
98
99config("cortex_m55") {
100  cflags = [ "-mcpu=cortex-m55" ]
101  asmflags = cflags
102  ldflags = cflags
103}
104
105config("cortex_a32") {
106  cflags = [ "-mcpu=cortex-a32" ]
107  asmflags = cflags
108  ldflags = cflags
109}
110
111config("cortex_software_fpu") {
112  cflags = [ "-mfloat-abi=soft" ]
113  asmflags = cflags
114  ldflags = cflags
115}
116
117config("cortex_hardware_fpu") {
118  cflags = [
119    "-mfloat-abi=hard",
120    "-mfpu=fpv4-sp-d16",
121  ]
122  asmflags = cflags
123  defines = [ "PW_ARMV7M_ENABLE_FPU=1" ]
124  ldflags = cflags
125}
126
127config("cortex_hardware_fpu_v5") {
128  cflags = [
129    "-mfloat-abi=hard",
130    "-mfpu=fpv5-d16",
131  ]
132  asmflags = cflags
133  defines = [ "PW_ARMV7M_ENABLE_FPU=1" ]
134  ldflags = cflags
135}
136
137config("cortex_hardware_fpu_v5_sp") {
138  cflags = [
139    "-mfloat-abi=hard",
140    "-mfpu=fpv5-sp-d16",
141  ]
142  asmflags = cflags
143  defines = [ "PW_ARMV7M_ENABLE_FPU=1" ]
144  ldflags = cflags
145}
146
147config("cortex_hardware_fpu_auto") {
148  cflags = [
149    "-mfloat-abi=hard",
150    "-mfpu=auto",
151  ]
152  asmflags = cflags
153  ldflags = cflags
154}
155
156config("wrap_newlib_stdio_functions") {
157  ldflags = [
158    "-Wl,--wrap=__sread",
159    "-Wl,--wrap=__swrite",
160    "-Wl,--wrap=__sseek",
161    "-Wl,--wrap=__sclose",
162  ]
163  visibility = [ ":*" ]
164}
165
166pw_source_set("newlib_os_interface_stubs") {
167  all_dependent_configs = [ ":wrap_newlib_stdio_functions" ]
168  sources = [ "newlib_os_interface_stubs.cc" ]
169  deps = [ dir_pw_assert ]
170}
171
172# Basic libraries any arm-none-eabi-gcc target should use. This library should
173# be included in pw_build_LINK_DEPS.
174group("arm_none_eabi_gcc_support") {
175  deps = [ "$dir_pw_toolchain:wrap_abort" ]
176
177  # TODO: b/301079199 - Stubs are not yet usable on clang.
178  # AttempedToInvokeUnsupportedNewlibOsInterfaceFunction (write_) is triggering,
179  # but not sure why yet.
180  # TODO: b/301262374 - Provide a better way to detect the compiler type.
181  if (get_path_info(pw_toolchain_SCOPE.cc, "file") != "clang") {
182    deps += [ ":newlib_os_interface_stubs" ]
183  }
184}
185