bug-binutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug gold/11683] New: GOLD wrongly linked function/var that are converte


From: bmei at broadcom dot com
Subject: [Bug gold/11683] New: GOLD wrongly linked function/var that are converted to static by GCC LTO
Date: 9 Jun 2010 10:35:12 -0000

The following are two test files:

a.c

#include <string.h>
#include <stdio.h>
extern int foo(int);
void bar() 
{
  printf("bar\n");
}  
extern int src[], dst[];
int vvvvvv;
int main()
{ 
  int ret;
  vvvvvv = 12; 
  ret = foo(20);
  memcpy(dst, src, 100);
  return ret + 3;
}  

b.c 
#include <stdio.h>
int src[100];
int dst[100];
extern int vvvvvv;
extern void bar();
int foo(int c)
{
  printf("Hello world: %d\n", c);
  bar();
  return 1000 + vvvvvv;
}

I compiled with following steps
~/work/install-x86/bin/gcc -flto a.c -O2 -c
~/work/install-x86/bin/gcc b.c -O2 -c
ar cru libb.a b.o
~/work/install-x86/bin/gcc -flto a.o -L. -lb -O2 -fuse-linker-plugin -o f
-fwhole-program -save-temps

Currently resolution file is not used to replace externally_visible attribute
yet, I expect there will be link errors regarding both vvvvvv and bar. Somehow,
GCC doesn't complain at all. However, looking at generated assembly code, GCC
produces wrong code for calling bar. vvvvvv is linked correctly but it 
shouldn't be.

0000000000400510 <foo>:
  400510:       48 83 ec 08             sub    $0x8,%rsp
  400514:       89 fe                   mov    %edi,%esi
  400516:       31 c0                   xor    %eax,%eax
  400518:       bf 1c 06 40 00          mov    $0x40061c,%edi
  40051d:       e8 56 01 00 00          callq  400678 <address@hidden>
  400522:       31 c0                   xor    %eax,%eax
  400524:       e8 d7 fa bf ff          callq  0 <__fini_array_end>   <-------- 
 should
call bar. 
  400529:       8b 05 a1 17 00 00       mov    0x17a1(%rip),%eax        # 
401cd0 <vvvvvv>
  40052f:       48 83 c4 08             add    $0x8,%rsp
  400533:       05 e8 03 00 00          add    $0x3e8,%eax
  400538:       c3                      retq   
  400539:       0f 1f 80 00 00 00 00    nopl   0x0(%rax)


My GOLD version is 2.20.51 & GCC is trunk. 

I discussed with Richard Guenther. He believed this is a bug of GOLD.

-- 
           Summary: GOLD wrongly linked function/var that are converted to
                    static by GCC LTO
           Product: binutils
           Version: 2.20
            Status: NEW
          Severity: normal
          Priority: P2
         Component: gold
        AssignedTo: ian at airs dot com
        ReportedBy: bmei at broadcom dot com
                CC: bug-binutils at gnu dot org


http://sourceware.org/bugzilla/show_bug.cgi?id=11683

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]