zephyr: Generated linker scripts break when ZEPHYR_BASE and ZEPHYR_MODULES share structure that contains symlinks

Describe the bug My zephyr workspace consists of symlinks to read-only copies of modules which exist in a programmatically managed filesystem. The filesystem looks something like this.

-/store
\-- zephyr-base
\-- hal-nxp
\-- cmsis
\-- zcbor
- /workspace
-- zephyr -> /store/zephyr-base
-- modules/hal/nxp -> /store/hal-nxp
-- modules/hal/cmsis -> /store/cmsis

This command builds successfully:

source /store/zephyr/zephyr-env.sh

cmake $ZEPHYR_BASE/samples/hello_world \
-Bbuild -DBOARD=frdm_k64f \
-DZEPHYR_MODULES=/store/hal-nxp;/store/cmsis
 
make -Cbuild

This command fails to build:

source /workspace/zephyr/zephyr-env.sh

cmake $ZEPHYR_BASE/samples/hello_world \
-Bbuild -DBOARD=frdm_k64f \
-DZEPHYR_MODULES=/workspace/modules/hal/nxp;/workspace/modules/hal/cmsis 

make -Cbuild

The reason is because the generated linker scripts in build/zephyr/include/generated/ use relative paths to $ZEPHYR_BASE. When the build is running it thinks its running from wherever it really is in the filesystem, i.e. /store/zephyr instead of ./workspace/zephyr. The linker generates an include that looks like

/* Sort key: "default" */#include "../../../modules/hal/nxp/mcux/quick_access_code.ld"

But starting from /store/zephyr/ there is no …/…/…/modules. If any of the “…/” are symlinks at configure time the build will fail.

If these files would embed absolute paths instead the symlinks would be resolved correctly at configure and build time. Is there any reason to prefer relative paths over absolute paths?

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 25

Most upvoted comments

When the build is running it thinks its running from wherever it really is in the filesystem, i.e. /store/zephyr instead of ./workspace/zephyr.

It depends. The build system is made of a very large collection of parts and different parts have different opinions.

But starting from /store/zephyr/ there is no …/…/…/modules.

Yes, symbolic links break relative paths, this has always been the case. Symbolic links are “quick hacks”, they cause countless other issues: https://lwn.net/Articles/899543/

I frequently use symbolic links to avoid spending time solving real problems and I even submitted small symlink fixes when possible (1c8632cfaad3, f7414ab85958, https://github.com/zephyrproject-rtos/west/pull/313, …) but I keep my symlinks expectations low.

It turns out this is not the way it always has been (62d611a3f8645c, 2019). The desire to move to relative paths was ironically in the name of reproducibility.

I miss the irony sorry. Any connection between symlinks and reproducibility?

EDIT: I missed you were working on reproducibility.

On a somewhat related note, this ZEPHYR_BASE discussion:

cc: @aborisovich