Bug 4424 - Can't link in Linux object files on FreeBSD
Summary: Can't link in Linux object files on FreeBSD
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.19
: P2 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
: 5179 (view as bug list)
Depends on:
Blocks:
 
Reported: 2007-04-24 23:09 UTC by H.J. Lu
Modified: 2009-03-03 11:03 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
Link all sparc64 objects too (1.64 KB, patch)
2007-10-16 10:01 UTC, Roy Marples
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description H.J. Lu 2007-04-24 23:09:21 UTC
elf_link_add_object_symbols has

  if (! dynamic
      && is_elf_hash_table (htab)
      && htab->root.creator == abfd->xvec
      && bed->check_relocs != NULL) 

When you link Linux object files on FreeBSD, htab->root.creator != abfd->xvec.
As the result, linker will fail later. We need a better way to check if
input format is compatible with output format.
Comment 1 H.J. Lu 2007-04-25 00:01:17 UTC
A patch is posted at

http://sourceware.org/ml/binutils/2007-04/msg00330.html
Comment 2 H.J. Lu 2007-04-25 02:33:09 UTC
An updated patch is at

http://sourceware.org/ml/binutils/2007-04/msg00331.html
Comment 3 H.J. Lu 2007-08-30 17:39:08 UTC
An updated patch is posted at

http://sourceware.org/ml/binutils/2007-08/msg00462.html
Comment 4 H.J. Lu 2007-10-15 17:13:26 UTC
An updated patch for i386/FreeBSD is posted at

http://sourceware.org/ml/binutils/2007-10/msg00215.html
Comment 5 H.J. Lu 2007-10-15 17:13:51 UTC
*** Bug 5179 has been marked as a duplicate of this bug. ***
Comment 6 Roy Marples 2007-10-16 10:01:35 UTC
Created attachment 2043 [details]
Link all sparc64 objects too

We need this for FreeBSD/Sparc64 as well. Thanks!
Comment 7 H.J. Lu 2007-10-16 17:56:46 UTC
A new patch is posted at

http://sourceware.org/ml/binutils/2007-10/msg00240.html
Comment 8 H.J. Lu 2007-10-18 01:31:02 UTC
The current patch is at

http://sourceware.org/ml/binutils/2007-10/msg00257.html
Comment 10 H.J. Lu 2008-07-15 17:22:55 UTC
We missed a case of linking Linux .o against FreeBSD .so:

[hjl@gnu-6 weak-11]$ cat foo.c
extern void xxxx () __attribute__((weak));
void _start(void)
{ 
  if (&xxxx != 0)
    xxxx ();
}
[hjl@gnu-6 weak-11]$ cat bar.c
void
__attribute__((weak))
xxxx ()
{
}
[hjl@gnu-6 weak-11]$ make
gcc -O2 -fno-asynchronous-unwind-tables   -c -o foo.o foo.c
gcc -O2 -fno-asynchronous-unwind-tables -fPIC   -c -o bar.o bar.c
./ld -shared -o libbar.so bar.o
./ld  -o foo foo.o libbar.so
readelf -s foo | grep xxxx
     1: 00000000004002a0     2 FUNC    GLOBAL   DEFAULT  UND xxxx
    15: 00000000004002a0     2 FUNC    GLOBAL   DEFAULT  UND xxxx
[hjl@gnu-6 weak-11]$ ./ld -V
GNU ld (GNU Binutils) 2.18.50.20080715
  Supported emulations:
   elf_x86_64_fbsd
   elf_i386_fbsd
   elf_x86_64
   elf_i386
[hjl@gnu-6 weak-11]$ 

It should be

readelf -s foo | grep xxxx
     1: 00000000004002a0     2 FUNC    WEAK   DEFAULT  UND xxxx
    15: 00000000004002a0     2 FUNC    WEAK   DEFAULT  UND xxxx
Comment 11 H.J. Lu 2008-07-15 17:34:59 UTC
A new patch is posted at

http://sourceware.org/ml/binutils/2008-07/msg00207.html
Comment 12 Alan Modra 2009-03-03 11:03:53 UTC
Patch was applied