[klibc] [PATCH] Kbuild for klibc and nfsmount: fix multiple definitions

Christophe Leroy christophe.leroy at csgroup.eu
Thu Jun 18 10:05:23 PDT 2020


-fcommon is not default anymore, with GCC 10 you get the following
failure without it:

  KLIBCLD usr/klibc/libc.so
ppc-linux-ld: usr/klibc/globals.o:/root/packages/klibc-2.0.7/usr/klibc/../include/unistd.h:15: multiple definition of `environ'; usr/klibc/__shared_init.o:/root/ldb_base/ofl/packages/klibc-2.0.7/usr/klibc/libc_init.c:42: first defined here
ppc-linux-ld: usr/klibc/sbrk.o:(.sbss+0x0): multiple definition of `__current_brk'; usr/klibc/brk.o:(.sbss+0x0): first defined here
ppc-linux-ld: usr/klibc/getopt_long.o:(.sbss+0x8): multiple definition of `optind'; usr/klibc/getopt.o:(.sbss+0x8): first defined here
ppc-linux-ld: usr/klibc/getopt_long.o:(.sbss+0xc): multiple definition of `optarg'; usr/klibc/getopt.o:(.sbss+0xc): first defined here
ppc-linux-ld: usr/klibc/getopt_long.o:(.sbss+0x0): multiple definition of `optopt'; usr/klibc/getopt.o:(.sbss+0x0): first defined here
ppc-linux-ld: usr/klibc/getopt_long.o:(.sbss+0x4): multiple definition of `opterr'; usr/klibc/getopt.o:(.sbss+0x4): first defined here
ppc-linux-ld: usr/klibc/mrand48.o:/root/ldb_base/ofl/packages/klibc-2.0.7/usr/klibc/mrand48.c:8: multiple definition of `__rand48_seed'; usr/klibc/lrand48.o:/root/ldb_base/ofl/packages/klibc-2.0.7/usr/klibc/lrand48.c:8: first defined here
ppc-linux-ld: usr/klibc/srand48.o:/root/ldb_base/ofl/packages/klibc-2.0.7/usr/klibc/srand48.c:8: multiple definition of `__rand48_seed'; usr/klibc/lrand48.o:/root/ldb_base/ofl/packages/klibc-2.0.7/usr/klibc/lrand48.c:8: first defined here
ppc-linux-ld: usr/klibc/seed48.o:/root/ldb_base/ofl/packages/klibc-2.0.7/usr/klibc/seed48.c:9: multiple definition of `__rand48_seed'; usr/klibc/lrand48.o:/root/ldb_base/ofl/packages/klibc-2.0.7/usr/klibc/lrand48.c:8: first defined here
make[2]: *** [usr/klibc/libc.so] Error 1

This is due to some variable defined several times. Make sure
they are defined only once.

Signed-off-by: Christophe Leroy <christophe.leroy at csgroup.eu>
---
 usr/kinit/kinit.c       | 1 -
 usr/klibc/getopt_long.c | 4 ++--
 usr/klibc/libc_init.c   | 2 +-
 usr/klibc/lrand48.c     | 2 +-
 usr/klibc/mrand48.c     | 2 +-
 usr/klibc/sbrk.c        | 2 +-
 usr/klibc/srand48.c     | 2 +-
 7 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/usr/kinit/kinit.c b/usr/kinit/kinit.c
index 28d29534896f..e2a2439c53ac 100644
--- a/usr/kinit/kinit.c
+++ b/usr/kinit/kinit.c
@@ -15,7 +15,6 @@
 #include "run-init.h"
 #include "resume.h"
 
-const char *progname = "kinit";
 int mnt_procfs;
 int mnt_sysfs;
 
diff --git a/usr/klibc/getopt_long.c b/usr/klibc/getopt_long.c
index e3d064b0af46..87c0559399e3 100644
--- a/usr/klibc/getopt_long.c
+++ b/usr/klibc/getopt_long.c
@@ -13,8 +13,8 @@
 #include <string.h>
 #include <getopt.h>
 
-char *optarg;
-int optind, opterr, optopt;
+extern char *optarg;
+extern int optind, opterr, optopt;
 static struct getopt_private_state {
 	const char *optptr;
 	const char *last_optstring;
diff --git a/usr/klibc/libc_init.c b/usr/klibc/libc_init.c
index c5b9bab4ef0c..6c4de361c42c 100644
--- a/usr/klibc/libc_init.c
+++ b/usr/klibc/libc_init.c
@@ -22,6 +22,7 @@
 #include <stddef.h>
 #include <stdlib.h>
 #include <stdint.h>
+#include <unistd.h>
 #include <klibc/compiler.h>
 #include <elf.h>
 #include <sys/auxv.h>
@@ -39,7 +40,6 @@
 # error "SHARED should be defined to 0 or 1"
 #endif
 
-char **environ;
 unsigned int __page_size, __page_shift;
 
 struct auxentry {
diff --git a/usr/klibc/lrand48.c b/usr/klibc/lrand48.c
index 7dfcf9200128..a2fc87ae039f 100644
--- a/usr/klibc/lrand48.c
+++ b/usr/klibc/lrand48.c
@@ -5,7 +5,7 @@
 #include <stdlib.h>
 #include <stdint.h>
 
-unsigned short __rand48_seed[3];	/* Common with mrand48.c, srand48.c */
+extern unsigned short __rand48_seed[3];	/* Common with mrand48.c, srand48.c */
 
 long lrand48(void)
 {
diff --git a/usr/klibc/mrand48.c b/usr/klibc/mrand48.c
index e3b73ccf7c2f..1a2383be8472 100644
--- a/usr/klibc/mrand48.c
+++ b/usr/klibc/mrand48.c
@@ -5,7 +5,7 @@
 #include <stdlib.h>
 #include <stdint.h>
 
-unsigned short __rand48_seed[3];	/* Common with lrand48.c, srand48.c */
+extern unsigned short __rand48_seed[3];	/* Common with lrand48.c, srand48.c */
 
 long mrand48(void)
 {
diff --git a/usr/klibc/sbrk.c b/usr/klibc/sbrk.c
index 4896ce0b1f9d..125aae6529d7 100644
--- a/usr/klibc/sbrk.c
+++ b/usr/klibc/sbrk.c
@@ -11,7 +11,7 @@
 
 #if !_KLIBC_NO_MMU		/* uClinux doesn't have brk() */
 
-char *__current_brk;		/* Common with brk.c */
+extern char *__current_brk;		/* Common with brk.c */
 
 /* p is an address,  a is alignment; must be a power of 2 */
 static inline void *align_up(void *p, uintptr_t a)
diff --git a/usr/klibc/srand48.c b/usr/klibc/srand48.c
index e1c95672f731..dd2112764af8 100644
--- a/usr/klibc/srand48.c
+++ b/usr/klibc/srand48.c
@@ -5,7 +5,7 @@
 #include <stdlib.h>
 #include <stdint.h>
 
-unsigned short __rand48_seed[3];	/* Common with mrand48.c, lrand48.c */
+extern unsigned short __rand48_seed[3];	/* Common with mrand48.c, lrand48.c */
 
 void srand48(long seedval)
 {
-- 
2.25.0



More information about the klibc mailing list