Bug 91396 - Link error when I use -fvtable-verify=std and -static
Summary: Link error when I use -fvtable-verify=std and -static
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: other (show other bugs)
Version: 7.4.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: link-failure
Depends on:
Blocks:
 
Reported: 2019-08-08 10:20 UTC by niva
Modified: 2019-11-14 11:40 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description niva 2019-08-08 10:20:03 UTC
I have built gcc-7.4.0 with --enable-vtable-verify for x86_64 under Fedora 27:

$HOME/src/gcc-7.4.0/configure --srcdir=$HOME/src/gcc-7.4.0 --verbose --enable-vtable-verify --enable-languages=c,c++,fortran --enable-lto --prefix=$HOME/local-gcc

When I run:

$ ~/local-gcc/bin/g++ -fvtable-verify=std -O2 -static t.C -o t.exe

the following error occurs:

~/local-gcc/lib/gcc/x86_64-pc-linux-gnu/7.4.0/vtv_end.o: In function `__VLTprotect':
vtv_end.c:(.text.startup+0x0): multiple definition of `__VLTprotect'
~/local-gcc/lib/gcc/x86_64-pc-linux-gnu/7.4.0/../../../../lib64/libvtv.a(vtv_end.o):~/build/native-gcc/x86_64-pc-linux-gnu/libvtv/vtv_end.c:59: first defined here

$ cat t.C
int main () {return 0;}

I have fixed the problem by deleting vtv_end.o from
~/local-gcc/lib64/libvtv.a but I'm not sure it's OK.
Comment 1 niva 2019-08-08 13:01:16 UTC
I've also noticed that small programs (tests) built with "vtable-verify enabled" gcc work slower than programs built with default gcc (even when the -fvtable-verify option is not used). This slowdown mostly concerns dynamically linked programs.
Comment 2 Eric Gallager 2019-08-08 16:15:37 UTC
cc-ing libvtv maintainer
Comment 3 Richard Biener 2019-08-09 07:30:46 UTC
Likely

#define GNU_USER_TARGET_STARTFILE_SPEC \
...
   %{fvtable-verify=none:%s; \
     fvtable-verify=preinit:vtv_start_preinit.o%s; \
     fvtable-verify=std:vtv_start.o%s} " \

should either be conditional on !static or indeed the copy removed from the
static libvtv.
Comment 4 ctice 2019-08-09 21:22:37 UTC
I would prefer that we make it condition on !static, rather than removing it.  I will work on a patch for that.
Comment 5 ctice 2019-08-13 16:11:53 UTC
Author: ctice
Date: Tue Aug 13 16:11:20 2019
New Revision: 274386

URL: https://gcc.gnu.org/viewcvs?rev=274386&root=gcc&view=rev
Log:
Fix PR other/91396 static linke error with -fvtable-verify

Fix a bug where linking with -fvtable-verify  and
-static causes the linker to complain about multiple definitions of
things in the vtv_end*.o files (once from the .o file and once from
libvtv.a).

2019-08-12  Caroline Tice  <cmtice@google.com>

        PR other/91396
        * config/gnu-user.h (GNU_USER_TARGET_ENDFILE_SPEC): Only add the
        vtv_end.o or vtv_end_preinit.o files if !static.



Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/gnu-user.h
Comment 6 Eric Gallager 2019-11-13 06:55:05 UTC
(In reply to ctice from comment #5)
> Author: ctice
> Date: Tue Aug 13 16:11:20 2019
> New Revision: 274386
> 
> URL: https://gcc.gnu.org/viewcvs?rev=274386&root=gcc&view=rev
> Log:
> Fix PR other/91396 static linke error with -fvtable-verify
> 
> Fix a bug where linking with -fvtable-verify  and
> -static causes the linker to complain about multiple definitions of
> things in the vtv_end*.o files (once from the .o file and once from
> libvtv.a).
> 
> 2019-08-12  Caroline Tice  <cmtice@google.com>
> 
>         PR other/91396
>         * config/gnu-user.h (GNU_USER_TARGET_ENDFILE_SPEC): Only add the
>         vtv_end.o or vtv_end_preinit.o files if !static.
> 
> 
> 
> Modified:
>     trunk/gcc/ChangeLog
>     trunk/gcc/config/gnu-user.h

Did this fix it?
Comment 7 ctice 2019-11-13 15:48:30 UTC
To the best of my knowledge this is fixed; do you have evidence otherwise?
Comment 8 Eric Gallager 2019-11-13 17:11:35 UTC
(In reply to ctice from comment #7)
> To the best of my knowledge this is fixed; do you have evidence otherwise?

Nope, just wanted to make sure I could close this.
Comment 9 niva 2019-11-14 11:40:29 UTC
I have built gcc-9.2.0 with --enable-vtable-verify for x86_64 under Fedora 22 with the correction
https://gcc.gnu.org/viewcvs/gcc?view=revision&revision=274386

Linking with -fvtable-verify  and -static is now ok, thank you.