Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to compile ext with multiple definition errors #261

Closed
runlevel5 opened this issue Mar 6, 2020 · 7 comments · Fixed by #288
Closed

Failed to compile ext with multiple definition errors #261

runlevel5 opened this issue Mar 6, 2020 · 7 comments · Fixed by #288

Comments

@runlevel5
Copy link

$ uname -a
Linux orion.dev 5.5.7-200.fc31.ppc64le #1 SMP Fri Feb 28 17:07:46 UTC 2020 ppc64le ppc64le ppc64le GNU/Linux

$ gcc --version
gcc (GCC) 10.0.1 20200216 (Red Hat 10.0.1-0.8)
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ ld --version
GNU ld version 2.34-2.fc32
Copyright (C) 2020 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License version 3 or (at your option) a later version.
This program has absolutely no warranty.

$ make --version
GNU Make 4.2.1
Built for powerpc64le-redhat-linux-gnu
Copyright (C) 1988-2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

$ make
compiling semian.c
compiling tickets.c
linking shared-object semian/semian.so
/usr/bin/ld: semian.o:(.bss+0x60): multiple definition of `eSyscall'; resource.o:(.bss+0x28): first defined here
/usr/bin/ld: semian.o:(.bss+0x58): multiple definition of `eTimeout'; resource.o:(.bss+0x20): first defined here
/usr/bin/ld: semian.o:(.bss+0x50): multiple definition of `eInternal'; resource.o:(.bss+0x18): first defined here
/usr/bin/ld: semian.o:(.bss+0x48): multiple definition of `id_wait_time'; resource.o:(.bss+0x10): first defined here
/usr/bin/ld: semian.o:(.bss+0x40): multiple definition of `id_timeout'; resource.o:(.bss+0x8): first defined here
/usr/bin/ld: semian.o:(.bss+0x38): multiple definition of `system_max_semaphore_count'; resource.o:(.bss+0x0): first defined here
/usr/bin/ld: sysv_semaphores.o:(.bss+0x10): multiple definition of `eSyscall'; resource.o:(.bss+0x28): first defined here
/usr/bin/ld: sysv_semaphores.o:(.bss+0x0): multiple definition of `eInternal'; resource.o:(.bss+0x18): first defined here
/usr/bin/ld: sysv_semaphores.o:(.bss+0x8): multiple definition of `eTimeout'; resource.o:(.bss+0x20): first defined here
/usr/bin/ld: tickets.o:(.bss+0x10): multiple definition of `eSyscall'; resource.o:(.bss+0x28): first defined here
/usr/bin/ld: tickets.o:(.bss+0x8): multiple definition of `eTimeout'; resource.o:(.bss+0x20): first defined here
/usr/bin/ld: tickets.o:(.bss+0x0): multiple definition of `eInternal'; resource.o:(.bss+0x18): first defined here
collect2: error: ld returned 1 exit status
make: *** [Makefile:261: semian.so] Error 1

The program could be compiled if I set LDFLAG explicitly with --allow-multiple-definition

Wondering if the team could resolve these warnings sot that semian could be compiled without --allow-multiple-definition flag?

@dalehamel
Copy link
Member

I don't see these values actually being defined more than once. I wonder if some behavior has changed in GCC 10?

Can you reproduce on any older version of GCC, eg, GCC 8?

@haines
Copy link
Contributor

haines commented Feb 18, 2021

I'm running into this in the Alpine-based Ruby Docker containers. On Alpine 3.12 (gcc 9.3.0) I can install Semian, but on Alpine 3.13 (gcc 10.2.1) I can't:

