Bug 15658

Summary: hifive_unleashed_defconfig: Linker errors in opensbi-0.9
Product: buildroot Reporter: Jan-Benedict Glaw <jbglaw>
Component: OtherAssignee: unassigned
Status: RESOLVED FIXED    
Severity: normal CC: buildroot, yann.morin.1998
Priority: P5    
Version: unspecified   
Target Milestone: ---   
Hardware: All   
OS: Linux   
Host: Target:
Build:
Attachments: one line patch that adds -fno-stack-protector to the CFLAGS for opensbi-0.9

Description Jan-Benedict Glaw 2023-06-22 16:32:41 UTC
As of c765ac9c02dbddd53cf6813cf59c8f265b043caf, I see this build error:

[build 2023-06-20 03:57:13]  ELF       platform/generic/firmware/fw_dynamic.elf
[build 2023-06-20 03:57:13] /var/lib/laminar/run/buildroot-hifive_unleashed_defconfig/5/buildroot/output/host/lib/gcc/riscv64-buildroot-linux-gnu/11.3.0/../../../../riscv64-buildroot-linux-gnu/bin/ld: /var/lib/laminar/run/buildroot-hifive_unleashed_defconfig/5/buildroot/output/build/opensbi-0.9/build/platform/generic/lib/libplatsbi.a(sbi_init.o): in function `sbi_init':
[build 2023-06-20 03:57:13] /var/lib/laminar/run/buildroot-hifive_unleashed_defconfig/5/buildroot/output/build/opensbi-0.9/lib/sbi/sbi_init.c:385: undefined reference to `__stack_chk_guard'
[build 2023-06-20 03:57:13] /var/lib/laminar/run/buildroot-hifive_unleashed_defconfig/5/buildroot/output/host/lib/gcc/riscv64-buildroot-linux-gnu/11.3.0/../../../../riscv64-buildroot-linux-gnu/bin/ld: /var/lib/laminar/run/buildroot-hifive_unleashed_defconfig/5/buildroot/output/build/opensbi-0.9/build/platform/generic/lib/libplatsbi.a(sbi_ipi.o): in function `sbi_ipi_send_many':
[build 2023-06-20 03:57:13] /var/lib/laminar/run/buildroot-hifive_unleashed_defconfig/5/buildroot/output/build/opensbi-0.9/lib/sbi/sbi_ipi.c:78: undefined reference to `__stack_chk_guard'
[build 2023-06-20 03:57:13] /var/lib/laminar/run/buildroot-hifive_unleashed_defconfig/5/buildroot/output/host/lib/gcc/riscv64-buildroot-linux-gnu/11.3.0/../../../../riscv64-buildroot-linux-gnu/bin/ld: /var/lib/laminar/run/buildroot-hifive_unleashed_defconfig/5/buildroot/output/build/opensbi-0.9/lib/sbi/sbi_ipi.c:92: undefined reference to `__stack_chk_fail'
[build 2023-06-20 03:57:13] /var/lib/laminar/run/buildroot-hifive_unleashed_defconfig/5/buildroot/output/host/lib/gcc/riscv64-buildroot-linux-gnu/11.3.0/../../../../riscv64-buildroot-linux-gnu/bin/ld: /var/lib/laminar/run/buildroot-hifive_unleashed_defconfig/5/buildroot/output/build/opensbi-0.9/build/platform/generic/lib/libplatsbi.a(sbi_tlb.o): in function `sbi_tlb_process':
[build 2023-06-20 03:57:13] /var/lib/laminar/run/buildroot-hifive_unleashed_defconfig/5/buildroot/output/build/opensbi-0.9/lib/sbi/sbi_tlb.c:213: undefined reference to `__stack_chk_guard'
[build 2023-06-20 03:57:13] /var/lib/laminar/run/buildroot-hifive_unleashed_defconfig/5/buildroot/output/host/lib/gcc/riscv64-buildroot-linux-gnu/11.3.0/../../../../riscv64-buildroot-linux-gnu/bin/ld: /var/lib/laminar/run/buildroot-hifive_unleashed_defconfig/5/buildroot/output/build/opensbi-0.9/lib/sbi/sbi_tlb.c:220: undefined reference to `__stack_chk_fail'
[build 2023-06-20 03:57:13] /var/lib/laminar/run/buildroot-hifive_unleashed_defconfig/5/buildroot/output/host/lib/gcc/riscv64-buildroot-linux-gnu/11.3.0/../../../../riscv64-buildroot-linux-gnu/bin/ld: /var/lib/laminar/run/buildroot-hifive_unleashed_defconfig/5/buildroot/output/build/opensbi-0.9/build/platform/generic/lib/libplatsbi.a(sbi_tlb.o): in function `sbi_tlb_update':
[build 2023-06-20 03:57:13] /var/lib/laminar/run/buildroot-hifive_unleashed_defconfig/5/buildroot/output/build/opensbi-0.9/lib/sbi/sbi_tlb.c:308: undefined reference to `__stack_chk_guard'
[build 2023-06-20 03:57:13] /var/lib/laminar/run/buildroot-hifive_unleashed_defconfig/5/buildroot/output/host/lib/gcc/riscv64-buildroot-linux-gnu/11.3.0/../../../../riscv64-buildroot-linux-gnu/bin/ld: /var/lib/laminar/run/buildroot-hifive_unleashed_defconfig/5/buildroot/output/build/opensbi-0.9/build/platform/generic/lib/libplatsbi.a(sbi_tlb.o): in function `sbi_tlb_process_count':


[...]

[build 2023-06-20 03:57:13] /var/lib/laminar/run/buildroot-hifive_unleashed_defconfig/5/buildroot/output/host/lib/gcc/riscv64-buildroot-linux-gnu/11.3.0/../../../../riscv64-buildroot-linux-gnu/bin/ld: /var/lib/laminar/run/buildroot-hifive_unleashed_defconfig/5/buildroot/output/build/opensbi-0.9/lib/utils/libfdt/fdt_wip.c:81: undefined reference to `__stack_chk_guard'
[build 2023-06-20 03:57:13] /var/lib/laminar/run/buildroot-hifive_unleashed_defconfig/5/buildroot/output/host/lib/gcc/riscv64-buildroot-linux-gnu/11.3.0/../../../../riscv64-buildroot-linux-gnu/bin/ld: /var/lib/laminar/run/buildroot-hifive_unleashed_defconfig/5/buildroot/output/build/opensbi-0.9/build/platform/generic/lib/libplatsbi.a(fdt_wip.o): in function `fdt_nop_region_':
[build 2023-06-20 03:57:13] /var/lib/laminar/run/buildroot-hifive_unleashed_defconfig/5/buildroot/output/build/opensbi-0.9/lib/utils/libfdt/fdt_wip.c:55: undefined reference to `__stack_chk_fail'
[build 2023-06-20 03:57:13] collect2: error: ld returned 1 exit status
[build 2023-06-20 03:57:13] make[1]: *** [Makefile:351: /var/lib/laminar/run/buildroot-hifive_unleashed_defconfig/5/buildroot/output/build/opensbi-0.9/build/platform/generic/firmware/fw_dynamic.elf] Error 1
[build 2023-06-20 03:57:13] make[1]: Leaving directory '/var/lib/laminar/run/buildroot-hifive_unleashed_defconfig/5/buildroot/output/build/opensbi-0.9'
[build 2023-06-20 03:57:13] make: *** [package/pkg-generic.mk:293: /var/lib/laminar/run/buildroot-hifive_unleashed_defconfig/5/buildroot/output/build/opensbi-0.9/.stamp_built] Error 2


