Christophe Leroy
2020-Jun-18 17:05 UTC
[klibc] [PATCH] Kbuild for klibc and nfsmount: fix multiple definitions
-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
Ben Hutchings
2020-Jul-25 21:16 UTC
[klibc] [PATCH] Kbuild for klibc and nfsmount: fix multiple definitions
On Thu, 2020-06-18 at 17:05 +0000, Christophe Leroy wrote:> -fcommon is not default anymore, with GCC 10 you get the following > failure without it:I just applied another patch that adds -fcommon, to make Clang happy, and that should also work for gcc. However, I'd be happy to apply this with a couple of changes: [...]> 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;[...] No, this is the definition we want to keep. Delete the other definition in usr/kinit/nfsmount/main.c. Please also change the -fcommon option to -fno-common, so that if a developer re-introductes multiple definitions they'll get a compiler error immediately, whichever compiler version they are using. Ben. -- Ben Hutchings Anthony's Law of Force: Don't force it, get a larger hammer. -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: This is a digitally signed message part URL: <https://lists.zytor.com/archives/klibc/attachments/20200725/45e593a1/attachment.sig>
Seemingly Similar Threads
- [PATCH] Kbuild for klibc and nfsmount: add -fcommon
- [PATCH] fix build failure when CONFIG_KLIBC_ZLIB is not set
- [PATCH v2] fix build failure when CONFIG_KLIBC_ZLIB is not set
- [klibc:master] fix build failure when CONFIG_KLIBC_ZLIB is not set
- klibc 1.5.21-1 and mksh