[needs,more,eyes] Relink also libopcodes and libgprofng to newly built libiberty.a

Message ID 20230228224937.3832887-1-dilfridge@gentoo.org
State Accepted
Headers
Series [needs,more,eyes] Relink also libopcodes and libgprofng to newly built libiberty.a |

Checks

Context Check Description
snail/binutils-gdb-check success Github commit url

Commit Message

Andreas K. Huettel Feb. 28, 2023, 10:49 p.m. UTC
  For Gentoo users, after updating gcc, a subsequent build of
binutils can fail during "make install" with the following symptoms:

lto1: fatal error: bytecode stream in file '/usr/lib64/binutils/x86_64-pc-linux-gnu/2.37_p1/libiberty.a' generated with LTO version 11.0 instead of the expected 11.2
compilation terminated.

The relink command picks up the installed version of libiberty.a
instead of the just built one. This commit addresses the issue by
replicating the workaround made in 7d53105d for libctf also for
libopcodes and libgprofng.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29042
Bug: https://bugs.gentoo.org/834720
Signed-off-by: Andreas K. Hüttel <dilfridge@gentoo.org>
---
 gprofng/src/Makefile.am | 3 ++-
 gprofng/src/Makefile.in | 3 ++-
 opcodes/configure       | 4 ++--
 opcodes/configure.ac    | 4 ++--
 4 files changed, 8 insertions(+), 6 deletions(-)
  

Comments

Jan Beulich March 1, 2023, 8:29 a.m. UTC | #1
On 28.02.2023 23:49, Andreas K. Hüttel via Binutils wrote:
> For Gentoo users, after updating gcc, a subsequent build of
> binutils can fail during "make install" with the following symptoms:
> 
> lto1: fatal error: bytecode stream in file '/usr/lib64/binutils/x86_64-pc-linux-gnu/2.37_p1/libiberty.a' generated with LTO version 11.0 instead of the expected 11.2
> compilation terminated.
> 
> The relink command picks up the installed version of libiberty.a
> instead of the just built one. This commit addresses the issue by
> replicating the workaround made in 7d53105d for libctf also for
> libopcodes and libgprofng.
> 
> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29042
> Bug: https://bugs.gentoo.org/834720
> Signed-off-by: Andreas K. Hüttel <dilfridge@gentoo.org>

Looks largely okay to me, but please add comments along the lines of the
one found in libctf/Makefile.am.

I'm not going to ask ...

> ---
>  gprofng/src/Makefile.am | 3 ++-
>  gprofng/src/Makefile.in | 3 ++-
>  opcodes/configure       | 4 ++--
>  opcodes/configure.ac    | 4 ++--
>  4 files changed, 8 insertions(+), 6 deletions(-)

... why libopcodes handles this in configure rather than in Makefile, as
that's a pre-existing (apparent) oddity.

Jan
  
Vladimir Mezentsev March 1, 2023, 10:17 p.m. UTC | #2
Hi Andreas,

  Your fix fixes gprofng bug 29987 - bfd/archive.c:1447: undefined 