$ docker run --rm ruby:2.7.2-alpine3.12 sh -c 'apk add build-base openssl-dev && gem install semian --version 0.11.3'
fetch http://dl-cdn.alpinelinux.org/alpine/v3.12/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.12/community/x86_64/APKINDEX.tar.gz
(1/20) Upgrading libcrypto1.1 (1.1.1i-r0 -> 1.1.1j-r0)
(2/20) Upgrading libssl1.1 (1.1.1i-r0 -> 1.1.1j-r0)
(3/20) Installing binutils (2.34-r1)
(4/20) Installing libmagic (5.38-r0)
(5/20) Installing file (5.38-r0)
(6/20) Installing isl (0.18-r0)
(7/20) Installing libgomp (9.3.0-r2)
(8/20) Installing libatomic (9.3.0-r2)
(9/20) Installing libgphobos (9.3.0-r2)
(10/20) Installing mpfr4 (4.0.2-r4)
(11/20) Installing mpc1 (1.1.0-r1)
(12/20) Installing gcc (9.3.0-r2)
(13/20) Installing musl-dev (1.1.24-r10)
(14/20) Installing libc-dev (0.7.2-r3)
(15/20) Installing g++ (9.3.0-r2)
(16/20) Installing make (4.3-r0)
(17/20) Installing fortify-headers (1.1-r0)
(18/20) Installing patch (2.7.6-r6)
(19/20) Installing build-base (0.5-r2)
(20/20) Installing openssl-dev (1.1.1j-r0)
Executing busybox-1.31.1-r19.trigger
Executing ca-certificates-20191127-r4.trigger
OK: 219 MiB in 54 packages
Building native extensions. This could take a while...
Successfully installed semian-0.11.3
1 gem installed

$ docker run --rm ruby:2.7.2-alpine3.13 sh -c 'apk add build-base openssl-dev && gem install semian --version 0.11.3'
fetch https://dl-cdn.alpinelinux.org/alpine/v3.13/main/x86_64/APKINDEX.tar.gz
fetch https://dl-cdn.alpinelinux.org/alpine/v3.13/community/x86_64/APKINDEX.tar.gz
(1/18) Installing binutils (2.35.1-r1)
(2/18) Installing libmagic (5.39-r0)
(3/18) Installing file (5.39-r0)
(4/18) Installing libgomp (10.2.1_pre1-r3)
(5/18) Installing libatomic (10.2.1_pre1-r3)
(6/18) Installing libgphobos (10.2.1_pre1-r3)
(7/18) Installing isl22 (0.22-r0)
(8/18) Installing mpfr4 (4.1.0-r0)
(9/18) Installing mpc1 (1.2.0-r0)
(10/18) Installing gcc (10.2.1_pre1-r3)
(11/18) Installing musl-dev (1.2.2-r0)
(12/18) Installing libc-dev (0.7.2-r3)
(13/18) Installing g++ (10.2.1_pre1-r3)
(14/18) Installing make (4.3-r0)
(15/18) Installing fortify-headers (1.1-r0)
(16/18) Installing patch (2.7.6-r6)
(17/18) Installing build-base (0.5-r2)
(18/18) Installing openssl-dev (1.1.1j-r0)
Executing busybox-1.32.1-r3.trigger
OK: 209 MiB in 54 packages
Building native extensions. This could take a while...
ERROR:  Error installing semian:
	ERROR: Failed to build gem native extension.

    current directory: /usr/local/bundle/gems/semian-0.11.3/ext/semian
/usr/local/bin/ruby -I /usr/local/lib/ruby/2.7.0 -r ./siteconf20210218-1-1wb9nhd.rb extconf.rb
checking for openssl/sha.h... yes
checking for SHA1() in -lcrypto... yes
checking for sys/ipc.h... yes
checking for sys/sem.h... yes
checking for sys/types.h... yes
checking for rb_thread_blocking_region()... no
checking for rb_thread_call_without_gvl()... yes
creating Makefile

current directory: /usr/local/bundle/gems/semian-0.11.3/ext/semian
make "DESTDIR=" clean

