Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clang/llvm/arm-clang build is broken: Error: initializer element is not a compile-time constant #54826

Closed
adrianlshaw opened this issue Feb 14, 2023 · 10 comments
Assignees
Labels
area: GPIO area: Toolchains Toolchains bug The issue is a bug, or the PR is fixing a bug platform: NXP NXP priority: medium Medium impact/importance bug

Comments

@adrianlshaw
Copy link

Trying to build Zephyr v3.3.0-rc3 with LLVM toolchain on Linux. Target is an LPCxpresso55S69 board. I'm unsure how to work around or fix it. It says error: initializer element is not a compile-time constant for one of the macro elements.

To Reproduce
Steps to reproduce the behavior:

  1. export ZEPHYR_TOOLCHAIN_VARIANT=llvm
  2. west build -p always -b lpcxpresso55s69_ns samples/basic/blinky

Expected behavior
Expect Zephyr to fully build

Impact
I'd like to know what's wrong, and ideally have a patch or workaround that I can carry until this is eventually fixed.

Logs and console output

/opt/zephyr/drivers/gpio/gpio_mcux_lpc.c:450:29: error: initializer element is not a compile-time constant
DT_INST_FOREACH_STATUS_OKAY(GPIO_MCUX_LPC)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
/opt/zephyr/include/zephyr/devicetree.h:3713:25: note: expanded from macro 'DT_INST_FOREACH_STATUS_OKAY'
                              DT_DRV_COMPAT)(fn)),              \
                              ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
/opt/zephyr/build/zephyr/include/generated/devicetree_generated.h:11256:47: note: expanded from macro 'DT_FOREACH_OKAY_INST_nxp_lpc_gpio'
#define DT_FOREACH_OKAY_INST_nxp_lpc_gpio(fn) fn(0) fn(1)
                                              ^
/opt/zephyr/drivers/gpio/gpio_mcux_lpc.c:430:20: note: expanded from macro 'GPIO_MCUX_LPC'
                .clock_ip_name = gpio_clock_names[DT_INST_PROP(n, port)],               \
                                 ^
note: (skipping 2 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
/opt/zephyr/include/zephyr/sys/util_internal.h:64:39: note: expanded from macro '__COND_CODE'
        __GET_ARG2_DEBRACKET(one_or_two_args _if_code, _else_code)
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
/opt/zephyr/include/zephyr/sys/util_internal.h:69:65: note: expanded from macro '__GET_ARG2_DEBRACKET'
#define __GET_ARG2_DEBRACKET(ignore_this, val, ...) __DEBRACKET val
                                                    ~~~~~~~~~~~~^~~
/opt/zephyr/include/zephyr/sys/util_internal.h:72:26: note: expanded from macro '__DEBRACKET'
#define __DEBRACKET(...) __VA_ARGS__
                         ^~~~~~~~~~~
/opt/zephyr/drivers/gpio/gpio_mcux_lpc.c:450:29: error: initializer element is not a compile-time constant
DT_INST_FOREACH_STATUS_OKAY(GPIO_MCUX_LPC)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
/opt/zephyr/include/zephyr/devicetree.h:3713:25: note: expanded from macro 'DT_INST_FOREACH_STATUS_OKAY'
                              DT_DRV_COMPAT)(fn)),              \
                              ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
/opt/zephyr/build/zephyr/include/generated/devicetree_generated.h:11256:53: note: expanded from macro 'DT_FOREACH_OKAY_INST_nxp_lpc_gpio'
#define DT_FOREACH_OKAY_INST_nxp_lpc_gpio(fn) fn(0) fn(1)
                                                    ^
/opt/zephyr/drivers/gpio/gpio_mcux_lpc.c:430:20: note: expanded from macro 'GPIO_MCUX_LPC'
                .clock_ip_name = gpio_clock_names[DT_INST_PROP(n, port)],               \
                                 ^
