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