current directory: /usr/local/bundle/gems/semian-0.11.3/ext/semian
make "DESTDIR="
compiling resource.c
compiling semian.c
compiling sysv_semaphores.c
compiling tickets.c
linking shared-object semian/semian.so
/usr/lib/gcc/x86_64-alpine-linux-musl/10.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: semian.o:(.bss+0x28): multiple definition of `id_wait_time'; resource.o:(.bss+0x10): first defined here
/usr/lib/gcc/x86_64-alpine-linux-musl/10.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: semian.o:(.bss+0x20): multiple definition of `id_timeout'; resource.o:(.bss+0x8): first defined here
/usr/lib/gcc/x86_64-alpine-linux-musl/10.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: semian.o:(.bss+0x18): multiple definition of `system_max_semaphore_count'; resource.o:(.bss+0x0): first defined here
collect2: error: ld returned 1 exit status
make: *** [Makefile:262: semian.so] Error 1

make failed, exit code 2

Gem files will remain installed in /usr/local/bundle/gems/semian-0.11.3 for inspection.
Results logged to /usr/local/bundle/extensions/x86_64-linux-musl/2.7.0/semian-0.11.3/gem_make.out

@haines
Copy link
Contributor

haines commented Feb 18, 2021

This looks like the culprit: https://gcc.gnu.org/gcc-10/porting_to.html#common

A common mistake in C is omitting extern when declaring a global variable in a header file. If the header is included by several files it results in multiple definitions of the same variable. In previous GCC versions this error is ignored. GCC 10 defaults to -fno-common, which means a linker error will now be reported. To fix this, use extern in header files when declaring global variables, and ensure each global is defined in exactly one C file. If tentative definitions of particular variables need to be placed in a common block, __attribute__((__common__)) can be used to force that behavior even in code compiled without -fcommon. As a workaround, legacy C code where all tentative definitions should be placed into a common block can be compiled with -fcommon.

  int x;  // tentative definition - avoid in header files

  extern int y;  // correct declaration in a header file

ID id_wait_time;
ID id_timeout;
int system_max_semaphore_count;

I'll try adding extern to those declarations.

@shruthi8
Copy link

shruthi8 commented Aug 6, 2021

Works if I declare the variable as an extern as follows.


/* changes  */
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,11,0)
extern int system_max_semaphore_count;
#else
int system_max_semaphore_count=0;
#endif

```

@luis-novoa
Copy link

I'm running into this in the Alpine-based Ruby Docker containers. On Alpine 3.12 (gcc 9.3.0) I can install Semian, but on Alpine 3.13 (gcc 10.2.1) I can't:

$ docker run --rm ruby:2.7.2-alpine3.12 sh -c 'apk add build-base openssl-dev && gem install semian --version 0.11.3'
fetch http://dl-cdn.alpinelinux.org/alpine/v3.12/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.12/community/x86_64/APKINDEX.tar.gz
(1/20) Upgrading libcrypto1.1 (1.1.1i-r0 -> 1.1.1j-r0)
(2/20) Upgrading libssl1.1 (1.1.1i-r0 -> 1.1.1j-r0)
(3/20) Installing binutils (2.34-r1)
(4/20) Installing libmagic (5.38-r0)
(5/20) Installing file (5.38-r0)
(6/20) Installing isl (0.18-r0)
(7/20) Installing libgomp (9.3.0-r2)
(8/20) Installing libatomic (9.3.0-r2)
(9/20) Installing libgphobos (9.3.0-r2)
(10/20) Installing mpfr4 (4.0.2-r4)
(11/20) Installing mpc1 (1.1.0-r1)
(12/20) Installing gcc (9.3.0-r2)
(13/20) Installing musl-dev (1.1.24-r10)
(14/20) Installing libc-dev (0.7.2-r3)
(15/20) Installing g++ (9.3.0-r2)
(16/20) Installing make (4.3-r0)
(17/20) Installing fortify-headers (1.1-r0)
(18/20) Installing patch (2.7.6-r6)
(19/20) Installing build-base (0.5-r2)
(20/20) Installing openssl-dev (1.1.1j-r0)
Executing busybox-1.31.1-r19.trigger
Executing ca-certificates-20191127-r4.trigger
OK: 219 MiB in 54 packages
Building native extensions. This could take a while...
Successfully installed semian-0.11.3
1 gem installed

