This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
RE: externally_visible and resoultion file
- From: "Bingfeng Mei" <bmei at broadcom dot com>
- To: "Jan Hubicka" <hubicka at ucw dot cz>, "Richard Guenther" <richard dot guenther at gmail dot com>
- Cc: "gcc at gcc dot gnu dot org" <gcc at gcc dot gnu dot org>
- Date: Tue, 8 Jun 2010 06:01:37 -0700
- Subject: RE: externally_visible and resoultion file
- References: <7FB04A5C213E9943A72EE127DB74F0ADA6666C4CB4@SJEXCHCCR02.corp.ad.broadcom.com> <AANLkTimYbuzLlapl78bxFsRaj93klV8_cAzJLhPCKPcS@mail.gmail.com> <20100527080348.GB21512@atrey.karlin.mff.cuni.cz>
Hi,
Sorry for coming back to this issue after a while. I am still puzzled
by this. 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
Since you both mentioned that 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, and vvvvvv is
linked correctly though.
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 <printf@plt>
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)
Is this a bug? GCC should issue warning/error here. Why is vvvvvv linked correctly?
Shouldn't it be treated as static with -fwhile-program and without externally_visible?
My trunk is 160104 by the way.
Thanks,
Bingfeng
> -----Original Message-----
> From: Jan Hubicka [mailto:hubicka@ucw.cz]
> Sent: 27 May 2010 09:04
> To: Richard Guenther
> Cc: Bingfeng Mei; gcc@gcc.gnu.org
> Subject: Re: externally_visible and resoultion file
>
> > On Wed, May 26, 2010 at 5:53 PM, Bingfeng Mei <bmei@broadcom.com>
> wrote:
> > > Hi, Richard,
> > > With resolution file generated by GOLD (or I am going to hack gnu
> LD), ?is
> > > externally_visible attribute still needed to annotate those symbols
> accessed
> > > from non-LTO objects when compiling with -fwhole-program.
> >
> > Yes it is. We do not parse the complete resolution file but only the
> > entries we'll end up reading .o files with LTO information for.
> >
> > > In theory, it shouldn't be needed since LTO has all information.
> But what
> > > about current implementation. I checked relevant source files and
> can't
> > > get immediate clue.
> >
> > The current implementation has no idea of the external references
> > (though it's probably not too hard to implement).
>
> Yep, this is also one of my TODO list items...
>
> Honza
> >
> > Richard.