chettrick / discobsd

2.11BSD-based Unix-like OS for STM32 and PIC32 Microcontrollers
http://www.DiscoBSD.org
BSD 3-Clause "New" or "Revised" License
182 stars 16 forks source link

kconfig: /usr/bin/ld: multiple definition of `debugging` #4

Closed saper closed 1 year ago

saper commented 1 year ago

This is gcc 11.3.1 on Almalinux 9, GNU ld 2.35.2

same with gcc 11 on FreeBSD

make[2]: Entering directory '/home/saper/src/discobsd/tools/kconfig'
gcc -g  -o kconfig config.o main.o lang.o mkioconf.o mkmakefile.o mkswapconf.o 
/usr/bin/ld: main.o:/home/saper/src/discobsd/tools/kconfig/config.h:180: multiple definition of `debugging'; config.o:/home/saper/src/discobsd/tools/kconfig/config.h:180: first defined here
/usr/bin/ld: main.o:/home/saper/src/discobsd/tools/kconfig/config.h:171: multiple definition of `dtab'; config.o:/home/saper/src/discobsd/tools/kconfig/config.h:171: first defined here
/usr/bin/ld: main.o:/home/saper/src/discobsd/tools/kconfig/config.h:176: multiple definition of `conf_list'; config.o:/home/saper/src/discobsd/tools/kconfig/config.h:176: first defined here

I fixed this with the following for now:

diff --git a/tools/kconfig/Makefile b/tools/kconfig/Makefile
index 42cb1cb..2b0eb56 100644
--- a/tools/kconfig/Makefile
+++ b/tools/kconfig/Makefile
@@ -1,5 +1,6 @@
 CC             = gcc -g
 CFLAGS         = -O -Wall -Werror
+LDFLAGS                = -z muldefs

 _HOST_OSNAME!= uname -s

but I think this is not a best change probably a linker script might be needed here...

chettrick commented 1 year ago

I have been able to recreate the issue with gcc-11.2 on a fresh OpenBSD 7.3, but gcc-8.4 (my current default gcc on OpenBSD) or earlier does not raise these errors. The proper solution is to handle the variable declarations and definitions in kconfig properly (old codebase), but using an older gcc is a stopgap measure.

Thanks for the heads up.

saper commented 1 year ago

I think just adding -fcommon to modern compilers might also fix this. I am not sure I want to see 2.11BSD code overly modernized, let's make compilers work a bit harder :)

Thanks for supporting BSD make now! It feels much better now. I am not sure I like 4.4BSD layout, the old once had a nice ancient flair! Great project, thank you!