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