send2vinnie / mclinker

Automatically exported from code.google.com/p/mclinker
Other
0 stars 0 forks source link

No 64-bit ELF support #124

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
On hjl/x86-64 branch, I got

[hjl@gnu-32 test-1]$ cat lib.c
int
foo ()
{
  return 300;
}
[hjl@gnu-32 test-1]$ make libfoo.so
/export/opt/google/bin/clang -c -O2 -m64 -emit-llvm -fPIC -o lib.bc lib.c
./ld.mcld -march=x86-64  -filetype=obj -o lib.o < lib.bc
./ld.mcld -march=x86-64  -filetype=dso -o libfoo.so -dB lib.bc lib.o
make: *** [libfoo.so] Segmentation fault
[hjl@gnu-32 test-1]$ 

The problem is

ELFObjectReader::ELFObjectReader(GNULDBackend& pBackend,
                                 IRBuilder& pBuilder,
                                 const LinkerConfig& pConfig)
  : ObjectReader(),
    m_pELFReader(NULL),
    m_pEhFrameReader(NULL),
    m_Builder(pBuilder),
    m_ReadFlag(ParseEhFrame),
    m_Backend(pBackend),
    m_Config(pConfig) {
  if (pConfig.targets().is32Bits() && pConfig.targets().isLittleEndian()) {
    m_pELFReader = new ELFReader<32, true>(pBackend);
  }

  m_pEhFrameReader = new EhFrameReader();
}

There is no 64-bit ELF support

Original issue reported on code.google.com by hjl.to...@gmail.com on 12 Feb 2013 at 12:19

GoogleCodeExporter commented 9 years ago
Bypass to Trent. He is responsible for this issue.

Original comment by LubaTang on 18 Feb 2013 at 2:35

GoogleCodeExporter commented 9 years ago
1. Add ELFReader<64, true> to read 64-bit ELF files (in ELFReader.h)
  -- please update to (or after) commit 82aacb to see it
2. Move out ELFReaderIf from ELFReader.h to a separate file (ELFReaderIf.h)
3. Add unitest cases in ELFReaderTest.h

Original comment by lo.chenk...@gmail.com on 20 Feb 2013 at 10:46

GoogleCodeExporter commented 9 years ago
It doesn't work right:

[hjl@gnu-6 test-1]$ cat lib.c
int
foo ()
{
  return 300;
}
[hjl@gnu-6 test-1]$ make libfoo.so
gcc -c -O2 -m64 -fno-asynchronous-unwind-tables -fPIC -o lib.o lib.c
./ld.mcld -mtriple=x86_64-linux -filetype=dso -o libfoo.so lib.o
ld.mcld: 
/export/gnu/import/git/google/mclinker/debug/../lib/Target/ELFDynamic.cpp:80: 
void mcld::ELFDynamic::reserveOne(uint64_t): Assertion `__null != 
m_pEntryFactory' failed.
make: *** [libfoo.so] Aborted
[hjl@gnu-6 test-1]$ 

Original comment by hjl.to...@gmail.com on 20 Feb 2013 at 8:57

GoogleCodeExporter commented 9 years ago

Original comment by pete.c...@gmail.com on 21 Feb 2013 at 1:54

GoogleCodeExporter commented 9 years ago
Hi HJ,

I added 64-bit elf dynamic support in Rev. 506d95e6df13, and your example can 
be linked with that.

Original comment by pete.c...@gmail.com on 21 Feb 2013 at 3:19

GoogleCodeExporter commented 9 years ago
64-bit dynamic relocations aren't generated properly:

[hjl@gnu-6 test-2]$ cat lib.c
int bar1 = 200;
int bar2 = 300;

int
foo ()
{
  return bar2 / bar1;
}

void *
foo_p ()
{
  return foo;
}
[hjl@gnu-6 test-2]$ make libfoo.so
gcc -c -O2 -m64 -fno-asynchronous-unwind-tables -fPIC -o lib.o lib.c
./ld.mcld -mtriple=x86_64-pc-linux-gnu -filetype=dso -o libfoo.so lib.o
[hjl@gnu-6 test-2]$ readelf -r libfoo.so

Relocation section '.rela.dyn' at offset 0x288 contains 3 entries:
  Offset          Info           Type           Sym. Value    Sym. Name + Addend
0606000010b0  10b800000000 R_X86_64_NONE     bad symbol index: 000010b8
0506000010c0  000000000000 R_X86_64_NONE                        0
000000000000  000000000000 R_X86_64_NONE                        0
[hjl@gnu-6 test-2]$ 

Original comment by hjl.to...@gmail.com on 21 Feb 2013 at 8:08

GoogleCodeExporter commented 9 years ago
ELFWriter::emitRel and ELFWriter::emitRela are hard-coded to 32-bit.

Original comment by hjl.to...@gmail.com on 22 Feb 2013 at 7:23

GoogleCodeExporter commented 9 years ago
Luba just added 64-bit relocation support in Rev. 37c9756c42b3.

Original comment by pete.c...@gmail.com on 25 Feb 2013 at 10:18

GoogleCodeExporter commented 9 years ago
Archive reader doesn't support 64-bit ELF:

[hjl@gnu-6 test-10b]$ cat foo.c
int foo[20];
extern void bar (int);

int
_start ()
{
  bar (12);
  return 0;
}
[hjl@gnu-6 test-10b]$ cat reloc.c
extern int foo[];

int
bar (int i)
{
  return foo[i];
}
[hjl@gnu-6 test-10b]$ make
gcc -O2    -c -o foo.o foo.c
./ld.mcld -mtriple=x86_64-linux -filetype=exe -o foo foo.o libreloc.a
make: *** [foo] Segmentation fault
[hjl@gnu-6 test-10b]$ 

Original comment by hjl.to...@gmail.com on 25 Feb 2013 at 6:17

GoogleCodeExporter commented 9 years ago
To build libreloc.a:

gcc -O2    -c -o reloc.o reloc.c
ar rv libreloc.a reloc.o

Original comment by hjl.to...@gmail.com on 25 Feb 2013 at 6:19

GoogleCodeExporter commented 9 years ago
I checked in commit 8e40b3dfbeba7410f10419f209fd5cf5c4940eaa
to add ELFReader<64, true> to ELFDynObjReader.

Original comment by hjl.to...@gmail.com on 25 Feb 2013 at 6:41

GoogleCodeExporter commented 9 years ago
So looks like it's not the bug in archive reader, but no 64-bit elf reader in 
ELFDynObjReader.

Original comment by pete.c...@gmail.com on 26 Feb 2013 at 1:39

GoogleCodeExporter commented 9 years ago
Is there anything left for this specific bug?

Original comment by joerg.sonnenberger@googlemail.com on 29 Mar 2013 at 3:04

GoogleCodeExporter commented 9 years ago
Closing, x86-64 has a few issues left in the NetBSD tries, but nothing generic 
in the 64bit ELF support AFAICT.

Original comment by joerg.sonnenberger@googlemail.com on 9 Aug 2013 at 7:02