(Build log at http://toolchain.lug-owl.de/laminar/jobs/buildroot-hifive_unleashed_defconfig/5 )
Comment 1 Zhen XIN 2023-06-25 11:00:45 UTC
Created attachment 9613 [details]
one line patch that adds -fno-stack-protector to the CFLAGS for opensbi-0.9

Put this patch in boot/opensbi/0.9/ and it builds fine.
Comment 2 Yann E. MORIN 2023-06-25 12:14:36 UTC
Jan-Benedict, All,

You want to get the patch added by 2f7582538fa5 (boot/opensbi: unconditionally
disable SSP) and carry it locally in your global patch dir.

When we bumped opensbi from 0.9 to 1.2, that patch no longer applied to 1.2.
We can't indefinitely carry patches against older versions, so we dropped it.

It is your responsibility when using a custom version (c765ac9c02db is
2023.05-rc2, which already has opensbi 1.2), to provide any necessary patch,
or to use an already patched version.

Regards,
Yann E. MORIN.
Comment 3 Jan-Benedict Glaw 2023-06-25 18:16:09 UTC
I'm just doing plain builds with the provided configs. With 0.9 being stripped, maybe the default config needs an update?

BR2_TARGET_OPENSBI=y
BR2_TARGET_OPENSBI_CUSTOM_VERSION=y
BR2_TARGET_OPENSBI_CUSTOM_VERSION_VALUE="0.9"
BR2_TARGET_OPENSBI_PLAT="generic"

I'll drop the two people that worked on that area an email to get their opinion about it.
Comment 4 Yann E. MORIN 2023-06-25 19:19:54 UTC
Jan-Benedict, All,

(In reply to Jan-Benedict Glaw from comment #3)
> I'm just doing plain builds with the provided [hifive_unleashed_defconfig]

Right, sorry, I totally missed that.

So, then we have two options (in order of preference, but n reverse order
of simplicity):

 1. switch hifive_unleashed_defconfig to use opensbi 1.2

 2. add the patch from 2f7582538fa5 into board/sifive/hifive-unleashed/linux/
    and use a global patch dir to point to board/sifive/hifive-unleashed/

Seeing commit fad36fa91d9a (configs/hifive_unleashed_defconfig: explicitly
use OpenSBI 0.9), there does not seem to be a reason to not use 1.2, so we
should at least try that. Could you please report wether opensbi 1.2 also
works?

Regards,
Yann E. MORIN.
Comment 5 Yann E. MORIN 2023-06-26 17:23:10 UTC
Jan-Benedict, All,

Thanks for the report. We believe it has now ben fixed by commit 02f6d77fbd
(configs/hifive_unleashed: Update to use OpenSBI 1.2).

If the issue still persists, do not hesitate to reopen.

Regards,
Yann E. MORIN.
Comment 6 Jan-Benedict Glaw 2023-06-26 19:03:09 UTC
Started a new build for this configuration (http://toolchain.lug-owl.de/laminar/jobs/buildroot-hifive_unleashed_defconfig/7), will let you know how it turned out.
Comment 7 Jan-Benedict Glaw 2023-06-26 20:23:52 UTC
Now breaks in uboot:

[build 2023-06-26 20:19:23] /usr/bin/make -f ./scripts/Makefile.build obj=scripts/dtc/pylibfdt
[build 2023-06-26 20:19:23]   cat scripts/dtc/pylibfdt/libfdt.i_shipped > scripts/dtc/pylibfdt/libfdt.i
[build 2023-06-26 20:19:23]   unset CROSS_COMPILE; unset CFLAGS; CC="/usr/bin/gcc -O2 -isystem /var/lib/laminar/run/buildroot-hifive_unleashed_defconfig/7/buildroot/output/host/include" LDSHARED="/usr/bin/gcc -O2 -isystem /var/lib/laminar/run/buildroot-hifive_unleashed_defconfig/7/buildroot/output/host/include -shared " LDFLAGS="-L/var/lib/laminar/run/buildroot-hifive_unleashed_defconfig/7/buildroot/output/host/lib -Wl,-rpath,/var/lib/laminar/run/buildroot-hifive_unleashed_defconfig/7/buildroot/output/host/lib" VERSION="2023.04" CPPFLAGS=" -I/var/lib/laminar/run/buildroot-hifive_unleashed_defconfig/7/buildroot/output/build/uboot-2023.04/scripts/dtc/libfdt" OBJDIR=scripts/dtc/pylibfdt SOURCES="/var/lib/laminar/run/buildroot-hifive_unleashed_defconfig/7/buildroot/output/build/uboot-2023.04/scripts/dtc/libfdt/fdt.c /var/lib/laminar/run/buildroot-hifive_unleashed_defconfig/7/buildroot/output/build/uboot-2023.04/scripts/dtc/libfdt/fdt_ro.c /var/lib/laminar/run/buildroot-hifive_unleashed_defconfig/7/buildroot/output/build/uboot-2023.04/scripts/dtc/libfdt/fdt_wip.c /var/lib/laminar/run/buildroot-hifive_unleashed_defconfig/7/buildroot/output/build/uboot-2023.04/scripts/dtc/libfdt/fdt_sw.c /var/lib/laminar/run/buildroot-hifive_unleashed_defconfig/7/buildroot/output/build/uboot-2023.04/scripts/dtc/libfdt/fdt_rw.c /var/lib/laminar/run/buildroot-hifive_unleashed_defconfig/7/buildroot/output/build/uboot-2023.04/scripts/dtc/libfdt/fdt_strerror.c /var/lib/laminar/run/buildroot-hifive_unleashed_defconfig/7/buildroot/output/build/uboot-2023.04/scripts/dtc/libfdt/fdt_empty_tree.c /var/lib/laminar/run/buildroot-hifive_unleashed_defconfig/7/buildroot/output/build/uboot-2023.04/scripts/dtc/libfdt/fdt_addresses.c /var/lib/laminar/run/buildroot-hifive_unleashed_defconfig/7/buildroot/output/build/uboot-2023.04/scripts/dtc/libfdt/fdt_overlay.c scripts/dtc/pylibfdt/libfdt.i" SWIG_OPTS="-I/var/lib/laminar/run/buildroot-hifive_unleashed_defconfig/7/buildroot/output/build/uboot-2023.04/scripts/dtc/libfdt -I/var/lib/laminar/run/buildroot-hifive_unleashed_defconfig/7/buildroot/output/build/uboot-2023.04/scripts/dtc/libfdt/.." python3 scripts/dtc/pylibfdt/setup.py --quiet build_ext --inplace
[build 2023-06-26 20:19:23] Traceback (most recent call last):
[build 2023-06-26 20:19:23]   File "/var/lib/laminar/run/buildroot-hifive_unleashed_defconfig/7/buildroot/output/build/uboot-2023.04/scripts/dtc/pylibfdt/setup.py", line 23, in <module>
[build 2023-06-26 20:19:23]     from setuptools import setup, Extension
[build 2023-06-26 20:19:23] ModuleNotFoundError: No module named 'setuptools'
[build 2023-06-26 20:19:23] make[3]: *** [scripts/dtc/pylibfdt/Makefile:33: rebuild] Error 1
[build 2023-06-26 20:19:23] make[2]: *** [scripts/Makefile.build:397: scripts/dtc/pylibfdt] Error 2
[build 2023-06-26 20:19:23] make[1]: *** [Makefile:2003: scripts_dtc] Error 2
[build 2023-06-26 20:19:23] make[1]: Leaving directory '/var/lib/laminar/run/buildroot-hifive_unleashed_defconfig/7/buildroot/output/build/uboot-2023.04'
[build 2023-06-26 20:19:23] make: *** [package/pkg-generic.mk:293: /var/lib/laminar/run/buildroot-hifive_unleashed_defconfig/7/buildroot/output/build/uboot-2023.04/.stamp_built] Error 2


I'm doing the CI builds in quite minimal Docker containers, with just the bare minimum documented packages installed. Shall I add Python's setuptools? Or is it a missing dependency? (Maybe I'd have put that into a new ticket?)
Comment 8 Jan-Benedict Glaw 2023-07-05 19:07:29 UTC
Hits on --target=i686-pc-msdosdjgpp as well (http://toolchain.lug-owl.de/laminar/jobs/binutils-i686-pc-msdosdjgpp/38).
Comment 9 Jan-Benedict Glaw 2023-07-05 19:09:25 UTC
Sorry, that former comment was ment for a different ticket!
Comment 10 Peter Korsgaard 2023-07-16 09:09:33 UTC
(In reply to Jan-Benedict Glaw from comment #7)

Looks like the new U-Boot version needs BR2_TARGET_UBOOT_NEEDS_PYLIBFDT. Could you check that?

In the mean time I have cherry picked the opensbi bump for 2023.05.x, so I'm closing this issue - Thanks!