Bug 71796 - Link error referencing compiler generated symbol __vtab_xxx
Summary: Link error referencing compiler generated symbol __vtab_xxx
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 7.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: link-failure
Depends on:
Blocks:
 
Reported: 2016-07-07 12:38 UTC by Ian Harvey
Modified: 2019-03-28 20:19 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work: 7.3.0
Known to fail: 6.5.0
Last reconfirmed: 2016-07-07 00:00:00


Attachments
Reduced test case program exhibiting the link error (365 bytes, text/plain)
2016-07-07 12:38 UTC, Ian Harvey
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Ian Harvey 2016-07-07 12:38:23 UTC
Created attachment 38853 [details]
Reduced test case program exhibiting the link error

With recent trunk (r238061) The attached program fails to link with undefined references to `__vtab_ma_Ta.3481`, which appears to be an internally generated symbol related to the compiler's support for polymorphism.

The error disappears if the order of the USE statements is changed in one of the scopes as indicated in the test case.  USE statement ordering in a scope is not supposed to affect source semantics.

$ gfortran -v vtab-link-error.f90
Driving: gfortran -v vtab-link-error.f90 -l gfortran -l m -shared-libgcc
Using built-in specs.
COLLECT_GCC=gfortran
COLLECT_LTO_WRAPPER=/home/MEGMS2/ian/usr/gcc-7.0.0/libexec/gcc/x86_64-pc-linux-gnu/7.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: .././src/configure --prefix=/home/MEGMS2/ian/usr/gcc-7.0.0 --enable-languages=c,c++,fortran --enable-libgomp --enable-checking=release : (reconfigured) .././src/configure --prefix=/home/MEGMS2/ian/usr/gcc-7.0.0 --enable-libgomp --enable-checking=release --enable-languages=c,c++,fortran,lto --no-create --no-recursion
Thread model: posix
gcc version 7.0.0 20160706 (experimental) (GCC)
COLLECT_GCC_OPTIONS='-v' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
 /home/MEGMS2/ian/usr/gcc-7.0.0/libexec/gcc/x86_64-pc-linux-gnu/7.0.0/f951 vtab-link-error.f90 -quiet -dumpbase vtab-link-error.f90 -mtune=generic -march=x86-64 -auxbase vtab-link-error -version -fintrinsic-modules-path /home/MEGMS2/ian/usr/gcc-7.0.0/lib/gcc/x86_64-pc-linux-gnu/7.0.0/finclude -o /tmp/cca44wnw.s
GNU Fortran (GCC) version 7.0.0 20160706 (experimental) (x86_64-pc-linux-gnu)
        compiled by GNU C version 7.0.0 20160706 (experimental), GMP version 6.1.0, MPFR version 3.1.4, MPC version 1.0.2, isl version none
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
GNU Fortran2008 (GCC) version 7.0.0 20160706 (experimental) (x86_64-pc-linux-gnu)
        compiled by GNU C version 7.0.0 20160706 (experimental), GMP version 6.1.0, MPFR version 3.1.4, MPC version 1.0.2, isl version none
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
COLLECT_GCC_OPTIONS='-v' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
 as -v --64 -o /tmp/ccnjfNd7.o /tmp/cca44wnw.s
