Bug 13298

Summary: ar --plugin doesn't work on mixed IR/non-IR input
Product: binutils Reporter: H.J. Lu <hjl.tools>
Component: binutilsAssignee: Not yet assigned to anyone <unassigned>
Status: NEW ---    
Severity: normal CC: law
Priority: P2    
Version: 2.24   
Target Milestone: ---   
Host: Target:
Build: Last reconfirmed:

Description H.J. Lu 2011-10-14 18:39:56 UTC
[hjl@gnu-6 slim-1]$ cat main.c
extern int bar ();

int
main ()
{
  return bar ();
}
[hjl@gnu-6 slim-1]$ cat xxx.c
int
xxx ()
{
  return 0;
}
[hjl@gnu-6 slim-1]$ cat bar.c
extern int xxx ();

int bar (void)
{
  return xxx ();
}
[hjl@gnu-6 slim-1]$ make
/usr/gcc-4.7.0-x32/bin/gcc    -c -o main.o main.c
/usr/gcc-4.7.0-x32/bin/gcc -flto -c -o xxx.o xxx.c
/usr/gcc-4.7.0-x32/bin/gcc    -c -o bar.o bar.c
ld -r -o rel.o xxx.o bar.o
ar --plugin /usr/gcc-4.7.0-x32/libexec/gcc/x86_64-unknown-linux-gnu/4.7.0/liblto_plugin.so -rcsD lib.a rel.o
/usr/gcc-4.7.0-x32/bin/gcc -flto -o x main.o lib.a
main.o: In function `main':
main.c:(.text+0xa): undefined reference to `bar'
collect2: error: ld returned 1 exit status
make: *** [x] Error 1
[hjl@gnu-6 slim-1]$ 
..

Without --plugin, it works fine:

[hjl@gnu-6 slim-1]$ rm lib.a
[hjl@gnu-6 slim-1]$ make
ar -rcsD lib.a rel.o
/usr/gcc-4.7.0-x32/bin/gcc -flto -o x main.o lib.a
[hjl@gnu-6 slim-1]$
Comment 1 H.J. Lu 2011-10-14 19:00:30 UTC
The problem is ar/nm doesn't see symbols in .gnu_object_only section.
Comment 2 H.J. Lu 2011-10-14 19:02:56 UTC
AR ignores the normal symbol table.