note: (skipping 2 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
/opt/zephyr/include/zephyr/sys/util_internal.h:64:39: note: expanded from macro '__COND_CODE'
        __GET_ARG2_DEBRACKET(one_or_two_args _if_code, _else_code)
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
/opt/zephyr/include/zephyr/sys/util_internal.h:69:65: note: expanded from macro '__GET_ARG2_DEBRACKET'
#define __GET_ARG2_DEBRACKET(ignore_this, val, ...) __DEBRACKET val
                                                    ~~~~~~~~~~~~^~~
/opt/zephyr/include/zephyr/sys/util_internal.h:72:26: note: expanded from macro '__DEBRACKET'
#define __DEBRACKET(...) __VA_ARGS__
                         ^~~~~~~~~~~
2 errors generated.
[117/173] Building C object modules/hal_nxp/hal_nxp/CMakeFiles/..__modules__hal__nxp.dir/mcux/mcux-sdk/devices/LPC55S69/drivers/fsl_clock.c.obj
ninja: build stopped: subcommand failed.
FATAL ERROR: command exited with status 1: /usr/bin/cmake --build /opt/zephyr/build
make: *** [Makefile:5: all] Error 1

Environment (please complete the following information):

  • OS: Ubuntu 20.04
  • Toolchain Zephyr SDK and Clang-12 aand LLVM-12
  • Commit SHA or Version used: v3.3.0-rc3 tag
@adrianlshaw adrianlshaw added the bug The issue is a bug, or the PR is fixing a bug label Feb 14, 2023
@laurenmurphyx64 laurenmurphyx64 added the priority: low Low impact/importance bug label Feb 14, 2023
@galak galak added the area: Toolchains Toolchains label Feb 14, 2023
@danieldegrasse
Copy link
Collaborator

@stephanosio do we currently support ARM compilation on LLVM? Based on #3689, it appears we do not currently.

@v-barshaw
Copy link

v-barshaw commented Feb 26, 2023

nRF52DK build is also broken in multiple places. The commands

export ZEPHYR_TOOLCHAIN_VARIANT=llvm LLVM_TOOLCHAIN_PATH=/opt/LLVMEmbeddedToolchainForArm-15.0.2
rm -rf build
west build -b nrf52dk_nrf52832 samples/bluetooth/hci_pwr_ctrl

produces the following:

-- Zephyr version: 3.3.99 (/home/vadim/work/RTOS/zephyrproject/zephyr), build: zephyr-v3.3.0-474-geead89e7f22d
[147/245] Building C object zephyr/subsys/bluetooth/contr...keFiles/subsys__bluetooth__controller.dir/ll_sw/ull.c.obj
/home/vadim/work/RTOS/zephyrproject/zephyr/subsys/bluetooth/controller/ll_sw/ull.c:1231:9: warning: use of bitwise '|' with boolean operands [-Wbitwise-instead-of-logical]
                        bm = (IS_ENABLED(CONFIG_BT_OBSERVER) &&
                             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/vadim/work/RTOS/zephyrproject/zephyr/subsys/bluetooth/controller/ll_sw/ull.c:1231:9: note: cast one or both operands to int to silence this warning
1 warning generated.
[151/245] Building C object zephyr/subsys/bluetooth/host/CMakeFiles/subsys__bluetooth__host.dir/gatt.c.obj
/home/vadim/work/RTOS/zephyrproject/zephyr/subsys/bluetooth/host/gatt.c:1881:2: warning: field  within 'struct gatt_chrc' is less aligned than 'union gatt_chrc::(anonymous at /home/vadim/work/RTOS/zephyrproject/zephyr/subsys/bluetooth/host/gatt.c:1881:2)' and is usually due to 'struct gatt_chrc' being packed, which can lead to unaligned accesses [-Wunaligned-access]
        union {
        ^
1 warning generated.
[165/245] Building C object zephyr/subsys/bluetooth/contr...sys__bluetooth__controller.dir/ll_sw/nordic/lll/lll.c.obj
/home/vadim/work/RTOS/zephyrproject/zephyr/subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c:85:1: warning: call to function without interrupt attribute could clobber interruptee's VFP registers [-Wextra]
ISR_DIRECT_DECLARE(radio_nrf5_isr)
^
/home/vadim/work/RTOS/zephyrproject/zephyr/include/zephyr/irq.h:180:34: note: expanded from macro 'ISR_DIRECT_DECLARE'
#define ISR_DIRECT_DECLARE(name) ARCH_ISR_DIRECT_DECLARE(name)
                                 ^
/home/vadim/work/RTOS/zephyrproject/zephyr/include/zephyr/arch/arm/aarch32/irq.h:184:3: note: expanded from macro 'ARCH_ISR_DIRECT_DECLARE'
                ISR_DIRECT_HEADER(); \
                ^
/home/vadim/work/RTOS/zephyrproject/zephyr/include/zephyr/irq.h:121:29: note: expanded from macro 'ISR_DIRECT_HEADER'
#define ISR_DIRECT_HEADER() ARCH_ISR_DIRECT_HEADER()
                            ^
/home/vadim/work/RTOS/zephyrproject/zephyr/include/zephyr/arch/arm/aarch32/irq.h:149:34: note: expanded from macro 'ARCH_ISR_DIRECT_HEADER'
#define ARCH_ISR_DIRECT_HEADER() arch_isr_direct_header()
                                 ^
/home/vadim/work/RTOS/zephyrproject/zephyr/include/zephyr/arch/arm/aarch32/irq.h:160:20: note: 'arch_isr_direct_header' declared here
static inline void arch_isr_direct_header(void)
                   ^
/home/vadim/work/RTOS/zephyrproject/zephyr/subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c:85:1: warning: call to function without interrupt attribute could clobber interruptee's VFP registers [-Wextra]
ISR_DIRECT_DECLARE(radio_nrf5_isr)
^
/home/vadim/work/RTOS/zephyrproject/zephyr/include/zephyr/irq.h:180:34: note: expanded from macro 'ISR_DIRECT_DECLARE'
#define ISR_DIRECT_DECLARE(name) ARCH_ISR_DIRECT_DECLARE(name)
                                 ^
/home/vadim/work/RTOS/zephyrproject/zephyr/include/zephyr/arch/arm/aarch32/irq.h:185:22: note: expanded from macro 'ARCH_ISR_DIRECT_DECLARE'
                check_reschedule = name##_body(); \
                                   ^
<scratch space>:4:1: note: expanded from here
radio_nrf5_isr_body
^
/home/vadim/work/RTOS/zephyrproject/zephyr/subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c:85:1: note: 'radio_nrf5_isr_body' declared here
/home/vadim/work/RTOS/zephyrproject/zephyr/include/zephyr/irq.h:180:34: note: expanded from macro 'ISR_DIRECT_DECLARE'
#define ISR_DIRECT_DECLARE(name) ARCH_ISR_DIRECT_DECLARE(name)
                                 ^
/home/vadim/work/RTOS/zephyrproject/zephyr/include/zephyr/arch/arm/aarch32/irq.h:178:20: note: expanded from macro 'ARCH_ISR_DIRECT_DECLARE'
        static inline int name##_body(void); \
                          ^
<scratch space>:152:1: note: expanded from here
radio_nrf5_isr_body
^
/home/vadim/work/RTOS/zephyrproject/zephyr/subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c:85:1: warning: call to function without interrupt attribute could clobber interruptee's VFP registers [-Wextra]
ISR_DIRECT_DECLARE(radio_nrf5_isr)
^
/home/vadim/work/RTOS/zephyrproject/zephyr/include/zephyr/irq.h:180:34: note: expanded from macro 'ISR_DIRECT_DECLARE'
#define ISR_DIRECT_DECLARE(name) ARCH_ISR_DIRECT_DECLARE(name)
                                 ^
/home/vadim/work/RTOS/zephyrproject/zephyr/include/zephyr/arch/arm/aarch32/irq.h:186:3: note: expanded from macro 'ARCH_ISR_DIRECT_DECLARE'
                ISR_DIRECT_FOOTER(check_reschedule); \
                ^
/home/vadim/work/RTOS/zephyrproject/zephyr/include/zephyr/irq.h:139:2: note: expanded from macro 'ISR_DIRECT_FOOTER'
        ARCH_ISR_DIRECT_FOOTER(check_reschedule)
        ^
/home/vadim/work/RTOS/zephyrproject/zephyr/include/zephyr/arch/arm/aarch32/irq.h:150:38: note: expanded from macro 'ARCH_ISR_DIRECT_FOOTER'
#define ARCH_ISR_DIRECT_FOOTER(swap) arch_isr_direct_footer(swap)
                                     ^
/home/vadim/work/RTOS/zephyrproject/zephyr/include/zephyr/arch/arm/aarch32/irq.h:167:20: note: 'arch_isr_direct_footer' declared here
static inline void arch_isr_direct_footer(int maybe_swap)
                   ^
3 warnings generated.
[178/245] Building C object zephyr/drivers/entropy/CMakeFiles/drivers__entropy.dir/entropy_nrf5.c.obj
/home/vadim/work/RTOS/zephyrproject/zephyr/drivers/entropy/entropy_nrf5.c:119:13: warning: unknown pragma ignored [-Wunknown-pragmas]
#pragma GCC push_options
            ^
/home/vadim/work/RTOS/zephyrproject/zephyr/drivers/entropy/entropy_nrf5.c:178:13: warning: unknown pragma ignored [-Wunknown-pragmas]
#pragma GCC pop_options
            ^
2 warnings generated.
[182/245] Building C object zephyr/drivers/clock_control/CMakeFiles/drivers__clock_control.dir/clock_control_nrf.c.obj
/home/vadim/work/RTOS/zephyrproject/zephyr/drivers/clock_control/clock_control_nrf.c:114:5: warning: cast to smaller integer type 'enum clock_control_nrf_type' from 'clock_control_subsys_t' (aka 'void *') [-Wvoid-pointer-to-enum-cast]
                                (enum clock_control_nrf_type)sys);
                                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/vadim/work/RTOS/zephyrproject/zephyr/drivers/clock_control/clock_control_nrf.c:120:37: warning: cast to smaller integer type 'enum clock_control_nrf_type' from 'clock_control_subsys_t' (aka 'void *') [-Wvoid-pointer-to-enum-cast]
        enum clock_control_nrf_type type = (enum clock_control_nrf_type)subsys;
                                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/vadim/work/RTOS/zephyrproject/zephyr/drivers/clock_control/clock_control_nrf.c:345:37: warning: cast to smaller integer type 'enum clock_control_nrf_type' from 'clock_control_subsys_t' (aka 'void *') [-Wvoid-pointer-to-enum-cast]
        enum clock_control_nrf_type type = (enum clock_control_nrf_type)subsys;
                                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/vadim/work/RTOS/zephyrproject/zephyr/drivers/clock_control/clock_control_nrf.c:369:37: warning: cast to smaller integer type 'enum clock_control_nrf_type' from 'clock_control_subsys_t' (aka 'void *') [-Wvoid-pointer-to-enum-cast]
        enum clock_control_nrf_type type = (enum clock_control_nrf_type)subsys;
                                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/vadim/work/RTOS/zephyrproject/zephyr/drivers/clock_control/clock_control_nrf.c:440:37: warning: cast to smaller integer type 'enum clock_control_nrf_type' from 'clock_control_subsys_t' (aka 'void *') [-Wvoid-pointer-to-enum-cast]
        enum clock_control_nrf_type type = (enum clock_control_nrf_type)sys;
                                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5 warnings generated.
[235/245] Linking C executable zephyr/zephyr_pre0.elf
FAILED: zephyr/zephyr_pre0.elf zephyr/zephyr_pre0.map /home/vadim/work/RTOS/zephyrproject/zephyr/build/zephyr/zephyr_pre0.map 
: && /opt/LLVMEmbeddedToolchainForArm-15.0.2/bin/clang --target=arm-none-eabi  --specs=nosys.specs zephyr/CMakeFiles/zephyr_pre0.dir/misc/empty_file.c.obj -o zephyr/zephyr_pre0.elf  zephyr/CMakeFiles/offsets.dir/./arch/arm/core/offsets/offsets.c.obj  -Wl,-T  zephyr/linker_zephyr_pre0.cmd  -Wl,-Map=/home/vadim/work/RTOS/zephyrproject/zephyr/build/zephyr/zephyr_pre0.map  -Wl,--whole-archive  app/libapp.a  zephyr/libzephyr.a  zephyr/arch/common/libarch__common.a  zephyr/arch/arch/arm/core/aarch32/libarch__arm__core__aarch32.a  zephyr/arch/arch/arm/core/aarch32/cortex_m/libarch__arm__core__aarch32__cortex_m.a  zephyr/arch/arch/arm/core/aarch32/mpu/libarch__arm__core__aarch32__mpu.a  zephyr/lib/libc/minimal/liblib__libc__minimal.a  zephyr/soc/arm/common/cortex_m/libsoc__arm__common__cortex_m.a  zephyr/soc/arm/nordic_nrf/nrf52/libsoc__arm__nordic_nrf__nrf52.a  zephyr/subsys/random/libsubsys__random.a  zephyr/subsys/bluetooth/common/libsubsys__bluetooth__common.a  zephyr/subsys/bluetooth/host/libsubsys__bluetooth__host.a  zephyr/subsys/bluetooth/controller/libsubsys__bluetooth__controller.a  zephyr/subsys/net/libsubsys__net.a  zephyr/drivers/clock_control/libdrivers__clock_control.a  zephyr/drivers/console/libdrivers__console.a  zephyr/drivers/entropy/libdrivers__entropy.a  zephyr/drivers/gpio/libdrivers__gpio.a  zephyr/drivers/pinctrl/libdrivers__pinctrl.a  zephyr/drivers/serial/libdrivers__serial.a  zephyr/drivers/timer/libdrivers__timer.a  modules/hal_nordic/nrfx/libmodules__hal_nordic__nrfx.a  modules/segger/libmodules__segger.a  -Wl,--no-whole-archive  zephyr/kernel/libkernel.a  -L"/opt/LLVMEmbeddedToolchainForArm-15.0.2/lib/clang/15.0.2/lib/baremetal"  -L/home/vadim/work/RTOS/zephyrproject/zephyr/build/zephyr  -lgcc  zephyr/arch/common/libisr_tables.a  -no-pie  -fshort-enums  -mcpu=cortex-m4  -mthumb  -mabi=aapcs  -Wl,--gc-sections  -Wl,--build-id=none  -Wl,--sort-section=alignment  -Wl,-u,_OffsetAbsSyms  -Wl,-u,_ConfigAbsSyms  -nostdlib  -static  -Wl,-X  -Wl,-N  -Wl,--orphan-handling=warn && cd /home/vadim/work/RTOS/zephyrproject/zephyr/build/zephyr && /usr/local/bin/cmake -E echo
clang-15: warning: argument unused during compilation: '--specs=nosys.specs' [-Wunused-command-line-argument]
clang-15: warning: argument unused during compilation: '-no-pie' [-Wunused-command-line-argument]
ld.lld: error: zephyr/linker_zephyr_pre0.cmd:112: { expected, but got ALIGN_WITH_INPUT
>>>  app_shmem_regions : ALIGN_WITH_INPUT
>>>                      ^

ld.lld: error: unable to find library -lgcc
clang-15: error: ld.lld command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
FATAL ERROR: command exited with status 1: /usr/local/bin/cmake --build /home/vadim/work/RTOS/zephyrproject/zephyr/build

@github-actions
Copy link

This issue has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this issue will automatically be closed in 14 days. Note, that you can always re-open a closed issue at any time.

@github-actions github-actions bot added the Stale label Apr 28, 2023
@galak
Copy link
Collaborator

galak commented Apr 28, 2023

These issues also existing when building with arm-clang.

@galak galak added priority: medium Medium impact/importance bug and removed priority: low Low impact/importance bug Stale labels Apr 28, 2023
@galak galak changed the title Clang/llvm build is broken: Error: initializer element is not a compile-time constant Clang/llvm/arm-clang build is broken: Error: initializer element is not a compile-time constant Apr 28, 2023
@dleach02
Copy link
Member

Who from the toolchain group can take this issue as it seems to be something happening across different vendors?

@github-actions
Copy link

This issue has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this issue will automatically be closed in 14 days. Note, that you can always re-open a closed issue at any time.

@github-actions
Copy link

This issue has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this issue will automatically be closed in 14 days. Note, that you can always re-open a closed issue at any time.

@github-actions github-actions bot added the Stale label Sep 10, 2023
@tejlmand tejlmand removed the Stale label Sep 11, 2023
@tejlmand
Copy link
Collaborator

Seems to be a clang issue:
llvm/llvm-project#44502

and fixed in clang here, which is part of LLVM-17 and later:
https://reviews.llvm.org/D76096

Please update your LLVM to LLVM 17 or later.

I have tested that this error is present in Zephyr when using clang 16, but is gone when using clang 17.

Other interesting references
llvm/llvm-project#64874

@tejlmand
Copy link
Collaborator

These issues also existing when building with arm-clang.

For armclang we need to wait for arm to update to a later LLVM baseline.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: GPIO area: Toolchains Toolchains bug The issue is a bug, or the PR is fixing a bug platform: NXP NXP priority: medium Medium impact/importance bug
Projects
None yet
Development

No branches or pull requests

8 participants