Zephyr Project API 4.5.0-rc2
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
gcc.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2010-2014,2017 Wind River Systems, Inc.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7#ifndef ZEPHYR_INCLUDE_TOOLCHAIN_GCC_H_
8#define ZEPHYR_INCLUDE_TOOLCHAIN_GCC_H_
9
10#ifndef ZEPHYR_INCLUDE_TOOLCHAIN_H_
11#error Please do not include toolchain-specific headers directly, use <zephyr/toolchain.h> instead
12#endif
13
20
21#define TOOLCHAIN_GCC_VERSION \
22 ((__GNUC__ * 10000) + (__GNUC_MINOR__ * 100) + __GNUC_PATCHLEVEL__)
23
24/* GCC supports #pragma diagnostics since 4.6.0 */
25#if !defined(TOOLCHAIN_HAS_PRAGMA_DIAG) && (TOOLCHAIN_GCC_VERSION >= 40600)
26#define TOOLCHAIN_HAS_PRAGMA_DIAG 1
27#endif
28
29#if !defined(TOOLCHAIN_HAS_C_GENERIC) && (TOOLCHAIN_GCC_VERSION >= 40900)
30#define TOOLCHAIN_HAS_C_GENERIC 1
31#endif
32
33#if !defined(TOOLCHAIN_HAS_C_AUTO_TYPE) && (TOOLCHAIN_GCC_VERSION >= 40900)
34#define TOOLCHAIN_HAS_C_AUTO_TYPE 1
35#endif
36
37#define TOOLCHAIN_HAS_ZLA 1
38
39/*
40 * Older versions of GCC do not define __BYTE_ORDER__, so it must be manually
41 * detected and defined using arch-specific definitions.
42 */
43
44#ifndef _LINKER
45
46#ifndef __ORDER_BIG_ENDIAN__
47#define __ORDER_BIG_ENDIAN__ (1)
48#endif
49
50#ifndef __ORDER_LITTLE_ENDIAN__
51#define __ORDER_LITTLE_ENDIAN__ (2)
52#endif
53
54#ifndef __BYTE_ORDER__
55#if defined(__BIG_ENDIAN__) || defined(__ARMEB__) || \
56 defined(__THUMBEB__) || defined(__AARCH64EB__) || \
57 defined(__MIPSEB__) || defined(__TC32EB__)
58
59#define __BYTE_ORDER__ __ORDER_BIG_ENDIAN__
60
61#elif defined(__LITTLE_ENDIAN__) || defined(__ARMEL__) || \
62 defined(__THUMBEL__) || defined(__AARCH64EL__) || \
63 defined(__MIPSEL__) || defined(__TC32EL__)
64
65#define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__
66
67#else
68#error "__BYTE_ORDER__ is not defined and cannot be automatically resolved"
69#endif
70#endif
71
72
73#undef BUILD_ASSERT /* clear out common version */
74/* C++11 has static_assert built in */
75#if defined(__cplusplus) && (__cplusplus >= 201103L)
76#define BUILD_ASSERT(EXPR, MSG...) static_assert(EXPR, "" MSG)
77
78/*
79 * GCC 4.6 and higher have the C11 _Static_assert built in and its
80 * output is easier to understand than the common BUILD_ASSERT macros.
81 * Don't use this in C++98 mode though (which we can hit, as
82 * static_assert() is not available)
83 */
84#elif !defined(__cplusplus) && \
85 (((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 6))) || \
86 (__STDC_VERSION__) >= 201100)
87#define BUILD_ASSERT(EXPR, MSG...) _Static_assert((EXPR), "" MSG)
88#else
89#define BUILD_ASSERT(EXPR, MSG...)
90#endif
91
92#ifdef __cplusplus
93#define ZRESTRICT __restrict
94#else
95#define ZRESTRICT restrict
96#endif
97
99#include <stdbool.h>
100
101#define ALIAS_OF(of) __attribute__((alias(#of)))
102
103#define FUNC_ALIAS(real_func, new_alias, return_type) \
104 return_type new_alias() ALIAS_OF(real_func)
105
106#if defined(CONFIG_ARCH_POSIX) && !defined(_ASMLANGUAGE)
108
109/*let's not segfault if this were to happen for some reason*/
110#define CODE_UNREACHABLE \
111{\
112 posix_print_error_and_exit("CODE_UNREACHABLE reached from %s:%d\n",\
113 __FILE__, __LINE__);\
114 __builtin_unreachable(); \
115}
116#else
117#define CODE_UNREACHABLE __builtin_unreachable()
118#endif
119#define FUNC_NORETURN __attribute__((__noreturn__))
120
121/* The GNU assembler for Cortex-M3 uses # for immediate values, not
122 * comments, so the @nobits# trick does not work.
123 */
124#if defined(CONFIG_ARM) || defined(CONFIG_ARM64)
125#define _NODATA_SECTION(segment) __attribute__((section(#segment)))
126#else
127#define _NODATA_SECTION(segment) \
128 __attribute__((section(#segment ",\"wa\",@nobits#")))
129#endif
130
131/* Unaligned access */
132#ifdef CONFIG_TRICORE
133#define UNALIGNED_GET(g) \
134 __extension__({ \
135 union { \
136 __typeof__(*(g)) __v; \
137 unsigned char __b[sizeof(__typeof__(*(g)))]; \
138 } __u = {0}; \
139 __builtin_memcpy(__u.__b, (const void *)(g), sizeof(__u.__b)); \
140 __u.__v; \
141 })
142#else
143#define UNALIGNED_GET(g) \
144__extension__ ({ \
145 struct __attribute__((__packed__)) { \
146 __typeof__(*(g)) __v; \
147 } *__g = (__typeof__(__g)) (g); \
148 __g->__v; \
149})
150#endif
151
152
153#if (__GNUC__ >= 7) && (defined(CONFIG_ARM) || defined(CONFIG_ARM64))
154
155/* Version of UNALIGNED_PUT() which issues a compiler_barrier() after
156 * the store. It is required to workaround an apparent optimization
157 * bug in GCC for ARM Cortex-M3 and higher targets, when multiple
158 * byte, half-word and word stores (strb, strh, str instructions),
159 * which support unaligned access, can be coalesced into store double
160 * (strd) instruction, which doesn't support unaligned access (the
161 * compilers in question do this optimization ignoring __packed__
162 * attribute).
163 */
164#define UNALIGNED_PUT(v, p) \
165do { \
166 struct __attribute__((__packed__)) { \
167 __typeof__(*p) __v; \
168 } *__p = (__typeof__(__p)) (p); \
169 __p->__v = (v); \
170 compiler_barrier(); \
171} while (false)
172
173#else
174
175#define UNALIGNED_PUT(v, p) \
176do { \
177 struct __attribute__((__packed__)) { \
178 __typeof__(*p) __v; \
179 } *__p = (__typeof__(__p)) (p); \
180 __p->__v = (v); \
181} while (false)
182
183#endif
184
185/*
186 * Get the address of a structure member even if the member may not be properly
187 * aligned. Note that accessing such an address must be done with care (for
188 * example with UNALIGNED_GET/PUT) and cannot be in general de-referenced to
189 * access the member directly, as that would cause a fault in architectures
190 * which have alignment requirements.
191 */
192#define UNALIGNED_MEMBER_ADDR(_p, _member) ((__typeof__(_p->_member) *) \
193 (((intptr_t)(_p)) + offsetof(__typeof__(*_p), _member)))
194
195/* Double indirection to ensure section names are expanded before
196 * stringification
197 */
198#define __GENERIC_SECTION(segment) __attribute__((section(STRINGIFY(segment))))
199#define Z_GENERIC_SECTION(segment) __GENERIC_SECTION(segment)
200
201#define __GENERIC_DOT_SECTION(segment) \
202 __attribute__((section("." STRINGIFY(segment))))
203#define Z_GENERIC_DOT_SECTION(segment) __GENERIC_DOT_SECTION(segment)
204
205#define ___in_section(a, b, c) \
206 __attribute__((section("." Z_STRINGIFY(a) \
207 "." Z_STRINGIFY(b) \
208 "." Z_STRINGIFY(c))))
209#define __in_section(a, b, c) ___in_section(a, b, c)
210
211#define ___in_section_unique(a, b) \
212 __attribute__((section("." Z_STRINGIFY(a) \
213 "." __FILE__ \
214 "." Z_STRINGIFY(b))))
215
216#ifndef __in_section_unique
217#define __in_section_unique(seg) ___in_section_unique(seg, __COUNTER__)
218#endif
219
220#ifndef __in_section_unique_named
221#define __in_section_unique_named(seg, name) ___in_section_unique(seg, name)
222#endif
223
224/* When using XIP, using '__ramfunc' places a function into RAM instead
225 * of FLASH. Make sure '__ramfunc' is defined only when
226 * CONFIG_ARCH_HAS_RAMFUNC_SUPPORT is defined, so that the compiler can
227 * report an error if '__ramfunc' is used but the architecture does not
228 * support it.
229 */
230#if !defined(CONFIG_XIP)
231#define __ramfunc
232#elif defined(CONFIG_ARCH_HAS_RAMFUNC_SUPPORT)
233#if defined(CONFIG_ARM)
234#if defined(__clang__)
235/* No long_call attribute for Clang.
236 * Rely on linker to place required veneers.
237 * https://github.com/llvm/llvm-project/issues/39969
238 */
239#define __ramfunc __attribute__((noinline)) __attribute__((section(".ramfunc")))
240#else
241/* GCC version */
242#define __ramfunc __attribute__((noinline)) \
243 __attribute__((long_call, section(".ramfunc")))
244#endif
245#else
246#define __ramfunc __attribute__((noinline)) \
247 __attribute__((section(".ramfunc")))
248#endif
249#endif /* !CONFIG_XIP */
250
251#ifndef __fallthrough
252#if __GNUC__ >= 7
253#define __fallthrough __attribute__((fallthrough))
254#else
255#define __fallthrough
256#endif /* __GNUC__ >= 7 */
257#endif
258
259#ifndef __packed
260#define __packed __attribute__((__packed__))
261#endif
262
263#ifndef __aligned
264#define __aligned(x) __attribute__((__aligned__(x)))
265#endif
266
267#ifndef __noinline
268#define __noinline __attribute__((noinline))
269#endif
270
271#define __may_alias __attribute__((__may_alias__))
272
273#ifndef __printf_like
274#ifdef CONFIG_ENFORCE_ZEPHYR_STDINT
275#define __printf_like(f, a) __attribute__((format (printf, f, a)))
276#else
277/*
278 * The Zephyr stdint convention enforces int32_t = int, int64_t = long long,
279 * and intptr_t = long so that short string format length modifiers can be
280 * used universally across ILP32 and LP64 architectures. Without that it
281 * is possible for ILP32 toolchains to have int32_t = long and intptr_t = int
282 * clashing with the Zephyr convention and generating pointless warnings
283 * as they're still the same size. Inhibit the format argument type
284 * validation in that case and let the other configs do it.
285 */
286#define __printf_like(f, a)
287#endif
288#endif
289
290#define __used __attribute__((__used__))
291#define __unused __attribute__((__unused__))
292#define __maybe_unused __attribute__((__unused__))
293
294#ifndef __deprecated
295#define __deprecated __attribute__((deprecated))
296/* When adding this, remember to follow the instructions in
297 * https://docs.zephyrproject.org/latest/develop/api/api_lifecycle.html#deprecated
298 */
299#endif
300
301#ifndef __deprecated_version
302#define __deprecated_version(version) \
303 __attribute__((deprecated("planned removal in v" #version)))
304#endif
305
306#ifndef __attribute_const__
307#define __attribute_const__ __attribute__((__const__))
308#endif
309
310#ifndef __must_check
311#define __must_check __attribute__((warn_unused_result))
312#endif
313
314#define ARG_UNUSED(x) (void)(x)
315
316#define likely(x) (__builtin_expect((bool)!!(x), true) != 0L)
317#define unlikely(x) (__builtin_expect((bool)!!(x), false) != 0L)
318#define POPCOUNT(x) __builtin_popcount(x)
319
320#ifndef __no_optimization
321#define __no_optimization __attribute__((optimize("-O0")))
322#endif
323
324#ifndef __weak
325#define __weak __attribute__((__weak__))
326#endif
327
328#ifndef __attribute_nonnull
329#define __attribute_nonnull(...) __attribute__((nonnull(__VA_ARGS__)))
330#endif
331
332#ifndef __cleanup
333#define __cleanup(x) __attribute__((cleanup(x)))
334#endif
335
336/* Builtins with availability that depend on the compiler version. */
337#if __GNUC__ >= 5
338#define HAS_BUILTIN___builtin_add_overflow 1
339#define HAS_BUILTIN___builtin_sub_overflow 1
340#define HAS_BUILTIN___builtin_mul_overflow 1
341#endif
342#if TOOLCHAIN_GCC_VERSION >= 40800
343#define HAS_BUILTIN___builtin_bswap16 1
344#endif
345#if TOOLCHAIN_GCC_VERSION >= 40300
346#define HAS_BUILTIN___builtin_bswap32 1
347#define HAS_BUILTIN___builtin_bswap64 1
348#endif
349#if __GNUC__ >= 4
350#define HAS_BUILTIN___builtin_clz 1
351#define HAS_BUILTIN___builtin_clzl 1
352#define HAS_BUILTIN___builtin_clzll 1
353#define HAS_BUILTIN___builtin_ctz 1
354#define HAS_BUILTIN___builtin_ctzl 1
355#define HAS_BUILTIN___builtin_ctzll 1
356#endif
357
358/*
359 * Be *very* careful with these. You cannot filter out __DEPRECATED_MACRO with
360 * -wno-deprecated, which has implications for -Werror.
361 */
362
368#ifndef TOOLCHAIN_PRAGMA_UNROLL
369#define _TOOLCHAIN_PRAGMA_UNROLL(x) _Pragma(#x)
370#define TOOLCHAIN_PRAGMA_UNROLL(n) _TOOLCHAIN_PRAGMA_UNROLL(GCC unroll n)
371#endif
372
373/*
374 * Expands to nothing and generates a warning. Used like
375 *
376 * #define FOO __WARN("Please use BAR instead") ...
377 *
378 * The warning points to the location where the macro is expanded.
379 */
380#define __WARN(msg) __WARN1(GCC warning msg)
381#define __WARN1(s) _Pragma(#s)
382
383/* Generic message */
384#if defined(CONFIG_WARN_DEPRECATED)
385#define __DEPRECATED_MACRO __WARN("Macro is deprecated")
386/* When adding this, remember to follow the instructions in
387 * https://docs.zephyrproject.org/latest/develop/api/api_lifecycle.html#deprecated
388 */
389#else
390#define __DEPRECATED_MACRO
391#endif
392
393/* These macros allow having ARM asm functions callable from thumb */
394
395#if defined(_ASMLANGUAGE)
396
397#if defined(CONFIG_ARM)
398
399#if defined(CONFIG_ASSEMBLER_ISA_THUMB2)
400
401#define FUNC_CODE() .thumb;
402#define FUNC_INSTR(a)
403
404#else
405
406#define FUNC_CODE() .code 32;
407#define FUNC_INSTR(a)
408
409#endif /* CONFIG_ASSEMBLER_ISA_THUMB2 */
410
411#else
412
413#define FUNC_CODE()
414#define FUNC_INSTR(a)
415
416#endif /* CONFIG_ARM */
417
418#endif /* _ASMLANGUAGE */
419
420/*
421 * These macros are used to declare assembly language symbols that need
422 * to be typed properly(func or data) to be visible to the OMF tool.
423 * So that the build tool could mark them as an entry point to be linked
424 * correctly. This is an elfism. Use #if 0 for a.out.
425 */
426
427#if defined(_ASMLANGUAGE)
428
429#if defined(CONFIG_ARM) || defined(CONFIG_RISCV) || defined(CONFIG_XTENSA) || \
430 defined(CONFIG_ARM64) || defined(CONFIG_MIPS) || defined(CONFIG_RX) || \
431 defined(CONFIG_OPENRISC) || defined(CONFIG_TRICORE)
432#define GTEXT(sym) .global sym; .type sym, %function
433#define GDATA(sym) .global sym; .type sym, %object
434#define WTEXT(sym) .weak sym; .type sym, %function
435#define WDATA(sym) .weak sym; .type sym, %object
436#elif defined(CONFIG_ARC)
437/*
438 * Need to use assembly macros because ';' is interpreted as the start of
439 * a single line comment in the ARC assembler.
440 */
441
442.macro glbl_text symbol
443 .globl \symbol
444 .type \symbol, %function
445.endm
446
447.macro glbl_data symbol
448 .globl \symbol
449 .type \symbol, %object
450.endm
451
452.macro weak_data symbol
453 .weak \symbol
454 .type \symbol, %object
455.endm
456
457#define GTEXT(sym) glbl_text sym
458#define GDATA(sym) glbl_data sym
459#define WDATA(sym) weak_data sym
460
461#else /* !CONFIG_ARM && !CONFIG_ARC */
462#define GTEXT(sym) .globl sym; .type sym, @function
463#define GDATA(sym) .globl sym; .type sym, @object
464#endif
465
466/*
467 * These macros specify the section in which a given function or variable
468 * resides.
469 *
470 * - SECTION_FUNC allows only one function to reside in a sub-section
471 * - SECTION_SUBSEC_FUNC allows multiple functions to reside in a sub-section
472 * This ensures that garbage collection only discards the section
473 * if all functions in the sub-section are not referenced.
474 */
475
476#if defined(CONFIG_ARC)
477/*
478 * Need to use assembly macros because ';' is interpreted as the start of
479 * a single line comment in the ARC assembler.
480 *
481 * Also, '\‍()' is needed in the .section directive of these macros for
482 * correct substitution of the 'section' variable.
483 */
484
485.macro section_var section, symbol
486 .section .\section\‍().\symbol
487 \symbol :
488.endm
489
490.macro section_func section, symbol
491 .section .\section\().\symbol, "ax"
492 FUNC_CODE()
493 PERFOPT_ALIGN
494 \symbol :
495 FUNC_INSTR(\symbol)
496.endm
497
498.macro section_subsec_func section, subsection, symbol
499 .section .\section\().\subsection, "ax"
500 PERFOPT_ALIGN
501 \symbol :
502.endm
503
504#define SECTION_VAR(sect, sym) section_var sect, sym
505#define SECTION_FUNC(sect, sym) section_func sect, sym
506#define SECTION_SUBSEC_FUNC(sect, subsec, sym) \
507 section_subsec_func sect, subsec, sym
508#else /* !CONFIG_ARC */
509
510#define SECTION_VAR(sect, sym) .section .sect.sym; sym:
511#define SECTION_FUNC(sect, sym) \
512 .section .sect.sym, "ax"; \
513 FUNC_CODE() \
514 PERFOPT_ALIGN; sym : \
515 FUNC_INSTR(sym)
516#define SECTION_SUBSEC_FUNC(sect, subsec, sym) \
517 .section .sect.subsec, "ax"; PERFOPT_ALIGN; sym :
518
519#endif /* CONFIG_ARC */
520
521#endif /* _ASMLANGUAGE */
522
523#if defined(_ASMLANGUAGE)
524#if defined(CONFIG_ARM)
525#if defined(CONFIG_ASSEMBLER_ISA_THUMB2)
526/* '.syntax unified' is a gcc-ism used in thumb-2 asm files */
527#define _ASM_FILE_PROLOGUE .text; .syntax unified; .thumb
528#else
529#define _ASM_FILE_PROLOGUE .text; .code 32
530#endif /* CONFIG_ASSEMBLER_ISA_THUMB2 */
531#elif defined(CONFIG_ARM64)
532#define _ASM_FILE_PROLOGUE .text
533#endif /* CONFIG_ARM64 || CONFIG_ARM */
534#endif /* _ASMLANGUAGE */
535
536/*
537 * These macros generate absolute symbols for GCC
538 */
539
540/* create an extern reference to the absolute symbol */
541
542#define GEN_OFFSET_EXTERN(name) extern const char name[]
543
544#define GEN_ABS_SYM_BEGIN(name) \
545 EXTERN_C void name(void); \
546 void name(void) \
547 {
548
549#define GEN_ABS_SYM_END }
550
551/*
552 * Note that GEN_ABSOLUTE_SYM(), depending on the architecture
553 * and toolchain, may restrict the range of values permitted
554 * for assignment to the named symbol.
555 *
556 * For example, on x86, "value" is interpreted as signed
557 * 32-bit integer. Passing in an unsigned 32-bit integer
558 * with MSB set would result in a negative integer.
559 * Moreover, GCC would error out if an integer larger
560 * than 2^32-1 is passed as "value".
561 */
562
563/*
564 * GEN_ABSOLUTE_SYM_KCONFIG() is outputted by the build system
565 * to generate named symbol/value pairs for kconfigs.
566 */
567
568#if defined(CONFIG_ARM) || (defined(CONFIG_ARCH_POSIX) && defined(__arm__))
569
570/*
571 * GNU/ARM backend does not have a proper operand modifier which does not
572 * produces prefix # followed by value, such as %0 for PowerPC, Intel, and
573 * MIPS. The workaround performed here is using %B0 which converts
574 * the value to ~(value). Thus "n"(~(value)) is set in operand constraint
575 * to output (value) in the ARM specific GEN_OFFSET macro.
576 */
577
578#define GEN_ABSOLUTE_SYM(name, value) \
579 __asm__ __volatile__(".globl\t" #name "\n\t.equ\t" #name \
580 ",%B0" \
581 "\n\t.type\t" #name ",%%object" : : "n"(~(value)))
582
583#define GEN_ABSOLUTE_SYM_KCONFIG(name, value) \
584 __asm__ __volatile__(".globl\t" #name \
585 "\n\t.equ\t" #name "," #value \
586 "\n\t.type\t" #name ",%object")
587
588#elif defined(CONFIG_ARC) || defined(CONFIG_ARM64) \
589 || defined(CONFIG_ARCH_POSIX) /*&& (__x86_64 or __i*86 or __aarch64__)*/ \
590 || defined(CONFIG_X86)
591
592#define GEN_ABSOLUTE_SYM(name, value) \
593 __asm__ __volatile__(".globl\t" #name "\n\t.equ\t" #name \
594 ",%c0" \
595 "\n\t.type\t" #name ",@object" : : "n"(value))
596
597#define GEN_ABSOLUTE_SYM_KCONFIG(name, value) \
598 __asm__ __volatile__(".globl\t" #name \
599 "\n\t.equ\t" #name "," #value \
600 "\n\t.type\t" #name ",@object")
601
602#elif defined(CONFIG_RISCV) || defined(CONFIG_XTENSA) || \
603 defined(CONFIG_MIPS) || defined(CONFIG_OPENRISC)
604
605/* No special prefixes necessary for constants in this arch AFAICT */
606#define GEN_ABSOLUTE_SYM(name, value) \
607 __asm__ __volatile__(".globl\t" #name "\n\t.equ\t" #name \
608 ",%0" \
609 "\n\t.type\t" #name ",%%object" : : "n"(value))
610
611#define GEN_ABSOLUTE_SYM_KCONFIG(name, value) \
612 __asm__ __volatile__(".globl\t" #name \
613 "\n\t.equ\t" #name "," #value \
614 "\n\t.type\t" #name ",%object")
615
616#elif defined(CONFIG_SPARC)
617#define GEN_ABSOLUTE_SYM(name, value) \
618 __asm__ __volatile__(".global\t" #name "\n\t.equ\t" #name \
619 ",%0" \
620 "\n\t.type\t" #name ",#object" : : "n"(value))
621
622#define GEN_ABSOLUTE_SYM_KCONFIG(name, value) \
623 __asm__ __volatile__(".globl\t" #name \
624 "\n\t.equ\t" #name "," #value \
625 "\n\t.type\t" #name ",#object")
626
627#elif defined(CONFIG_RX)
628#define GEN_ABSOLUTE_SYM(name, value) \
629 __asm__ __volatile__(".global\t" #name "\n\t.equ\t" #name \
630 ",%c0" \
631 "\n\t.type\t" #name ",%%object" : : "n"(value))
632
633#define GEN_ABSOLUTE_SYM_KCONFIG(name, value) \
634 __asm__ __volatile__(".global\t" #name \
635 "\n\t.equ\t" #name "," #value \
636 "\n\t.type\t" #name ",#object")
637
638#elif defined(CONFIG_HEXAGON)
639/* Hexagon (Qualcomm DSP) - use standard assembly approach */
640#define GEN_ABSOLUTE_SYM(name, value) \
641 __asm__(".globl\t" #name "\n\t.equ\t" #name ",%c0" \
642 "\n\t.type\t" #name ",@object" \
643 : \
644 : "n"(value))
645
646#define GEN_ABSOLUTE_SYM_KCONFIG(name, value) __asm__(".globl " #name "\n.equ " #name ", " #value)
647
648#elif defined(CONFIG_TRICORE)
649#define GEN_ABSOLUTE_SYM(name, value) \
650 __asm__(".global\t" #name "\n\t.equ\t" #name \
651 ",%0" \
652 "\n\t.type\t" #name ",@object" : : "n"(value))
653
654#define GEN_ABSOLUTE_SYM_KCONFIG(name, value) \
655 __asm__(".globl\t" #name \
656 "\n\t.equ\t" #name "," #value \
657 "\n\t.type\t" #name ",@object")
658#else
659#error processor architecture not supported
660#endif
661
662#define compiler_barrier() do { \
663 __asm__ __volatile__ ("" ::: "memory"); \
664} while (false)
665
672#define Z_POW2_CEIL(x) \
673 ((x) <= 2UL ? (x) : (1UL << (8 * sizeof(long) - __builtin_clzl((x) - 1))))
674
681#define Z_IS_POW2(x) (((x) != 0) && (((x) & ((x)-1)) == 0))
682
683#if defined(CONFIG_ASAN) && defined(__clang__)
684#define __noasan __attribute__((no_sanitize("address")))
685#else
686#define __noasan /**/
687#endif
688
689#if defined(CONFIG_UBSAN)
690#define __noubsan __attribute__((no_sanitize("undefined")))
691#else
692#define __noubsan
693#endif
694
700#if (TOOLCHAIN_GCC_VERSION >= 110000) || \
701 (defined(TOOLCHAIN_CLANG_VERSION) && (TOOLCHAIN_CLANG_VERSION >= 70000))
702#define FUNC_NO_STACK_PROTECTOR __attribute__((no_stack_protector))
703#else
704#define FUNC_NO_STACK_PROTECTOR
705#endif
706
707#if defined(CONFIG_INSTRUMENTATION)
708#define __no_instrumentation__ __attribute__((__no_instrument_function__))
709#else
710#define __no_instrumentation__ /**/
711#endif
712
713#endif /* !_LINKER */
714
715#define TOOLCHAIN_WARNING_ADDRESS_OF_PACKED_MEMBER "-Waddress-of-packed-member"
716#define TOOLCHAIN_WARNING_ARRAY_BOUNDS "-Warray-bounds"
717#define TOOLCHAIN_WARNING_ATTRIBUTES "-Wattributes"
718#define TOOLCHAIN_WARNING_DELETE_NON_VIRTUAL_DTOR "-Wdelete-non-virtual-dtor"
719#define TOOLCHAIN_WARNING_DEPRECATED_DECLARATIONS "-Wdeprecated-declarations"
720#define TOOLCHAIN_WARNING_EXTRA "-Wextra"
721#define TOOLCHAIN_WARNING_NONNULL "-Wnonnull"
722#define TOOLCHAIN_WARNING_SHADOW "-Wshadow"
723#define TOOLCHAIN_WARNING_UNUSED_LABEL "-Wunused-label"
724#define TOOLCHAIN_WARNING_UNUSED_VARIABLE "-Wunused-variable"
725#define TOOLCHAIN_WARNING_CAST_QUAL "-Wcast-qual"
726
727/* GCC-specific warnings that aren't in clang. */
728#if defined(__GNUC__) && !defined(__clang__)
729#define TOOLCHAIN_WARNING_POINTER_ARITH "-Wpointer-arith"
730#define TOOLCHAIN_WARNING_STRINGOP_OVERREAD "-Wstringop-overread"
731#endif
732
733#define _TOOLCHAIN_DISABLE_WARNING(compiler, warning) \
734 TOOLCHAIN_PRAGMA(compiler diagnostic push) \
735 TOOLCHAIN_PRAGMA(compiler diagnostic ignored warning)
736
737#define _TOOLCHAIN_ENABLE_WARNING(compiler, warning) TOOLCHAIN_PRAGMA(compiler diagnostic pop)
738
739#define TOOLCHAIN_DISABLE_WARNING(warning) _TOOLCHAIN_DISABLE_WARNING(GCC, warning)
740#define TOOLCHAIN_ENABLE_WARNING(warning) _TOOLCHAIN_ENABLE_WARNING(GCC, warning)
741
742#if defined(__GNUC__) && !defined(__clang__)
743#define TOOLCHAIN_DISABLE_GCC_WARNING(warning) _TOOLCHAIN_DISABLE_WARNING(GCC, warning)
744#define TOOLCHAIN_ENABLE_GCC_WARNING(warning) _TOOLCHAIN_ENABLE_WARNING(GCC, warning)
745#endif
746
747#endif /* ZEPHYR_INCLUDE_TOOLCHAIN_GCC_H_ */
Common toolchain abstraction.