public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/62287] New: gcc generates near call for extern weak function
@ 2014-08-27 21:31 breiten at lexmark dot com
  2015-01-15 11:22 ` [Bug target/62287] " ramana at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: breiten at lexmark dot com @ 2014-08-27 21:31 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62287

            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. 
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 the 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 with
the ‘long-call’ attribute or the ‘section’ attribute, and functions that are
within the scope of a ‘ #pragma long_calls’ directive are always 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/configure
--build=x86_64-linux --host=x86_64-linux --target=arm-poky-linux-gnueabi
--prefix=/bonus/scratch/gcc49/poky/gg-debug/tmp/sysroots/x86_64-linux/usr
--exec_prefix=/bonus/scratch/gcc49/poky/gg-debug/tmp/sysroots/x86_64-linux/usr
--bindir=/bonus/scratch/gcc49/poky/gg-debug/tmp/sysroots/x86_64-linux/usr/bin/cortexa53-vfp-neon-poky-linux-gnueabi
--sbindir=/bonus/scratch/gcc49/poky/gg-debug/tmp/sysroots/x86_64-linux/usr/bin/cortexa53-vfp-neon-poky-linux-gnueabi
--libexecdir=/bonus/scratch/gcc49/poky/gg-debug/tmp/sysroots/x86_64-linux/usr/libexec/cortexa53-vfp-neon-poky-linux-gnueabi
--datadir=/bonus/scratch/gcc49/poky/gg-debug/tmp/sysroots/x86_64-linux/usr/share
--sysconfdir=/bonus/scratch/gcc49/poky/gg-debug/tmp/sysroots/x86_64-linux/etc
--sharedstatedir=/bonus/scratch/gcc49/poky/gg-debug/tmp/sysroots/x86_64-linux/com
--localstatedir=/bonus/scratch/gcc49/poky/gg-debug/tmp/sysroots/x86_64-linux/var
--libdir=/bonus/scratch/gcc49/poky/gg-debug/tmp/sysroots/x86_64-linux/usr/lib/cortexa53-vfp-neon-poky-linux-gnueabi
--includedir=/bonus/scratch/gcc49/poky/gg-debug/tmp/sysroots/x86_64-linux/usr/include
--oldincludedir=/bonus/scratch/gcc49/poky/gg-debug/tmp/sysroots/x86_64-linux/usr/include
--infodir=/bonus/scratch/gcc49/poky/gg-debug/tmp/sysroots/x86_64-linux/usr/share/info
--mandir=/bonus/scratch/gcc49/poky/gg-debug/tmp/sysroots/x86_64-linux/usr/share/man
--disable-silent-rules --disable-dependency-tracking
--with-libtool-sysroot=/bonus/scratch/gcc49/poky/gg-debug/tmp/sysroots/x86_64-linux
--enable-clocale=generic --with-gnu-ld --enable-shared --enable-languages=c,c++
--enable-threads=posix --disable-multilib --enable-c99 --enable-long-long
--enable-symvers=gnu --enable-libstdcxx-pch
--program-prefix=arm-poky-linux-gnueabi- --without-local-prefix
--enable-target-optspace --enable-lto --enable-libssp --disable-bootstrap
--disable-libmudflap --with-system-zlib --with-linker-hash-style=gnu
--enable-linker-build-id --with-ppl=no --with-cloog=no
--enable-checking=release --enable-cheaders=c_global
--with-gxx-include-dir=/bonus/scratch/gcc49/poky/gg-debug/tmp/sysroots/gg/usr/include/c++
--with-sysroot=/bonus/scratch/gcc49/poky/gg-debug/tmp/sysroots/gg
--with-build-sysroot=/bonus/scratch/gcc49/poky/gg-debug/tmp/sysroots/gg
--enable-poison-system-directories --disable-libunwind-exceptions
--with-mpfr=/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/cortexa53-vfp-neon-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc
-Os -mabi=aapcs-linux -mcpu=cortex-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 = 0, pretend = 0, frame = 0
    @ frame_needed = 0, uses_anonymous_args = 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: <gcc-bugs-return-459376-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
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: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
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" <gcc-bugzilla@gcc.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: <bug-58678-4-94JAZ3j79x@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-58678-4@http.gcc.gnu.org/bugzilla/>
References: <bug-58678-4@http.gcc.gnu.org/bugzilla/>
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?idX678

--- Comment #58 from Markus Trippelsdorf <trippels at gcc dot gnu.org> ---
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<B*>(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 %


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug target/62287] gcc generates near call for extern weak function
  2014-08-27 21:31 [Bug c/62287] New: gcc generates near call for extern weak function breiten at lexmark dot com
@ 2015-01-15 11:22 ` ramana at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: ramana at gcc dot gnu.org @ 2015-01-15 11:22 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62287

Ramana Radhakrishnan <ramana at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
                 CC|                            |ramana at gcc dot gnu.org
         Resolution|---                         |INVALID

--- Comment #1 from Ramana Radhakrishnan <ramana at gcc dot gnu.org> ---
If you use -mlong-calls in these particular cases, you should be able to work
around the problem.


The documentation for this feature states the following. 

 Even if this switch is enabled, not all function calls are turned
into long calls.  The heuristic is that static functions, functions
that have the @code{short_call} attribute, functions that are inside
the scope of a @code{#pragma no_long_calls} directive, and functions whose
definitions have already been compiled within the current compilation
unit are not turned into long calls.  The exceptions to this rule are
that weak function definitions, functions with the @code{long_call}
attribute or the @code{section} attribute, and functions that are within
the scope of a @code{#pragma long_calls} directive are always
turned into long calls.


I would read the exceptions to the rule as part of the #pragma no_long_calls
directive rather than anythign else. I'm not sure there's much for the compiler
to do here.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-01-15 11:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-27 21:31 [Bug c/62287] New: gcc generates near call for extern weak function breiten at lexmark dot com
2015-01-15 11:22 ` [Bug target/62287] " ramana at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).