$ docker run --rm ruby:2.7.2-alpine3.13 sh -c 'apk add build-base openssl-dev && gem install semian --version 0.11.3'
fetch https://dl-cdn.alpinelinux.org/alpine/v3.13/main/x86_64/APKINDEX.tar.gz
fetch https://dl-cdn.alpinelinux.org/alpine/v3.13/community/x86_64/APKINDEX.tar.gz
(1/18) Installing binutils (2.35.1-r1)
(2/18) Installing libmagic (5.39-r0)
(3/18) Installing file (5.39-r0)
(4/18) Installing libgomp (10.2.1_pre1-r3)
(5/18) Installing libatomic (10.2.1_pre1-r3)
(6/18) Installing libgphobos (10.2.1_pre1-r3)
(7/18) Installing isl22 (0.22-r0)
(8/18) Installing mpfr4 (4.1.0-r0)
(9/18) Installing mpc1 (1.2.0-r0)
(10/18) Installing gcc (10.2.1_pre1-r3)
(11/18) Installing musl-dev (1.2.2-r0)
(12/18) Installing libc-dev (0.7.2-r3)
(13/18) Installing g++ (10.2.1_pre1-r3)
(14/18) Installing make (4.3-r0)
(15/18) Installing fortify-headers (1.1-r0)
(16/18) Installing patch (2.7.6-r6)
(17/18) Installing build-base (0.5-r2)
(18/18) Installing openssl-dev (1.1.1j-r0)
Executing busybox-1.32.1-r3.trigger
OK: 209 MiB in 54 packages
Building native extensions. This could take a while...
ERROR:  Error installing semian:
	ERROR: Failed to build gem native extension.

    current directory: /usr/local/bundle/gems/semian-0.11.3/ext/semian
/usr/local/bin/ruby -I /usr/local/lib/ruby/2.7.0 -r ./siteconf20210218-1-1wb9nhd.rb extconf.rb
checking for openssl/sha.h... yes
checking for SHA1() in -lcrypto... yes
checking for sys/ipc.h... yes
checking for sys/sem.h... yes
checking for sys/types.h... yes
checking for rb_thread_blocking_region()... no
checking for rb_thread_call_without_gvl()... yes
creating Makefile

current directory: /usr/local/bundle/gems/semian-0.11.3/ext/semian
make "DESTDIR=" clean

current directory: /usr/local/bundle/gems/semian-0.11.3/ext/semian
make "DESTDIR="
compiling resource.c
compiling semian.c
compiling sysv_semaphores.c
compiling tickets.c
linking shared-object semian/semian.so
/usr/lib/gcc/x86_64-alpine-linux-musl/10.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: semian.o:(.bss+0x28): multiple definition of `id_wait_time'; resource.o:(.bss+0x10): first defined here
/usr/lib/gcc/x86_64-alpine-linux-musl/10.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: semian.o:(.bss+0x20): multiple definition of `id_timeout'; resource.o:(.bss+0x8): first defined here
/usr/lib/gcc/x86_64-alpine-linux-musl/10.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: semian.o:(.bss+0x18): multiple definition of `system_max_semaphore_count'; resource.o:(.bss+0x0): first defined here
collect2: error: ld returned 1 exit status
make: *** [Makefile:262: semian.so] Error 1

make failed, exit code 2

Gem files will remain installed in /usr/local/bundle/gems/semian-0.11.3 for inspection.
Results logged to /usr/local/bundle/extensions/x86_64-linux-musl/2.7.0/semian-0.11.3/gem_make.out

@haines I now this is a super old issue, but your reply gave me a hint on why I was having problems installing the semian gem. I believe it's also why you had different results on your dockers. For version 0.10.6, I had to revert gcc and g++ back to version 9 (by default, it was 11). So yeah, that's the fix for that specific version (if anyone needs it. I'm even writing this for myself in the future, just in case!!)

@haines
Copy link
Contributor

haines commented Feb 17, 2022

Glad this helped @luis-novoa! Note that if you can upgrade semian to 0.11.4+, it should compile fine with gcc 10+.

@RobertoPatino1
Copy link

This seems to be an issue with the newer versions of gcc. In my case this error appeared while running a project on a docker container (Alpine image). However it did not appear when i ran the same project on my regular wsl (Ubuntu).
As mentioned before, might be an issue with the most recent versions of gcc.
What fixed it for me was adding the "extern" keyword to the global variables that presented the issue.
Hope this helps!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants