fails on the 2.22 branch and trunk, works with ld.gold on both the branch and the trunk. $ cat mpitest.f90 program main include 'mpif.h' integer ierr call mpi_init(ierr) end $ mpif90 -Wl,--as-needed -g mpitest.f90 /usr/bin/ld: /tmp/cc9rtjMR.o(.debug_info+0x493): unresolvable R_X86_64_64 relocation against symbol `mpi_fortran_argv_null_' /usr/bin/ld: /tmp/cc9rtjMR.o(.debug_info+0x4ad): unresolvable R_X86_64_64 relocation against symbol `mpi_fortran_argv_null_' /usr/bin/ld: /tmp/cc9rtjMR.o(.debug_info+0x523): unresolvable R_X86_64_64 relocation against symbol `mpi_fortran_errcodes_ignore_' /usr/bin/ld: /tmp/cc9rtjMR.o(.debug_info+0x53d): unresolvable R_X86_64_64 relocation against symbol `mpi_fortran_errcodes_ignore_' The undefined references to `__libc_csu_(init|fini)' are an artefact in the self-contained testcase.
self-contained test case at http://people.debian.org/~doko/tmp/mpi.tar.xz
Please provide the source of mpitest.o as well as command line used to create mpitest.o.
A small testcase: hjl@gnu-6 pr13250]$ cat foo.c char mpi_fortran_argv_null_[8]; [hjl@gnu-6 pr13250]$ cat bar.c extern char mpi_fortran_argv_null_[8]; int bar () { return mpi_fortran_argv_null_[0]; } [hjl@gnu-6 pr13250]$ cat main.c char mpi_fortran_argv_null_[1]; extern int bar (); int main () { bar (); return 0; } [hjl@gnu-6 pr13250]$ make gcc -g -c -o main.o main.c gcc -shared -fPIC -g -o libfoo.so foo.c gcc -shared -fPIC -g -o libbar.so bar.c libfoo.so gcc -Wl,--as-needed -o x main.o libbar.so libfoo.so -Wl,-rpath,. /usr/local/bin/ld: main.o(.debug_info+0x7e): unresolvable R_X86_64_64 relocation against symbol `mpi_fortran_argv_null_' ./x [hjl@gnu-6 pr13250]$
Created attachment 5963 [details] A patch This patch preserves the maximum alignment and size for common symbols.
the patch fixes the original issue as well.
A patch is posted at http://sourceware.org/ml/binutils/2011-10/msg00035.html
CVSROOT: /cvs/src Module name: src Changes by: hjl@sourceware.org 2011-10-08 16:51:11 Modified files: bfd : ChangeLog elflink.c ld/testsuite : ChangeLog ld/testsuite/ld-elf: shared.exp Added files: ld/testsuite/ld-elf: pr13250-1.c pr13250-2.c pr13250-3.c Log message: Preserve the maximum alignment/size for common symbols. bfd/ 2011-10-08 H.J. Lu <hongjiu.lu@intel.com> PR ld/13250 * elflink.c (elf_link_add_object_symbols): Preserve the maximum alignment and size for common symbols. ld/testsuite/ 2011-10-08 H.J. Lu <hongjiu.lu@intel.com> PR ld/13250 * ld-elf/shared.exp (build_tests): Add tests for PR ld/13250. (run_tests): Likewise. * ld-elf/pr13250-1.c: New. * ld-elf/pr13250-2.c: Likewise. * ld-elf/pr13250-3.c: Likewise. Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/ChangeLog.diff?cvsroot=src&r1=1.5483&r2=1.5484 http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/elflink.c.diff?cvsroot=src&r1=1.424&r2=1.425 http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ChangeLog.diff?cvsroot=src&r1=1.1465&r2=1.1466 http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-elf/pr13250-1.c.diff?cvsroot=src&r1=NONE&r2=1.1 http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-elf/pr13250-2.c.diff?cvsroot=src&r1=NONE&r2=1.1 http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-elf/pr13250-3.c.diff?cvsroot=src&r1=NONE&r2=1.1 http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-elf/shared.exp.diff?cvsroot=src&r1=1.17&r2=1.18
Fixed.
CVSROOT: /cvs/src Module name: src Branch: binutils-2_22-branch Changes by: amodra@sourceware.org 2011-10-25 02:57:24 Modified files: bfd : ChangeLog elflink.c ld/testsuite : ChangeLog ld/testsuite/ld-elf: shared.exp Added files: ld/testsuite/ld-elf: pr13250-1.c pr13250-2.c pr13250-3.c Log message: PR ld/13250 bfd/ 2011-10-08 H.J. Lu <hongjiu.lu@intel.com> * elflink.c (elf_link_add_object_symbols): Preserve the maximum alignment and size for common symbols. ld/testsuite/ 2011-10-08 H.J. Lu <hongjiu.lu@intel.com> * ld-elf/shared.exp (build_tests): Add tests for PR ld/13250. (run_tests): Likewise. * ld-elf/pr13250-1.c: New. * ld-elf/pr13250-2.c: Likewise. * ld-elf/pr13250-3.c: Likewise. Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/ChangeLog.diff?cvsroot=src&only_with_tag=binutils-2_22-branch&r1=1.5473.2.10&r2=1.5473.2.11 http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/elflink.c.diff?cvsroot=src&only_with_tag=binutils-2_22-branch&r1=1.420.2.5&r2=1.420.2.6 http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ChangeLog.diff?cvsroot=src&only_with_tag=binutils-2_22-branch&r1=1.1460.2.6&r2=1.1460.2.7 http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-elf/pr13250-1.c.diff?cvsroot=src&only_with_tag=binutils-2_22-branch&r1=NONE&r2=1.1.2.1 http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-elf/pr13250-2.c.diff?cvsroot=src&only_with_tag=binutils-2_22-branch&r1=NONE&r2=1.1.2.1 http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-elf/pr13250-3.c.diff?cvsroot=src&only_with_tag=binutils-2_22-branch&r1=NONE&r2=1.1.2.1 http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-elf/shared.exp.diff?cvsroot=src&only_with_tag=binutils-2_22-branch&r1=1.17&r2=1.17.2.1
The master branch has been updated by Alan Modra <amodra@sourceware.org>: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=7ba115508aa02ffbb01a09613b5dffdd0c6563e3 commit 7ba115508aa02ffbb01a09613b5dffdd0c6563e3 Author: Alan Modra <amodra@gmail.com> Date: Tue Sep 8 13:02:31 2020 +0930 PR26580, Size and alignment of commons vs as-needed shared lib Two pieces to this puzzle: 1) Revert HJ's fix for PR13250 so that size and alignment isn't sticky, instead attack the real underlying problem that _bfd_generic_link_add_one_symbol does the wrong thing in making a common section in a shared library bfd. 2) Save and restore common u.c.p fields, which hold the section and alignment. A better fix for (2) would be to throw away all of that horrible code saving and restoring the hash table when loading as-needed library symbols, and instead do a scan over as-needed library symbols before adding anything. bfd/ PR 13250 PR 26580 * elflink.c (_bfd_elf_merge_symbol): Make "override" a bfd**. Return oldbfd in override when old common should override new common. (_bfd_elf_add_default_symbol): Adjust to suit. (elf_link_add_object_symbols): Likewise. Pass "override" to _bfd_generic_link_add_one_symbol. Save and restore common u.c.p field for --as-needed shared libraries. Revert pr13250 changes. ld/ * testsuite/ld-elf/pr26580-a.s, * testsuite/ld-elf/pr26580-b.s, * testsuite/ld-elf/pr26580-1.sd, * testsuite/ld-elf/pr26580-2.sd: New tests * testsuite/ld-elf/comm-data.exp: Run new tests. * testsuite/ld-elf/pr26580-a.c, * testsuite/ld-elf/pr26580-b.c, * testsuite/ld-elf/pr26580-3.out, * testsuite/ld-elf/pr26580-4.out: New tests. * testsuite/ld-elf/shared.exp: Run new tests.