From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28780 invoked by alias); 27 Aug 2014 21:31:27 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 28754 invoked by uid 48); 27 Aug 2014 21:31:19 -0000 From: "breiten at lexmark dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/62287] New: gcc generates near call for extern weak function Date: Wed, 27 Aug 2014 21:31:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: 4.9.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: breiten at lexmark dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2014-08/txt/msg01872.txt.bz2 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D62287 Bug ID: 62287 Summary: gcc generates near call for extern weak function Product: gcc Version: 4.9.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: breiten at lexmark dot com The following code, from a linux driver, attempts to call a weak function, = if the address of that function is non-zero (i.e. defined in an earlier-loaded module). However, when configured for arm-eabi, a normal "bl" instruction is issued.= =20 While it generates the logic to test and avoid the call if bar is NULL, we = get a relocation error when the driver is loaded, because 0 is too far away from 0xbf7xxxx. Verified this on 4.7.2, 4,8.3, and 4.9.0. gcc-4.2 generates th= e bx opcode that I expect. The current documentation for -mlong-calls" under "ARM options" states: The exceptions to this rule are that weak function definitions, functions w= ith the =E2=80=98long-call=E2=80=99 attribute or the =E2=80=98section=E2=80=99 = attribute, and functions that are within the scope of a =E2=80=98 #pragma long_calls=E2=80=99 directive are a= lways turned into long calls. I did see PR51643, which addresses this sort of problem for tail calls, and= I see it behave correctly if I modify the code below to allow a tail-call. extern void bar(void)__attribute__((weak)); int foo() { if( bar) bar(); return 0; } Here's my configuration/version info: Target: arm-poky-linux-gnueabi Configured with: /bonus/scratch/gcc49/poky/gg-debug/tmp/work-shared/gcc-4.9.0-r0/gcc-4.9.0/c= onfigure --build=3Dx86_64-linux --host=3Dx86_64-linux --target=3Darm-poky-linux-gnue= abi --prefix=3D/bonus/scratch/gcc49/poky/gg-debug/tmp/sysroots/x86_64-linux/usr --exec_prefix=3D/bonus/scratch/gcc49/poky/gg-debug/tmp/sysroots/x86_64-linu= x/usr --bindir=3D/bonus/scratch/gcc49/poky/gg-debug/tmp/sysroots/x86_64-linux/usr= /bin/cortexa53-vfp-neon-poky-linux-gnueabi --sbindir=3D/bonus/scratch/gcc49/poky/gg-debug/tmp/sysroots/x86_64-linux/us= r/bin/cortexa53-vfp-neon-poky-linux-gnueabi --libexecdir=3D/bonus/scratch/gcc49/poky/gg-debug/tmp/sysroots/x86_64-linux= /usr/libexec/cortexa53-vfp-neon-poky-linux-gnueabi --datadir=3D/bonus/scratch/gcc49/poky/gg-debug/tmp/sysroots/x86_64-linux/us= r/share --sysconfdir=3D/bonus/scratch/gcc49/poky/gg-debug/tmp/sysroots/x86_64-linux= /etc --sharedstatedir=3D/bonus/scratch/gcc49/poky/gg-debug/tmp/sysroots/x86_64-l= inux/com --localstatedir=3D/bonus/scratch/gcc49/poky/gg-debug/tmp/sysroots/x86_64-li= nux/var --libdir=3D/bonus/scratch/gcc49/poky/gg-debug/tmp/sysroots/x86_64-linux/usr= /lib/cortexa53-vfp-neon-poky-linux-gnueabi --includedir=3D/bonus/scratch/gcc49/poky/gg-debug/tmp/sysroots/x86_64-linux= /usr/include --oldincludedir=3D/bonus/scratch/gcc49/poky/gg-debug/tmp/sysroots/x86_64-li= nux/usr/include --infodir=3D/bonus/scratch/gcc49/poky/gg-debug/tmp/sysroots/x86_64-linux/us= r/share/info --mandir=3D/bonus/scratch/gcc49/poky/gg-debug/tmp/sysroots/x86_64-linux/usr= /share/man --disable-silent-rules --disable-dependency-tracking --with-libtool-sysroot=3D/bonus/scratch/gcc49/poky/gg-debug/tmp/sysroots/x8= 6_64-linux --enable-clocale=3Dgeneric --with-gnu-ld --enable-shared --enable-languages= =3Dc,c++ --enable-threads=3Dposix --disable-multilib --enable-c99 --enable-long-long --enable-symvers=3Dgnu --enable-libstdcxx-pch --program-prefix=3Darm-poky-linux-gnueabi- --without-local-prefix --enable-target-optspace --enable-lto --enable-libssp --disable-bootstrap --disable-libmudflap --with-system-zlib --with-linker-hash-style=3Dgnu --enable-linker-build-id --with-ppl=3Dno --with-cloog=3Dno --enable-checking=3Drelease --enable-cheaders=3Dc_global --with-gxx-include-dir=3D/bonus/scratch/gcc49/poky/gg-debug/tmp/sysroots/gg= /usr/include/c++ --with-sysroot=3D/bonus/scratch/gcc49/poky/gg-debug/tmp/sysroots/gg --with-build-sysroot=3D/bonus/scratch/gcc49/poky/gg-debug/tmp/sysroots/gg --enable-poison-system-directories --disable-libunwind-exceptions --with-mpfr=3D/bonus/scratch/gcc49/poky/gg-debug/tmp/sysroots/x86_64-linux/= usr --with-system-zlib --disable-nls Thread model: posix gcc version 4.9.0 (GCC) /bonus/scratch/gcc49/poky/gg-debug/tmp/sysroots/x86_64-linux/usr/bin/cortex= a53-vfp-neon-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc -Os -mabi=3Daapcs-linux -mcpu=3Dcortex-a53 -S -o - p.c .cpu cortex-a53 .fpu softvfp .eabi_attribute 20, 1 .eabi_attribute 21, 1 .eabi_attribute 23, 3 .eabi_attribute 24, 1 .eabi_attribute 25, 1 .eabi_attribute 26, 2 .eabi_attribute 30, 4 .eabi_attribute 34, 1 .eabi_attribute 18, 4 .file "p.c" .text .align 2 .global foo .type foo, %function foo: @ args =3D 0, pretend =3D 0, frame =3D 0 @ frame_needed =3D 0, uses_anonymous_args =3D 0 stmfd sp!, {r3, lr} ldr r3, .L8 cmp r3, #0 beq .L2 bl bar .L2: mov r0, #0 ldmfd sp!, {r3, pc} .L9: .align 2 .L8: .word bar .size foo, .-foo .weak bar .ident "GCC: (GNU) 4.9.0" .section .note.GNU-stack,"",%progbits >>From gcc-bugs-return-459376-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Wed Aug 27 21:40:20 2014 Return-Path: Delivered-To: listarch-gcc-bugs@gcc.gnu.org Received: (qmail 6760 invoked by alias); 27 Aug 2014 21:40:19 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Delivered-To: mailing list gcc-bugs@gcc.gnu.org Received: (qmail 6448 invoked by uid 48); 27 Aug 2014 21:40:15 -0000 From: "trippels at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/58678] [4.9 Regression] pykde4-4.11.2 link error (devirtualization too trigger happy) Date: Wed, 27 Aug 2014 21:40:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 4.9.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: trippels at gcc dot gnu.org X-Bugzilla-Status: RESOLVED X-Bugzilla-Priority: P1 X-Bugzilla-Assigned-To: hubicka at gcc dot gnu.org X-Bugzilla-Target-Milestone: 4.9.0 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2014-08/txt/msg01873.txt.bz2 Content-length: 2462 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58678 --- Comment #58 from Markus Trippelsdorf --- A gentoo user wrote me that pykde still fails with the same error when build with -flto. And indeed both the testcase from comment0 and from comment 13 still fail with -flto: markus@x4 /tmp % cat test.ii class A { public: virtual ~A(); }; class B : A { virtual int m_fn1(); }; void fn1() { delete reinterpret_cast(1); } markus@x4 /tmp % cat test2.ii class Part { public: virtual ~Part(); }; class A : Part {}; void fn1() { A *a; delete a; } markus@x4 /tmp % g++ -Wl,--no-undefined -shared -fPIC -flto -O2 test.ii /tmp/ccvkKVlc.ltrans0.ltrans.o:ccvkKVlc.ltrans0.o:function B::~B(): error: undefined reference to 'vtable for B' /usr/lib/gcc/x86_64-pc-linux-gnu/4.9.2/../../../../x86_64-pc-linux-gnu/bin/ld: the vtable symbol may be undefined because the class is missing its key function /tmp/ccvkKVlc.ltrans0.ltrans.o:ccvkKVlc.ltrans0.o:function B::~B(): error: undefined reference to 'A::~A()' /tmp/ccvkKVlc.ltrans0.ltrans.o:ccvkKVlc.ltrans0.o:function B::~B(): error: undefined reference to 'vtable for B' /usr/lib/gcc/x86_64-pc-linux-gnu/4.9.2/../../../../x86_64-pc-linux-gnu/bin/ld: the vtable symbol may be undefined because the class is missing its key function /tmp/ccvkKVlc.ltrans0.ltrans.o:ccvkKVlc.ltrans0.o:function fn1(): error: undefined reference to 'vtable for B' /usr/lib/gcc/x86_64-pc-linux-gnu/4.9.2/../../../../x86_64-pc-linux-gnu/bin/ld: the vtable symbol may be undefined because the class is missing its key function /tmp/ccvkKVlc.ltrans0.ltrans.o:ccvkKVlc.ltrans0.o:function fn1(): error: undefined reference to 'A::~A()' /tmp/ccvkKVlc.ltrans0.ltrans.o:ccvkKVlc.ltrans0.o:function B::~B(): error: undefined reference to 'A::~A()' collect2: error: ld returned 1 exit status markus@x4 /tmp % g++ -Wl,--no-undefined -shared -fPIC -flto -O2 test2.ii /tmp/ccY0KXU2.ltrans0.ltrans.o:ccY0KXU2.ltrans0.o:function A::~A(): error: undefined reference to 'Part::~Part()' /tmp/ccY0KXU2.ltrans0.ltrans.o:ccY0KXU2.ltrans0.o:function A::~A(): error: undefined reference to 'Part::~Part()' /tmp/ccY0KXU2.ltrans0.ltrans.o:ccY0KXU2.ltrans0.o:typeinfo for A: error: undefined reference to 'typeinfo for Part' collect2: error: ld returned 1 exit status markus@x4 /tmp % g++ -Wl,--no-undefined -shared -fPIC -O2 test.ii markus@x4 /tmp % g++ -Wl,--no-undefined -shared -fPIC -O2 test2.ii markus@x4 /tmp %