reference to `filename_ncmp' 
<https://sourceware.org/bugzilla/show_bug.cgi?id=29987>

  But It is a workaround of problem.
I think the problem is in the libbfd build.

% ../binutils-gdb.git/configure --with-system-zlib 
--with-system-readline --enable-default-hash-style=gnu --enable-gold 
--without-guile 
--disable-{gdb,gdbserver,libbacktrace,libdecnumber,readline,sim}
% make -j 20 2>&1 | tee make.log

% grep 'skipping incompatible' make.log
/usr/local/bin/ld: skipping incompatible /usr/lib/libz.so when searching 
for -lz
/usr/local/bin/ld: skipping incompatible /usr/lib/libdl.so when 
searching for -ldl
/usr/local/bin/ld: skipping incompatible /usr/lib/libc.so when searching 
for -lc
/usr/local/bin/ld: skipping incompatible /usr/lib/libz.so when searching 
for -lz
/usr/local/bin/ld: skipping incompatible /usr/lib/libm.so when searching 
for -lm
...

We see these warnings because libtool added -L/usr/lib

% grep L/usr/lib make.log
libtool: link: g++ -Wall -pthread -Wno-switch -g -O2 -o gp-archive 
gp-archive.o ArchiveExp.o  ./.libs/libgprofng.a 
-L/dev/shm/bld-binutils-gdb/libiberty -L/usr/lib 
/dev/shm/bld-binutils-gdb/opcodes/.libs/libopcodes.a 
/dev/shm/bld-binutils-gdb/bfd/.libs/libbfd.a -lzstd 
/dev/shm/bld-binutils-gdb/libsframe/.libs/libsframe.a -liberty -lpthread 
-ldl -lz -pthread
libtool: link: g++ -Wall -pthread -Wno-switch -g -O2 -o gp-collect-app 
gp-collect-app.o checks.o envsets.o count.o ./.libs/libgprofng.a 
-L/dev/shm/bld-binutils-gdb/libiberty -L/usr/lib 
/dev/shm/bld-binutils-gdb/opcodes/.libs/libopcodes.a 
/dev/shm/bld-binutils-gdb/bfd/.libs/libbfd.a -lzstd 
/dev/shm/bld-binutils-gdb/libsframe/.libs/libsframe.a -liberty -lpthread 
-ldl -lz -pthread
libtool: link: g++ -Wall -pthread -Wno-switch -g -O2 -o gprofng 
gprofng.o  ./.libs/libgprofng.a -L/dev/shm/bld-binutils-gdb/libiberty 
-L/usr/lib /dev/shm/bld-binutils-gdb/opcodes/.libs/libopcodes.a 
/dev/shm/bld-binutils-gdb/bfd/.libs/libbfd.a -lzstd 
/dev/shm/bld-binutils-gdb/libsframe/.libs/libsframe.a -liberty -lpthread 
-ldl -lz -pthread
libtool: link: g++ -Wall -pthread -Wno-switch -g -O2 -o gp-display-text 
gp-display-text.o ipc.o ipcio.o ./.libs/libgprofng.a 
-L/dev/shm/bld-binutils-gdb/libiberty -L/usr/lib 
/dev/shm/bld-binutils-gdb/opcodes/.libs/libopcodes.a 
/dev/shm/bld-binutils-gdb/bfd/.libs/libbfd.a -lzstd 
/dev/shm/bld-binutils-gdb/libsframe/.libs/libsframe.a -liberty -lpthread 
-ldl -lz -pthread
libtool: link: g++ -Wall -pthread -Wno-switch -g -O2 -o gp-display-src 
gp-display-src.o  ./.libs/libgprofng.a 
-L/dev/shm/bld-binutils-gdb/libiberty -L/usr/lib 
/dev/shm/bld-binutils-gdb/opcodes/.libs/libopcodes.a 
/dev/shm/bld-binutils-gdb/bfd/.libs/libbfd.a -lzstd 
/dev/shm/bld-binutils-gdb/libsframe/.libs/libsframe.a -liberty -lpthread 
-ldl -lz -pthread

I think libtool added -L/usr/lib because gprofng and libsframe are 
linked with bfd/libbfd.la and
libbfd.la has a wrong dependency:

% grep L/usr/lib bfd/libbfd.la
dependency_libs=' -lz -L/usr/lib -lzstd 
/dev/shm/bld-binutils-gdb/libsframe/libsframe.la -ldl'

-L/usr/lib should not be here.
It can be -L/usr/lib64 but not -L/usr/lib in the 64-bit build.

Thank you,
-Vladimir




On 2/28/23 14:49, Andreas K. Hüttel via Binutils wrote:
> For Gentoo users, after updating gcc, a subsequent build of
> binutils can fail during "make install" with the following symptoms:
>
> lto1: fatal error: bytecode stream in file '/usr/lib64/binutils/x86_64-pc-linux-gnu/2.37_p1/libiberty.a' generated with LTO version 11.0 instead of the expected 11.2
> compilation terminated.
>
> The relink command picks up the installed version of libiberty.a
> instead of the just built one. This commit addresses the issue by
> replicating the workaround made in 7d53105d for libctf also for
> libopcodes and libgprofng.
>
> Bug:https://sourceware.org/bugzilla/show_bug.cgi?id=29042
> Bug:https://bugs.gentoo.org/834720
> Signed-off-by: Andreas K. Hüttel<dilfridge@gentoo.org>
> ---
>   gprofng/src/Makefile.am | 3 ++-
>   gprofng/src/Makefile.in | 3 ++-
>   opcodes/configure       | 4 ++--
>   opcodes/configure.ac    | 4 ++--
>   4 files changed, 8 insertions(+), 6 deletions(-)
>
> diff --git a/gprofng/src/Makefile.am b/gprofng/src/Makefile.am
> index ab90bb08c5f..96256faf788 100644
> --- a/gprofng/src/Makefile.am
> +++ b/gprofng/src/Makefile.am
> @@ -131,7 +131,8 @@ libgprofng_la_LDFLAGS = -version-info 0:0:0
>   # Pass -lpthread instead of $(PTHREAD_LIBS) due to $(PTHREAD_LIBS) being empty
>   # when -nostdlib is passed to libtool.
>   # See bug 29364 - libgprofng.so: needs to link against -pthread
> -libgprofng_la_LIBADD = $(top_builddir)/../opcodes/libopcodes.la \
> +libgprofng_la_LIBADD = $(GPROFNG_LIBADD) \
> +	$(top_builddir)/../opcodes/libopcodes.la \
>   	$(top_builddir)/../bfd/libbfd.la \
>   	$(GPROFNG_LIBADD) \
>   	-lpthread -ldl
> diff --git a/gprofng/src/Makefile.in b/gprofng/src/Makefile.in
> index 605fa4f6fd4..f968d8d6e59 100644
> --- a/gprofng/src/Makefile.in
> +++ b/gprofng/src/Makefile.in
> @@ -555,7 +555,8 @@ libgprofng_la_LDFLAGS = -version-info 0:0:0
>   # Pass -lpthread instead of $(PTHREAD_LIBS) due to $(PTHREAD_LIBS) being empty
>   # when -nostdlib is passed to libtool.
>   # See bug 29364 - libgprofng.so: needs to link against -pthread
> -libgprofng_la_LIBADD = $(top_builddir)/../opcodes/libopcodes.la \
> +libgprofng_la_LIBADD = $(GPROFNG_LIBADD) \
> +	$(top_builddir)/../opcodes/libopcodes.la \
>   	$(top_builddir)/../bfd/libbfd.la \
>   	$(GPROFNG_LIBADD) \
>   	-lpthread -ldl
> diff --git a/opcodes/configure b/opcodes/configure
> index 8717d99ca26..fbdf41f87be 100755
> --- a/opcodes/configure
> +++ b/opcodes/configure
> @@ -12445,10 +12445,10 @@ if test "$enable_shared" = "yes"; then
>     case "${host}" in
>       *-*-cygwin*)
>         SHARED_LDFLAGS="-no-undefined"
> -      SHARED_LIBADD="-L`pwd`/../bfd -lbfd -L`pwd`/../libiberty -liberty $SHARED_LIBADD"
> +      SHARED_LIBADD="$SHARED_LIBADD -L`pwd`/../bfd -lbfd -L`pwd`/../libiberty -liberty $SHARED_LIBADD"
>         ;;
>       *)
> -      SHARED_LIBADD="../bfd/libbfd.la ${SHARED_LIBADD}"
> +      SHARED_LIBADD="${SHARED_LIBADD} ../bfd/libbfd.la ${SHARED_LIBADD}"
>         SHARED_DEPENDENCIES="../bfd/libbfd.la"
>         ;;
>     esac
> diff --git a/opcodes/configure.ac b/opcodes/configure.ac
> index 1beb72e87e0..79310916f7d 100644
> --- a/opcodes/configure.ac
> +++ b/opcodes/configure.ac
> @@ -193,10 +193,10 @@ if test "$enable_shared" = "yes"; then
>     case "${host}" in
>       *-*-cygwin*)
>         SHARED_LDFLAGS="-no-undefined"
> -      SHARED_LIBADD="-L`pwd`/../bfd -lbfd -L`pwd`/../libiberty -liberty $SHARED_LIBADD"
> +      SHARED_LIBADD="$SHARED_LIBADD -L`pwd`/../bfd -lbfd -L`pwd`/../libiberty -liberty $SHARED_LIBADD"
>         ;;
>       *)
> -      SHARED_LIBADD="../bfd/libbfd.la ${SHARED_LIBADD}"
> +      SHARED_LIBADD="${SHARED_LIBADD} ../bfd/libbfd.la ${SHARED_LIBADD}"
>         SHARED_DEPENDENCIES="../bfd/libbfd.la"
>         ;;
>     esac
  
Alan Modra March 2, 2023, 5:11 a.m. UTC | #3
On Wed, Mar 01, 2023 at 02:17:54PM -0800, Vladimir Mezentsev via Binutils wrote:
> I think libtool added -L/usr/lib because gprofng and libsframe are linked
> with bfd/libbfd.la and
> libbfd.la has a wrong dependency:
> 
> % grep L/usr/lib bfd/libbfd.la
> dependency_libs=' -lz -L/usr/lib -lzstd
> /dev/shm/bld-binutils-gdb/libsframe/libsframe.la -ldl'

Hmm, I used exactly the same configure line as you did, and I don't
see any -L in libbfd.la dependency_libs.  Built on x86_64-linux-gnu
running Ubuntu 22.04.
$ find /usr/lib -name libzstd\*
/usr/lib/i386-linux-gnu/libzstd.so.1
/usr/lib/i386-linux-gnu/libzstd.so.1.4.8
/usr/lib/x86_64-linux-gnu/libzstd.so
/usr/lib/x86_64-linux-gnu/libzstd.so.1
/usr/lib/x86_64-linux-gnu/libzstd.a
/usr/lib/x86_64-linux-gnu/pkgconfig/libzstd.pc
/usr/lib/x86_64-linux-gnu/libzstd.so.1.4.8
  
Vladimir Mezentsev March 2, 2023, 8:10 a.m. UTC | #4
On 3/1/23 21:11, Alan Modra wrote:
> On Wed, Mar 01, 2023 at 02:17:54PM -0800, Vladimir Mezentsev via Binutils wrote:
>> I think libtool added -L/usr/lib because gprofng and libsframe are linked
>> with bfd/libbfd.la and
>> libbfd.la has a wrong dependency:
>>
>> % grep L/usr/lib bfd/libbfd.la
>> dependency_libs=' -lz -L/usr/lib -lzstd
>> /dev/shm/bld-binutils-gdb/libsframe/libsframe.la -ldl'
> Hmm, I used exactly the same configure line as you did, and I don't
> see any -L in libbfd.la dependency_libs.  Built on x86_64-linux-gnu
> running Ubuntu 22.04.

  I build on OL8.

grep dependency_libs in <your_build_area>/bfd/libbfd.la.
It is a problem in my build.

> $ find /usr/lib -name libzstd\*

  Why do you try to find it ?
I wrote about build area.

> /usr/lib/i386-linux-gnu/libzstd.so.1
> /usr/lib/i386-linux-gnu/libzstd.so.1.4.8
> /usr/lib/x86_64-linux-gnu/libzstd.so
> /usr/lib/x86_64-linux-gnu/libzstd.so.1
> /usr/lib/x86_64-linux-gnu/libzstd.a
> /usr/lib/x86_64-linux-gnu/pkgconfig/libzstd.pc
> /usr/lib/x86_64-linux-gnu/libzstd.so.1.4.8
>
  
Alan Modra March 2, 2023, 9:27 a.m. UTC | #5
On Thu, Mar 02, 2023 at 12:10:52AM -0800, Vladimir Mezentsev wrote:
> 
> 
> On 3/1/23 21:11, Alan Modra wrote:
> > On Wed, Mar 01, 2023 at 02:17:54PM -0800, Vladimir Mezentsev via Binutils wrote:
> > > I think libtool added -L/usr/lib because gprofng and libsframe are linked
> > > with bfd/libbfd.la and
> > > libbfd.la has a wrong dependency:
> > > 
> > > % grep L/usr/lib bfd/libbfd.la
> > > dependency_libs=' -lz -L/usr/lib -lzstd
> > > /dev/shm/bld-binutils-gdb/libsframe/libsframe.la -ldl'
> > Hmm, I used exactly the same configure line as you did, and I don't
> > see any -L in libbfd.la dependency_libs.  Built on x86_64-linux-gnu
> > running Ubuntu 22.04.
> 
>  I build on OL8.
> 
> grep dependency_libs in <your_build_area>/bfd/libbfd.la.
> It is a problem in my build.
> 
> > $ find /usr/lib -name libzstd\*
> 
>  Why do you try to find it ?
> I wrote about build area.

To show you that I had both .a and .so for -lzstd.  I'm assuming that
since -L/usr/lib comes before -lzstd in your dependency_libs that it
might be something to do with libzstd.

> > /usr/lib/i386-linux-gnu/libzstd.so.1
> > /usr/lib/i386-linux-gnu/libzstd.so.1.4.8
> > /usr/lib/x86_64-linux-gnu/libzstd.so
> > /usr/lib/x86_64-linux-gnu/libzstd.so.1
> > /usr/lib/x86_64-linux-gnu/libzstd.a
> > /usr/lib/x86_64-linux-gnu/pkgconfig/libzstd.pc
> > /usr/lib/x86_64-linux-gnu/libzstd.so.1.4.8
> >
  
Andreas K. Huettel March 15, 2023, 8:51 p.m. UTC | #6
Big apology for the silence, a heap of unrelated work got in the way.
I'll respond in a few days when the worst is over.. :|

FWIW, I got several confirmations in the meantime that the patch solves
our problem in Gentoo ...

Am Dienstag, 28. Februar 2023, 23:49:37 CET schrieb Andreas K. Hüttel:
> For Gentoo users, after updating gcc, a subsequent build of
> binutils can fail during "make install" with the following symptoms:
> 
> lto1: fatal error: bytecode stream in file '/usr/lib64/binutils/x86_64-pc-linux-gnu/2.37_p1/libiberty.a' generated with LTO version 11.0 instead of the expected 11.2
> compilation terminated.
> 
> The relink command picks up the installed version of libiberty.a
> instead of the just built one. This commit addresses the issue by
> replicating the workaround made in 7d53105d for libctf also for
> libopcodes and libgprofng.
> 
> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29042
> Bug: https://bugs.gentoo.org/834720
> Signed-off-by: Andreas K. Hüttel <dilfridge@gentoo.org>
> ---
>  gprofng/src/Makefile.am | 3 ++-
>  gprofng/src/Makefile.in | 3 ++-
>  opcodes/configure       | 4 ++--
>  opcodes/configure.ac    | 4 ++--
>  4 files changed, 8 insertions(+), 6 deletions(-)
> 
> diff --git a/gprofng/src/Makefile.am b/gprofng/src/Makefile.am
> index ab90bb08c5f..96256faf788 100644
> --- a/gprofng/src/Makefile.am
> +++ b/gprofng/src/Makefile.am
> @@ -131,7 +131,8 @@ libgprofng_la_LDFLAGS = -version-info 0:0:0
>  # Pass -lpthread instead of $(PTHREAD_LIBS) due to $(PTHREAD_LIBS) being empty
>  # when -nostdlib is passed to libtool.
>  # See bug 29364 - libgprofng.so: needs to link against -pthread
> -libgprofng_la_LIBADD = $(top_builddir)/../opcodes/libopcodes.la \
> +libgprofng_la_LIBADD = $(GPROFNG_LIBADD) \
> +	$(top_builddir)/../opcodes/libopcodes.la \
>  	$(top_builddir)/../bfd/libbfd.la \
>  	$(GPROFNG_LIBADD) \
>  	-lpthread -ldl
> diff --git a/gprofng/src/Makefile.in b/gprofng/src/Makefile.in
> index 605fa4f6fd4..f968d8d6e59 100644
> --- a/gprofng/src/Makefile.in
> +++ b/gprofng/src/Makefile.in
> @@ -555,7 +555,8 @@ libgprofng_la_LDFLAGS = -version-info 0:0:0
>  # Pass -lpthread instead of $(PTHREAD_LIBS) due to $(PTHREAD_LIBS) being empty
>  # when -nostdlib is passed to libtool.
>  # See bug 29364 - libgprofng.so: needs to link against -pthread
> -libgprofng_la_LIBADD = $(top_builddir)/../opcodes/libopcodes.la \
> +libgprofng_la_LIBADD = $(GPROFNG_LIBADD) \
> +	$(top_builddir)/../opcodes/libopcodes.la \
>  	$(top_builddir)/../bfd/libbfd.la \
>  	$(GPROFNG_LIBADD) \
>  	-lpthread -ldl
> diff --git a/opcodes/configure b/opcodes/configure
> index 8717d99ca26..fbdf41f87be 100755
> --- a/opcodes/configure
> +++ b/opcodes/configure
> @@ -12445,10 +12445,10 @@ if test "$enable_shared" = "yes"; then
>    case "${host}" in
>      *-*-cygwin*)
>        SHARED_LDFLAGS="-no-undefined"
> -      SHARED_LIBADD="-L`pwd`/../bfd -lbfd -L`pwd`/../libiberty -liberty $SHARED_LIBADD"
> +      SHARED_LIBADD="$SHARED_LIBADD -L`pwd`/../bfd -lbfd -L`pwd`/../libiberty -liberty $SHARED_LIBADD"
>        ;;
>      *)
> -      SHARED_LIBADD="../bfd/libbfd.la ${SHARED_LIBADD}"
> +      SHARED_LIBADD="${SHARED_LIBADD} ../bfd/libbfd.la ${SHARED_LIBADD}"
>        SHARED_DEPENDENCIES="../bfd/libbfd.la"
>        ;;
>    esac
> diff --git a/opcodes/configure.ac b/opcodes/configure.ac
> index 1beb72e87e0..79310916f7d 100644
> --- a/opcodes/configure.ac
> +++ b/opcodes/configure.ac
> @@ -193,10 +193,10 @@ if test "$enable_shared" = "yes"; then
>    case "${host}" in
>      *-*-cygwin*)
>        SHARED_LDFLAGS="-no-undefined"
> -      SHARED_LIBADD="-L`pwd`/../bfd -lbfd -L`pwd`/../libiberty -liberty $SHARED_LIBADD"
> +      SHARED_LIBADD="$SHARED_LIBADD -L`pwd`/../bfd -lbfd -L`pwd`/../libiberty -liberty $SHARED_LIBADD"
>        ;;
>      *)
> -      SHARED_LIBADD="../bfd/libbfd.la ${SHARED_LIBADD}"
> +      SHARED_LIBADD="${SHARED_LIBADD} ../bfd/libbfd.la ${SHARED_LIBADD}"
>        SHARED_DEPENDENCIES="../bfd/libbfd.la"
>        ;;
>    esac
>
  

Patch

diff --git a/gprofng/src/Makefile.am b/gprofng/src/Makefile.am
index ab90bb08c5f..96256faf788 100644
--- a/gprofng/src/Makefile.am
+++ b/gprofng/src/Makefile.am
@@ -131,7 +131,8 @@  libgprofng_la_LDFLAGS = -version-info 0:0:0
 # Pass -lpthread instead of $(PTHREAD_LIBS) due to $(PTHREAD_LIBS) being empty
 # when -nostdlib is passed to libtool.
 # See bug 29364 - libgprofng.so: needs to link against -pthread
-libgprofng_la_LIBADD = $(top_builddir)/../opcodes/libopcodes.la \
+libgprofng_la_LIBADD = $(GPROFNG_LIBADD) \
+	$(top_builddir)/../opcodes/libopcodes.la \
 	$(top_builddir)/../bfd/libbfd.la \
 	$(GPROFNG_LIBADD) \
 	-lpthread -ldl
diff --git a/gprofng/src/Makefile.in b/gprofng/src/Makefile.in
index 605fa4f6fd4..f968d8d6e59 100644
--- a/gprofng/src/Makefile.in
+++ b/gprofng/src/Makefile.in
@@ -555,7 +555,8 @@  libgprofng_la_LDFLAGS = -version-info 0:0:0
 # Pass -lpthread instead of $(PTHREAD_LIBS) due to $(PTHREAD_LIBS) being empty
 # when -nostdlib is passed to libtool.
 # See bug 29364 - libgprofng.so: needs to link against -pthread
-libgprofng_la_LIBADD = $(top_builddir)/../opcodes/libopcodes.la \
+libgprofng_la_LIBADD = $(GPROFNG_LIBADD) \
+	$(top_builddir)/../opcodes/libopcodes.la \
 	$(top_builddir)/../bfd/libbfd.la \
 	$(GPROFNG_LIBADD) \
 	-lpthread -ldl
diff --git a/opcodes/configure b/opcodes/configure
index 8717d99ca26..fbdf41f87be 100755
--- a/opcodes/configure
+++ b/opcodes/configure
@@ -12445,10 +12445,10 @@  if test "$enable_shared" = "yes"; then
   case "${host}" in
     *-*-cygwin*)
       SHARED_LDFLAGS="-no-undefined"
-      SHARED_LIBADD="-L`pwd`/../bfd -lbfd -L`pwd`/../libiberty -liberty $SHARED_LIBADD"
+      SHARED_LIBADD="$SHARED_LIBADD -L`pwd`/../bfd -lbfd -L`pwd`/../libiberty -liberty $SHARED_LIBADD"
       ;;
     *)
-      SHARED_LIBADD="../bfd/libbfd.la ${SHARED_LIBADD}"
+      SHARED_LIBADD="${SHARED_LIBADD} ../bfd/libbfd.la ${SHARED_LIBADD}"
       SHARED_DEPENDENCIES="../bfd/libbfd.la"
       ;;
   esac
diff --git a/opcodes/configure.ac b/opcodes/configure.ac
index 1beb72e87e0..79310916f7d 100644
--- a/opcodes/configure.ac
+++ b/opcodes/configure.ac
@@ -193,10 +193,10 @@  if test "$enable_shared" = "yes"; then
   case "${host}" in
     *-*-cygwin*)
       SHARED_LDFLAGS="-no-undefined"
-      SHARED_LIBADD="-L`pwd`/../bfd -lbfd -L`pwd`/../libiberty -liberty $SHARED_LIBADD"
+      SHARED_LIBADD="$SHARED_LIBADD -L`pwd`/../bfd -lbfd -L`pwd`/../libiberty -liberty $SHARED_LIBADD"
       ;;
     *)
-      SHARED_LIBADD="../bfd/libbfd.la ${SHARED_LIBADD}"
+      SHARED_LIBADD="${SHARED_LIBADD} ../bfd/libbfd.la ${SHARED_LIBADD}"
       SHARED_DEPENDENCIES="../bfd/libbfd.la"
       ;;
   esac