[PATCH] {md5,sha1,sha256,sha512,sm3}-stream: avoid duplicate symbols
when building with openssl *_init_ctx and other inline symbols are supposed to be provided by non *-stream compilation units so drop extern from *-stream c files. Fixes linking ie: mold: error: duplicate symbol: ../lib/.libs/libgnu.a(libgnu_la-md5.o): ../lib/.libs/libgnu.a(libgnu_la-md5-stream.o): md5_init_ctx mold: error: duplicate symbol: ../lib/.libs/libgnu.a(libgnu_la-md5.o): ../lib/.libs/libgnu.a(libgnu_la-md5-stream.o): md5_process_bytes mold: error: duplicate symbol: ../lib/.libs/libgnu.a(libgnu_la-md5.o): ../lib/.libs/libgnu.a(libgnu_la-md5-stream.o): md5_process_block mold: error: duplicate symbol: ../lib/.libs/libgnu.a(libgnu_la-md5.o): ../lib/.libs/libgnu.a(libgnu_la-md5-stream.o): md5_finish_ctx mold: error: duplicate symbol: ../lib/.libs/libgnu.a(libgnu_la-md5.o): ../lib/.libs/libgnu.a(libgnu_la-md5-stream.o): md5_buffer mold: error: duplicate symbol: ../lib/.libs/libgnu.a(libgnu_la-md5.o): ../lib/.libs/libgnu.a(libgnu_la-md5-stream.o): md5_read_ctx Fixes: 439979c000 ("md5: Clarify module to source relation.") Fixes: ecf145d277 ("sha1: Clarify module to source relation.") Fixes: 36cd6e0a4e ("sha256: Clarify module to source relation.") Fixes: 2b6d343ff9 ("sha512: Clarify module to source relation.") Fixes: 81ca30b0de ("sm3-buffer: New module.") Signed-off-by: Jan Palus --- lib/md5-stream.c| 3 --- lib/sha1-stream.c | 3 --- lib/sha256-stream.c | 3 --- lib/sha512-stream.c | 3 --- lib/sm3-stream.c| 3 --- 5 files changed, 15 deletions(-) diff --git a/lib/md5-stream.c b/lib/md5-stream.c index fdd2bd8b4b..2cbdda6b0f 100644 --- a/lib/md5-stream.c +++ b/lib/md5-stream.c @@ -22,9 +22,6 @@ #include /* Specification. */ -#if HAVE_OPENSSL_MD5 -# define GL_OPENSSL_INLINE _GL_EXTERN_INLINE -#endif #include "md5.h" #include diff --git a/lib/sha1-stream.c b/lib/sha1-stream.c index cbdf95ab76..b713e678a6 100644 --- a/lib/sha1-stream.c +++ b/lib/sha1-stream.c @@ -24,9 +24,6 @@ #include /* Specification. */ -#if HAVE_OPENSSL_SHA1 -# define GL_OPENSSL_INLINE _GL_EXTERN_INLINE -#endif #include "sha1.h" #include diff --git a/lib/sha256-stream.c b/lib/sha256-stream.c index 690ca967dd..82abc2c8af 100644 --- a/lib/sha256-stream.c +++ b/lib/sha256-stream.c @@ -23,9 +23,6 @@ #include /* Specification. */ -#if HAVE_OPENSSL_SHA256 -# define GL_OPENSSL_INLINE _GL_EXTERN_INLINE -#endif #include "sha256.h" #include diff --git a/lib/sha512-stream.c b/lib/sha512-stream.c index 74fdd5047d..6362e55a6a 100644 --- a/lib/sha512-stream.c +++ b/lib/sha512-stream.c @@ -23,9 +23,6 @@ #include /* Specification. */ -#if HAVE_OPENSSL_SHA512 -# define GL_OPENSSL_INLINE _GL_EXTERN_INLINE -#endif #include "sha512.h" #include diff --git a/lib/sm3-stream.c b/lib/sm3-stream.c index f9ed05a944..2a96fd734e 100644 --- a/lib/sm3-stream.c +++ b/lib/sm3-stream.c @@ -26,9 +26,6 @@ #include /* Specification. */ -#if HAVE_OPENSSL_SM3 -# define GL_OPENSSL_INLINE _GL_EXTERN_INLINE -#endif #include "sm3.h" #include -- 2.47.0
Re: [PATCH] {md5,sha1,sha256,sha512,sm3}-stream: avoid duplicate symbols
On 17.11.2024 15:53, Bruno Haible wrote: > Jan Palus wrote: > > Fixes linking ie: > > mold: error: duplicate symbol: ../lib/.libs/libgnu.a(libgnu_la-md5.o): > > ../lib/.libs/libgnu.a(libgnu_la-md5-stream.o): md5_init_ctx > > How to reproduce the problem? > 1) Which package did you build? > 2) On which platform? > 3) With which values for CC, CPPFLAGS, CFLAGS, LDFLAGS? > 4) With which configure options? > 5) Do you get the same link error also when using GNU ld instead of 'mold'? The error was spotted when building lftp on Linux which uses -Wl,--whole-archive that appears to trigger the behavior. I was able to reproduce it with just gnulib: cd gnulib ./gnulib-tool --create-testdir --dir=build crypto/md5 cd build ./configure --with-openssl=yes make cd gltests GNU ld: $ gcc -fuse-ld=bfd -o test-md5-buffer test-md5-buffer.o -Wl,--whole-archive ../gllib/libgnu.a -Wl,-no-whole-archive -lcrypto /usr/bin/ld.bfd: ../gllib/libgnu.a(md5.o): in function `md5_init_ctx': /.../gnulib/build/gllib/md5.c:81: multiple definition of `md5_init_ctx'; ../gllib/libgnu.a(md5-stream.o):/.../gnulib/build/gllib/md5-stream.c:81: first defined here /usr/bin/ld.bfd: ../gllib/libgnu.a(md5.o): in function `md5_process_bytes': /.../gnulib/build/gllib/md5.c:87: multiple definition of `md5_process_bytes'; ../gllib/libgnu.a(md5-stream.o):/.../gnulib/build/gllib/md5-stream.c:87: first defined here /usr/bin/ld.bfd: ../gllib/libgnu.a(md5.o): in function `md5_process_block': /.../gnulib/build/gllib/md5.c:90: multiple definition of `md5_process_block'; ../gllib/libgnu.a(md5-stream.o):/.../gnulib/build/gllib/md5-stream.c:90: first defined here /usr/bin/ld.bfd: ../gllib/libgnu.a(md5.o): in function `md5_finish_ctx': /.../gnulib/build/gllib/md5.c:96: multiple definition of `md5_finish_ctx'; ../gllib/libgnu.a(md5-stream.o):/.../gnulib/build/gllib/md5-stream.c:96: first defined here /usr/bin/ld.bfd: ../gllib/libgnu.a(md5.o): in function `md5_buffer': /.../gnulib/build/gllib/md5.c:100: multiple definition of `md5_buffer'; ../gllib/libgnu.a(md5-stream.o):/.../gnulib/build/gllib/md5-stream.c:100: first defined here /usr/bin/ld.bfd: ../gllib/libgnu.a(md5.o): in function `md5_read_ctx': /.../gnulib/build/gllib/md5.c:104: multiple definition of `md5_read_ctx'; ../gllib/libgnu.a(md5-stream.o):/.../gnulib/build/gllib/md5-stream.c:104: first defined here collect2: error: ld returned 1 exit status mold: $ gcc -fuse-ld=mold -o test-md5-buffer test-md5-buffer.o -Wl,--whole-archive ../gllib/libgnu.a -Wl,-no-whole-archive -lcrypto mold: error: duplicate symbol: ../gllib/libgnu.a(md5.o): ../gllib/libgnu.a(md5-stream.o): md5_init_ctx mold: error: duplicate symbol: ../gllib/libgnu.a(md5.o): ../gllib/libgnu.a(md5-stream.o): md5_process_bytes mold: error: duplicate symbol: ../gllib/libgnu.a(md5.o): ../gllib/libgnu.a(md5-stream.o): md5_process_block mold: error: duplicate symbol: ../gllib/libgnu.a(md5.o): ../gllib/libgnu.a(md5-stream.o): md5_finish_ctx mold: error: duplicate symbol: ../gllib/libgnu.a(md5.o): ../gllib/libgnu.a(md5-stream.o): md5_buffer mold: error: duplicate symbol: ../gllib/libgnu.a(md5.o): ../gllib/libgnu.a(md5-stream.o): md5_read_ctx collect2: error: ld returned 1 exit status lld: $ gcc -fuse-ld=lld -o test-md5-buffer test-md5-buffer.o -Wl,--whole-archive ../gllib/libgnu.a -Wl,-no-whole-archive -lcrypto ld.lld: error: duplicate symbol: md5_init_ctx >>> defined at gl_openssl.h:81 >>> (/home/users/jan/devel/gnulib/build/gllib/gl_openssl.h:81) >>>md5-stream.o:(md5_init_ctx) in archive ../gllib/libgnu.a >>> defined at gl_openssl.h:81 >>> (/home/users/jan/devel/gnulib/build/gllib/gl_openssl.h:81) >>>md5.o:(.text+0x0) in archive ../gllib/libgnu.a ld.lld: error: duplicate symbol: md5_process_bytes >>> defined at gl_openssl.h:87 >>> (/home/users/jan/devel/gnulib/build/gllib/gl_openssl.h:87) >>>md5-stream.o:(md5_process_bytes) in archive ../gllib/libgnu.a >>> defined at gl_openssl.h:87 >>> (/home/users/jan/devel/gnulib/build/gllib/gl_openssl.h:87) >>>md5.o:(.text+0x4) in archive ../gllib/libgnu.a ld.lld: error: duplicate symbol: md5_process_block >>> defined at gl_openssl.h:90 >>> (/home/users/jan/devel/gnulib/build/gllib/gl_openssl.h:90) >>>md5-stream.o:(md5_process_block) in archive ../gllib/libgnu.a >>> defined at gl_openssl.h:90 >>> (/home/users/jan/devel/gnulib/build/gllib/gl_openssl.h:90) >>>md5.o:(.text+0x20) in archive ../gllib/libgnu.a ld.lld: error: duplicate symbol: md5_finish_ctx >>> defined at gl_openssl.h:96 >>> (/home/users/jan/devel/gnulib/build/gllib/g