Commit graph

10 commits

Author SHA1 Message Date
Krzysztof Chruściński 1e7b540aa8 toolchain: Add flag indicating zero length array support
Add flag which indicates if a toolchain supports ZLA (Zero
Length Arrays). It is a GCCC extension inherited by clang as
well.

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
2023-09-12 17:23:31 +01:00
Daniel Leung 8dc9d89d29 toolchain: introduce macros to ignore -Wshadow
This introduces two macros TOOLCHAIN_IGNORE_WSHADOW_BEGIN and
TOOLCHAIN_IGNORE_WSHADOW_END which can be used inside another
macro to ignore -Wshadow for certain block of code. This is
useful for common macros that may nest upon themselves
(for example, logging).

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2023-08-10 08:14:12 +00:00
Patryk Duda fad8ae4052 linker: Introduce linker-tool-lld.h
Until now, linker-tool-gcc.h was used when LLD linker was chosen.
This causes linking issues because for GNU LD we use ALIGN_WITH_INPUT
attribute which is not available in LLVM LLD.

When using GNU LD we have to use ALIGN_WITH_INPUT to make sure that the
difference between VMA and LMA remains the same between output sections
that have different memory regions for VMA and LMA (RAM and FLASH).
With ALIGN_WITH_INPUT it's safe to do the memcpy of sections
that needs to be copied from flash to RAM in one function call:

(from z_data_copy() in kernel/xip.c)
```
z_early_memcpy(&__data_region_start, &__data_region_load_start,
               __data_region_end - __data_region_start);
```

By default, LLVM LLD aligns both VMA and LMA to the same value, but
when --omagic (-N) option is provided then only the first output section
of given region has aligned LMA and the difference between VMA addresses
(0 is this is the first section) is added.

As a result the difference between LMA and VMA is constant for every
section, so this emulates ALIGN_WITH_INPUT option present in GNU LD
(required by XIP systems).

The --omagic flag is defined in cmake/linker/lld/target_baremetal.cmake

Example:
```
MEMORY {
  ROM : ORIGIN = 0x1000, LENGTH = 1K
  RAM : ORIGIN = 0x11000, LENGTH = 1K
}
SECTIONS {
  .text 0x1000 : {
  	*(.text*)
  } >ROM

  .data.rel.ro : {
  	*(.data.rel.ro)
  } >RAM AT>ROM

  .data : {
  	*(.data*)
  } >RAM AT>ROM
}
```

```
echo '.globl _start; _start: nop; .byte 1;'\
     '.data.rel.ro; .balign 16; .byte 0;'\
     '.data; .balign 32; .byte 0;' | \
     llvm-mc -filetype=obj -triple=arm - -o test.o

armv7m-cros-eabi-ld.lld --sort-section=alignment -N -T script.ld \
     test.o -o lld_out
```

```
Idx Name          Size      VMA       LMA       File off  Algn
  0 .text         00000005  00001000  00001000  00000094  2**2
  1 .data.rel.ro  00000001  00011000  00001010  000000a0  2**4
  2 .data         00000001  00011020  00001030  000000c0  2**5
```

In this example the first section has lower alignment than the following
section, but with -N option the difference between VMA and LMA is the
same for .data.rel.ro and .data sections.

For comparison, using BFD linker with --omagic option results in the
following:
```
Idx Name          Size      VMA       LMA       File off  Algn
  0 .text         00000005  00001000  00001000  00000094  2**2
  1 .data.rel.ro  00000001  00011000  00001005  000000a0  2**4
  2 .data         00000001  00011020  00001006  000000c0  2**5

```

with ALIGN_WITH_INPUT added, GNU LD adds the difference between VMA to
LMA, but doesn't align LMA of .data.rel.ro section:
```
Idx Name          Size      VMA       LMA       File off  Algn
  0 .text         00000005  00001000  00001000  00000074  2**2
  1 .data.rel.ro  00000001  00011000  00001005  00000080  2**4
  2 .data         00000001  00011020  00001025  000000a0  2**5
```

Signed-off-by: Patryk Duda <pdk@semihalf.com>
2023-07-05 12:33:42 +00:00
Keith Packard c58c76ef0a toolchain: Replace GCC_VERSION, CLANG_VERSION and BUILD_ASSERT macros
GCC_VERSION is defined in a few modules, and those headers are often
included first, so replace the one used in zephyr with
TOOLCHAIN_GCC_VERSION. Do the same with CLANG_VERSION, replacing it with
TOOLCHAIN_CLANG_VERSION.

BUILD_ASSERT is also defined in include/toolchain/common.h, which might
get included before gcc.h. We want to use the gcc-specific one instead
of the general one.

Signed-off-by: Keith Packard <keithp@keithp.com>
2022-12-05 18:30:54 +01:00
Marc Herbert 44d9f2ce5c toolchain: more detailed #error messages on endianness mismatch
Recent commit ae123c9bd1 ("toolchain: Ensure that Kconfig endianness
matches the compiler's") added an endianness check which immediately
revealed a problem when compiling with -DSPARSE=y

Finding which values were wrong was a typical pre-processor
nightmare. Avoid this nightmare to anyone in a similar situation again
by adding more tests and #error messages.

- Before:
```
west build  -p -b intel_adsp_cavs25 samples/hello_world/ -- -DSPARSE=y

zephyr/toolchain.h: error: "Endiannes mismatch"
```

- Now:
```
zephyr/toolchain.h: error: "Kconfig/toolchain endianness mismatch:"
zephyr/toolchain.h: error: "CONFIG_LITTLE_ENDIAN but __ORDER_BIG_ENDIAN__"
```

Signed-off-by: Marc Herbert <marc.herbert@intel.com>
2022-11-07 09:49:11 +01:00
Carles Cufi ae123c9bd1 toolchain: Ensure that Kconfig endianness matches the compiler's
In preparation for using CONFIG_(BIG|LITTLE)_ENDIAN exclusively for
endianness-based conditional compilation in the tree, ensure that the
Kconfig CONFIG_(BIG|LITTLE)_ENDIAN options match the compiler's
__BYTE_ORDER__ macro.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2022-10-28 19:23:46 +09:00
Rob Barnes 0b2b221b36 toolchain: Check if __STDC_VERSION__ is defined
Check if __STDC_VERSION__ is defined before referencing it. This will
prevent a compilation failure when __STDC_VERSION__ is not defined for
any reason.

Signed-off-by: Rob Barnes <robbarnes@google.com>
2022-10-27 11:03:49 +02:00
Andy Ross 74cc534758 cmake: Update CONFIG_ASAN support
This had bitrotten a bit, and didn't build as shipped.  Current
libasan implementations want -fsanitize=address passed as a linker
argument too.  We have grown a "lld" linker variant that needs the
same cmake treatment as the "ld" binutils one, but never got it.  But
the various flags had been cut/pasted around to different places, with
slightly different forms.  That's really sort of a mess, as sanitizer
support was only ever support with host toolchains for native_posix
(and AFAICT no one anywhere has made this work on cross compilers in
an embedded environment).  And the separate "gcc" vs. "llvm" layers
were silly, as there has only ever been one API for this feature (from
LLVM, then picked up compatibly by gcc).

Pull this stuff out and just do it in one place in the posix arch for
simplicity.

Also recent sanitizers are trying to add instrumentation padding
around data that we use linker trickery to pack tightly
(c.f. SYS_INIT, STRUCT_SECTION_ITERABLE) and we need a way
("__noasan") to turn that off.  Actually for gcc, it was enough to
just make the records const (already true for most of them, except a
native_posix init struct), but clang apparently isn't smart enough.

Finally, add an ASAN_RECOVER kconfig that enables the use of
"halt_on_error=0" in $ASAN_OPTIONS, which continues execution past the
first error.

Signed-off-by: Andy Ross <andyross@google.com>
2022-08-19 08:30:01 +02:00
Gerard Marull-Paretas fb9b3bcd93 include: migrate includes to <zephyr/...>
In order to bring consistency in-tree, migrate all includes within
include directory to the new prefix <zephyr/...>. Note that the
conversion has been scripted, refer to zephyrproject-rtos#45388 for more
details.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-05-06 20:03:00 +02:00
Yuval Peress 53ef68d459 include: Prefix includes to use a scope
Move include paths and add new target_include_directories to support
backwards compatibility:
* /include -> /include/zephyr
  example: <irq.h> -> <zephyr/irq.h>

Issue #41543

Signed-off-by: Yuval Peress <peress@google.com>
2022-04-08 19:03:32 +02:00
Renamed from include/toolchain.h (Browse further)