zephyr: native_posix build fails with X86_64 on macOS

I’m trying to make native posix build on macOS. It seems 32-bit support has been discontinued from the macOS toolchain, and indeed the build fails almost immediately with that. I get much further when enabling CONFIG_X86_64=y for samples/hello_world, but that fails eventually as well, due to what looks like some sort of dependency issue (possibly circular) with various headers:

[8/84] Building C object zephyr/CMakeFiles/offsets.dir/arch/posix/core/offsets/offsets.c.obj
FAILED: zephyr/CMakeFiles/offsets.dir/arch/posix/core/offsets/offsets.c.obj 
ccache /usr/bin/gcc -DBUILD_VERSION=zephyr-v1.14.0-1601-gfaa398f078c4 -DKERNEL -D_FORTIFY_SOURCE=2 -D_POSIX_C_SOURCE=200809 -D_XOPEN_SOURCE=600 -D_XOPEN_SOURCE_EXTENDED -D__ZEPHYR__=1 -I../kernel/include -I../arch/posix/include -I../include -I../include/drivers -Izephyr/include/generated -I../soc/posix/inf_clock -I../boards/posix/native_posix -I../lib/libc/minimal/include -isystem /Library/Developer/CommandLineTools/usr/lib/clang/11.0.0/include -Os -nostdinc -imacros /Users/jhedberg/src/zephyr/zephyr/build/zephyr/include/generated/autoconf.h -ffreestanding -fno-common -g -Wall -Wformat -Wformat-security -Wno-format-zero-length -Wno-main -Wno-address-of-packed-member -Wno-pointer-sign -Wpointer-arith -Werror=implicit-int -fno-asynchronous-unwind-tables -fno-pie -fno-pic -fno-strict-overflow -ffunction-sections -fdata-sections -m32 -MMD -MP -include /Users/jhedberg/src/zephyr/zephyr/arch/posix/include/posix_cheats.h -std=c11 -MD -MT zephyr/CMakeFiles/offsets.dir/arch/posix/core/offsets/offsets.c.obj -MF zephyr/CMakeFiles/offsets.dir/arch/posix/core/offsets/offsets.c.obj.d -o zephyr/CMakeFiles/offsets.dir/arch/posix/core/offsets/offsets.c.obj   -c /Users/jhedberg/src/zephyr/zephyr/arch/posix/core/offsets/offsets.c
In file included from /Users/jhedberg/src/zephyr/zephyr/arch/posix/core/offsets/offsets.c:30:
In file included from ../kernel/include/kernel_structs.h:10:
In file included from ../include/kernel.h:17:
In file included from ../include/kernel_includes.h:34:
In file included from ../include/arch/cpu.h:15:
In file included from ../include/arch/x86_64/arch.h:9:
In file included from ../arch/posix/include/kernel_arch_func.h:15:
../arch/posix/include/posix_core.h:17:2: error: unknown type name 'k_thread_entry_t'
        k_thread_entry_t entry_point;
        ^
In file included from /Users/jhedberg/src/zephyr/zephyr/arch/posix/core/offsets/offsets.c:30:
In file included from ../kernel/include/kernel_structs.h:10:
In file included from ../include/kernel.h:17:
In file included from ../include/kernel_includes.h:34:
In file included from ../include/arch/cpu.h:15:
In file included from ../include/arch/x86_64/arch.h:9:
../arch/posix/include/kernel_arch_func.h:49:8: error: incomplete definition of type 'struct k_thread'
        thread->callee_saved.retval = value;
        ~~~~~~^
../include/sched_priq.h:32:8: note: forward declaration of 'struct k_thread'
struct k_thread;
       ^
In file included from /Users/jhedberg/src/zephyr/zephyr/arch/posix/core/offsets/offsets.c:30:
In file included from ../kernel/include/kernel_structs.h:10:
In file included from ../include/kernel.h:17:
In file included from ../include/kernel_includes.h:37:
../include/spinlock.h:75:10: warning: implicit declaration of function 'z_arch_irq_lock' is invalid in C99 [-Wimplicit-function-declaration]
        k.key = z_arch_irq_lock();
                ^
../include/spinlock.h:110:2: warning: implicit declaration of function 'z_arch_irq_unlock' is invalid in C99 [-Wimplicit-function-declaration]
        z_arch_irq_unlock(key.key);
        ^
2 warnings and 2 errors generated.
ninja: build stopped: subcommand failed.
ERROR: command exited with status 1: /usr/local/bin/cmake --build /Users/jhedberg/src/zephyr/zephyr/build

I.e. the problem seems to be that include/kernel.h very early includes a chain of headers which ends up requiring symbols that are only defined later inside kernel.h.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 17 (14 by maintainers)

Most upvoted comments

That -m32 is to explicitly tell the compiler to build for x86, otherwise it targets the host platform.

Sorry for being pedantic but as usual in this area there’s a high potential for confusion, so better safe than sorry: even with -m32 the compiler still targets “the host platform”. Both native_posix (-m32) and native_posix_64 run on the host. The exact same host does both 32 and 64 bits simultaneously.

BTW https://www.phoronix.com/scan.php?page=news_item&px=Ubuntu-Partial-32-Bit-19.10

(Disclaimer: You may face other issues when trying to compile it or run it in macOS)

You bet.