Re: Compiler and linker warnings with GCC 11

Kumar Gala

Some of these issues might be resolved by:

- k

On Jul 21, 2021, at 4:06 AM, Sven Vaink├╝la <svenvainkyla@...> wrote:


After updating my GCC to version 11.1.0 I started getting a bunch of linker
errors when compiling projects. Previously I was using GCC 10.2.0.

For example, when building the sample hello_world project using:
west build -b stm32f4_disco
Many warnings are emitted that are related to
Z_KERNEL_STACK_ARRAY_x macros, for example:
[56/139] Building C object zephyr/arch/arch/arm/core/aarch32/CMakeFiles/arch__arm__core__aarch32.dir/thread.c.obj
In file included from ../../../include/kernel_includes.h:39,
from ../../../include/kernel.h:17,
from /home/sv/extern-projects/zephyr/zephyr/arch/arm/core/aarch32/thread.c:15:
../../../include/kernel/thread_stack.h:157:16: warning: ignoring attribute 'section (".noinit.\"../../../kernel/include/kernel_internal.h\".1")' because it conflicts with previous 'section (".noinit.\"../../../arch/arm/include/aarch32/cortex_m/stack.h\".0")' [-Wattributes]
157 | struct z_thread_stack_element lsect \
| ^~~~~~~~~~~~~~~~~~~~~~
../../../include/kernel/thread_stack.h:221:9: note: in expansion of macro 'Z_KERNEL_STACK_ARRAY_DEFINE_IN'
221 | Z_KERNEL_STACK_ARRAY_DEFINE_IN(sym, nmemb, size, __kstackmem)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../../kernel/include/kernel_internal.h:155:8: note: in expansion of macro 'K_KERNEL_STACK_ARRAY_DEFINE'
155 | extern K_KERNEL_STACK_ARRAY_DEFINE(z_interrupt_stacks, CONFIG_MP_NUM_CPUS,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
../../../arch/arm/include/aarch32/cortex_m/stack.h:29:36: note: previous declaration here
29 | extern K_KERNEL_STACK_ARRAY_DEFINE(z_interrupt_stacks, CONFIG_MP_NUM_CPUS,
| ^~~~~~~~~~~~~~~~~~
../../../include/kernel/thread_stack.h:159:17: note: in definition of macro 'Z_KERNEL_STACK_ARRAY_DEFINE_IN'
159 | sym[nmemb][Z_KERNEL_STACK_LEN(size)]
| ^~~
../../../arch/arm/include/aarch32/cortex_m/stack.h:29:8: note: in expansion of macro 'K_KERNEL_STACK_ARRAY_DEFINE'
29 | extern K_KERNEL_STACK_ARRAY_DEFINE(z_interrupt_stacks, CONFIG_MP_NUM_CPUS,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
A couple of linker warnings are also emitted during linking:
[132/139] Linking C executable zephyr/zephyr_prebuilt.elf
/usr/lib/gcc/arm-none-eabi/11.1.0/../../../../arm-none-eabi/bin/ld.bfd: warning: orphan section `.debug_line_str' from `/usr/lib/gcc/arm-none-eabi/11.1.0/thumb/v7e-m/nofp/libgcc.a(_aeabi_uldivmod.o)' being placed in section `.debug_line_str'
/usr/lib/gcc/arm-none-eabi/11.1.0/../../../../arm-none-eabi/bin/ld.bfd: warning: orphan section `.debug_loclists' from `/usr/lib/gcc/arm-none-eabi/11.1.0/thumb/v7e-m/nofp/libgcc.a(_udivmoddi4.o)' being placed in section `.debug_loclists'
/usr/lib/gcc/arm-none-eabi/11.1.0/../../../../arm-none-eabi/bin/ld.bfd: warning: orphan section `.debug_rnglists' from `/usr/lib/gcc/arm-none-eabi/11.1.0/thumb/v7e-m/nofp/libgcc.a(_udivmoddi4.o)' being placed in section `.debug_rnglists'
/usr/lib/gcc/arm-none-eabi/11.1.0/../../../../arm-none-eabi/bin/ld.bfd: warning: orphan section `.debug_line_str' from `/usr/lib/gcc/arm-none-eabi/11.1.0/thumb/v7e-m/nofp/libgcc.a(_dvmd_tls.o)' being placed in section `.debug_line_str'
The same warnings occur when building for the nRF development kit.

Noticed the issue first while using the Nordic nRF SDK, but it also happens
with non-nRF Zephyr. Tested with latest Zephyr at the time of this e-mail
(HEAD at 0ef77d4ea41fb765061c64896b3fbd0b2e4bc276).

The configuration flag CONFIG_LINKER_ORPHAN_SECTION_PLACE does get rid of
the linker warnings, but the compiler warnings related to

I don't think that this is related to an invalid configuration of the build
environment, as compilation used to complete without these linker warnings.
This causes a lot of noise in the build logs that can mask other warnings.

Does anyone have any ideas on how to fix these build errors?
Is this a known bug or have I misconfigured something that just didn't
manifest with an older GCC?

Best regards
Sven Vaink├╝la

Join to automatically receive all group messages.