mk install: multiple definitions of coherence

47 views
Skip to first unread message

Paul Dufresne

unread,
Jun 26, 2021, 11:54:56 AM6/26/21
to inferno-os

I see:
/inferno/os/pc/fns.h:10:void    (*coherence)(void);
/inferno/emu/port/fns.h:23:void    (*coherence)(void);

Paul Dufresne

unread,
Jun 26, 2021, 12:13:58 PM6/26/21
to inferno-os
I just tried replacing both definitions by:
#ifndef COHERENCE_DEFINED
#define COHERENCE_DEFFINED
void    (*coherence)(void);
#endif

Still getting (after mk nuke) on mk install:
/usr/bin/ld: kproc-pthreads.o:/inferno/emu/Linux/../port/fns.h:25: multiple definition of `coherence'; os.o:/inferno/emu/Linux/../port/fns.h:25: first defined here
/usr/bin/ld: lock.o:/inferno/emu/Linux/../port/fns.h:25: multiple definition of `coherence'; os.o:/inferno/emu/Linux/../port/fns.h:25: first defined here
/usr/bin/ld: ipif6-posix.o:/inferno/emu/Linux/../port/fns.h:25: multiple definition of `coherence'; os.o:/inferno/emu/Linux/../port/fns.h:25: first defined here
/usr/bin/ld: cmd.o:/inferno/emu/Linux/../port/fns.h:25: multiple definition of `coherence'; os.o:/inferno/emu/Linux/../port/fns.h:25: first defined here
/usr/bin/ld: devmnt.o:/inferno/emu/Linux/../port/fns.h:25: multiple definition of `coherence'; os.o:/inferno/emu/Linux/../port/fns.h:25: first defined here
/usr/bin/ld: win-x11a.o:/inferno/emu/Linux/../port/fns.h:25: multiple definition of `coherence'; os.o:/inferno/emu/Linux/../port/fns.h:25: first defined here

Paul Dufresne

unread,
Jun 26, 2021, 12:25:29 PM6/26/21
to inferno-os
Even fixing the typo of DEFFINED (extra F) and adding it also for:
/inferno/os/pc/devarch.c:509:void (*coherence)(void) = nop;
did not seems to help.

Paul Dufresne

unread,
Jun 26, 2021, 1:17:59 PM6/26/21
to inferno-os
I added static:
paul@kasparno:/inferno$ grep -rnw '/inferno/' -e *coherence
/inferno/emu/port/fns.h:25:static void    (*coherence)(void);
/inferno/os/pc/devarch.c:510:void (*coherence)(void) = nop;
/inferno/os/pc/fns.h:12:static void    (*coherence)(void);
paul@kasparno:/inferno$
And  that seems to have fixed that problem... I still get:
/usr/bin/ld: devcons.o:/inferno/emu/Linux/../port/devcons.c:64: multiple definition of `gkscanid'; win-x11a.o:/inferno/emu/Linux/../port/win-x11a.c:120: first defined here
/usr/bin/ld: exportfs.o:/inferno/emu/Linux/../port/exportfs.c:108: multiple definition of `exdebug'; devcons.o:/inferno/emu/Linux/../port/devcons.c:10: first defined here
/usr/bin/ld: dis.o:/inferno/emu/Linux/../port/dis.c:26: multiple definition of `bflag'; main.o:/inferno/emu/Linux/../port/main.c:23: first defined here
/usr/bin/ld: /inferno/Linux/386/lib/libinterp.a(tk.o):/inferno/libinterp/tk.c:17: multiple definition of `tkstylus'; main.o:/inferno/emu/Linux/../port/main.c:14: first defined here
/usr/bin/ld: /inferno/Linux/386/lib/libtk.a(utils.o):/inferno/libtk/utils.c:57: multiple definition of `tkfont'; main.o:/inferno/emu/Linux/../port/main.c:13: first defined here
collect2: error: ld returned 1 exit status
mk: cc -c -m32 ...  : exit status=exit(1)
mk: echo "(cd $SYSTARG; ...  : exit status=exit(1)
mk: for j in ...  : exit status=exit(1)

Paul Dufresne

unread,
Jun 26, 2021, 1:43:06 PM6/26/21
to inferno-os
Looks like someone else have a solution for many months:

Paul Dufresne

unread,
Jun 26, 2021, 1:51:55 PM6/26/21
to inferno-os
But his solution: adding extern does not make sense to me (as it means it needs to be defined elsewhere...) ... static make sense, it make the function or variable local to the file where it is defined. (for a variable in a function it would means keep it's value between different invocatons).

Paul Dufresne

unread,
Jun 26, 2021, 6:13:54 PM6/26/21
to inferno-os
I now think that adding "external" before declarations in .h is the correct solution.
If they were not mark static already, it is that the value is expected to be shared (being global).
The solution is *I now think* to add external, and have the real declaration in a unique place, like in main.c.

Go Phone

unread,
Jun 26, 2021, 6:25:50 PM6/26/21
to inferno-os
I worked around this by moving the coherence to port/main.c

Go Phone

unread,
Jun 26, 2021, 6:27:13 PM6/26/21
to inferno-os
diff --git a/emu/port/fns.h b/emu/port/fns.h
index 357be61f..d16a753a 100644
--- a/emu/port/fns.h
+++ b/emu/port/fns.h
@@ -20,7 +20,7 @@ Dir*          chandirstat(Chan*);
 void           cinit(void);
 char*  clipread(void);
 int            clipwrite(char*);
-void   (*coherence)(void);
+/*void (*coherence)(void); moved this to port/main.c to avoid the duplicate symbols error */
 void           copen(Chan*);
 void           cmderror(Cmdbuf*, char*);
 Block* concatblock(Block*);
diff --git a/emu/port/lock.c b/emu/port/lock.c
index 7028dbd8..adba21b2 100644
--- a/emu/port/lock.c
+++ b/emu/port/lock.c
@@ -2,6 +2,8 @@
 #include       "fns.h"
 #include       "error.h"
 
+extern void    (*coherence)(void);
+
 void
 lock(Lock *l)
 {
diff --git a/emu/port/main.c b/emu/port/main.c
index d5ec8829..a1dc470a 100644
--- a/emu/port/main.c
+++ b/emu/port/main.c
@@ -7,15 +7,17 @@
 #include       "version.h"
 
 #define DP if(1){}else print
+void   (*coherence)(void) = nil;       /* used by port/lock.c and port/win-x11a.c */
+int    exdebug = 0;
 int            rebootargc = 0;
 char**         rebootargv;
+char   gkscanid[32] = "";

Paul Dufresne

unread,
Jun 27, 2021, 5:54:42 PM6/27/21
to inferno-os
which deels with the multiple definitions at linking time.

"GCC now defaults to -fno-common. As a result, global variable accesses are more efficient on various targets. In C, global variables with multiple tentative definitions now result in linker errors. With -fcommon such definitions are silently merged during linking."
Reply all
Reply to author
Forward
0 new messages