GNU assembler version 2.26 (x86_64-redhat-linux) using BFD version version 2.26.20160125
Reading specs from /home/MEGMS2/ian/usr/gcc-7.0.0/lib/gcc/x86_64-pc-linux-gnu/7.0.0/../../../../lib64/libgfortran.spec
rename spec lib to liborig
COLLECT_GCC_OPTIONS='-v' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
COMPILER_PATH=/home/MEGMS2/ian/usr/gcc-7.0.0/libexec/gcc/x86_64-pc-linux-gnu/7.0.0/:/home/MEGMS2/ian/usr/gcc-7.0.0/libexec/gcc/x86_64-pc-linux-gnu/7.0.0/:/home/MEGMS2/ian/usr/gcc-7.0.0/libexec/gcc/x86_64-pc-linux-gnu/:/home/MEGMS2/ian/usr/gcc-7.0.0/lib/gcc/x86_64-pc-linux-gnu/7.0.0/:/home/MEGMS2/ian/usr/gcc-7.0.0/lib/gcc/x86_64-pc-linux-gnu/
LIBRARY_PATH=/home/MEGMS2/ian/usr/gcc-7.0.0/lib/gcc/x86_64-pc-linux-gnu/7.0.0/:/home/MEGMS2/ian/usr/gcc-7.0.0/lib/gcc/x86_64-pc-linux-gnu/7.0.0/../../../../lib64/:/lib/../lib64/:/usr/lib/../lib64/:/home/MEGMS2/ian/usr/gcc-7.0.0/lib/gcc/x86_64-pc-linux-gnu/7.0.0/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
 /home/MEGMS2/ian/usr/gcc-7.0.0/libexec/gcc/x86_64-pc-linux-gnu/7.0.0/collect2 -plugin /home/MEGMS2/ian/usr/gcc-7.0.0/libexec/gcc/x86_64-pc-linux-gnu/7.0.0/liblto_plugin.so -plugin-opt=/home/MEGMS2/ian/usr/gcc-7.0.0/libexec/gcc/x86_64-pc-linux-gnu/7.0.0/lto-wrapper -plugin-opt=-fresolution=/tmp/cc1JOD5H.res -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lquadmath -plugin-opt=-pass-through=-lm -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 /lib/../lib64/crt1.o /lib/../lib64/crti.o /home/MEGMS2/ian/usr/gcc-7.0.0/lib/gcc/x86_64-pc-linux-gnu/7.0.0/crtbegin.o -L/home/MEGMS2/ian/usr/gcc-7.0.0/lib/gcc/x86_64-pc-linux-gnu/7.0.0 -L/home/MEGMS2/ian/usr/gcc-7.0.0/lib/gcc/x86_64-pc-linux-gnu/7.0.0/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/home/MEGMS2/ian/usr/gcc-7.0.0/lib/gcc/x86_64-pc-linux-gnu/7.0.0/../../.. /tmp/ccnjfNd7.o -lgfortran -lm -lgcc_s -lgcc -lquadmath -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /home/MEGMS2/ian/usr/gcc-7.0.0/lib/gcc/x86_64-pc-linux-gnu/7.0.0/crtend.o /lib/../lib64/crtn.o
/tmp/ccnjfNd7.o: In function `__mc_MOD_subc':
vtab-link-error.f90:(.text+0x17): undefined reference to `__vtab_ma_Ta.3481'
vtab-link-error.f90:(.text+0x96): undefined reference to `__vtab_ma_Ta.3481'
collect2: error: ld returned 1 exit status
Comment 1 Dominique d'Humieres 2016-07-07 17:03:16 UTC
Confirmed from 4.8 up to trunk (7.0).
Comment 2 Dominique d'Humieres 2016-10-24 18:52:37 UTC
The link error has been fixed by r241450. I'll commit the test to the gfortran test suite soon.

Note that it would be nice to have a test giving a working executable with an expected result at run time: the executable for the test segfaults at run time.
Comment 3 Ian Harvey 2016-10-26 23:02:37 UTC
If you want a test case that exhibits no run time error upon successful compilation and linking, then replace the entire main program with an END statement.

MODULE ma
  IMPLICIT NONE
  PRIVATE
  
  TYPE, PUBLIC, ABSTRACT :: ta
  END TYPE ta
END MODULE ma

MODULE mb
  IMPLICIT NONE
  PRIVATE
  
  TYPE, PUBLIC, ABSTRACT :: tb
  CONTAINS
    PROCEDURE(b_binding), DEFERRED :: binding
  END TYPE tb
  
  ABSTRACT INTERFACE
    SUBROUTINE b_binding(argb, arga)
      USE ma
      IMPORT :: tb
      IMPLICIT NONE
      
      CLASS(tb), INTENT(IN) :: argb
      CLASS(ta), INTENT(OUT), ALLOCATABLE :: arga
    END SUBROUTINE b_binding
  END INTERFACE
END MODULE mb

MODULE mc
  IMPLICIT NONE
  PRIVATE
  
  PUBLIC :: subc
CONTAINS
  SUBROUTINE subc
    USE mb      !<< Ordering of these statements is significant.
    USE ma      !<< Ordering of these statements is significant.
    
    CLASS(ta), ALLOCATABLE :: a
    CLASS(tb), ALLOCATABLE :: b
    !****
    CALL b%binding(a)
  END SUBROUTINE subc
END MODULE mc

END     ! <<<<
Comment 4 Dominique d'Humieres 2016-11-01 16:41:08 UTC
> If you want a test case that exhibits no run time error upon successful
> compilation and linking, then replace the entire main program with an
> END statement.

I am using that for years and was not what I asked for (sorry if I have been unclear).

Presently the test obviously segfaults at run time.

What I'ld like to have is an actual implementation of b_binding and the expected output at run time.
Comment 5 Dominique d'Humieres 2017-03-22 15:58:58 UTC
No help, thus unassigned myself!-(
Comment 6 janus 2019-03-28 20:19:52 UTC
The problem is fixed since gfortran version 7. Closing.