tinycc-devel
[Top][All Lists]
Advanced

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

Re: [Tinycc-devel] linux/unix shared libraries?


From: grischka
Subject: Re: [Tinycc-devel] linux/unix shared libraries?
Date: Thu, 24 Apr 2008 19:41:12 +0200

From: "Olaf Dietrich":
> I don't see any difference either: "segmentation fault" also without -r.

In between I could reproduce the error with a modified example, 
i.e. with some data access.

Reason seems a problem with the dynamic relocation entries that
TCC generates. You can see this with
    
    objdump -x libmylib.so

Here is the difference between TCC and GCC

------------------------------------------
TCC makes separate .rel sections, and in the 'dynamic' header,
puts the address (REL) of the first (rel.text), but the size 
(RELSZ) of all added:

Dynamic Section:
  ...
  REL         0x348
  RELSZ       0xc8

Sections:
Idx Name                Size      VMA       LMA       File off  Algn
  4 .rel.text           00000010  00000348  00000348  00000348  2**2
  7 .rel.fini           00000008  00000358  00000358  00000358  2**2
 12 .rel.debug_line     00000038  00000360  00000360  00000360  2**2
 14 .rel.debug_info     00000020  00000398  00000398  00000398  2**2
 17 .rel.debug_aranges  00000048  000003b8  000003b8  000003b8  2**2
 18 .rel.data           00000008  00000400  00000400  00000400  2**2
 27 .rel.got            00000008  00000408  00000408  00000408  2**2

------------------------------------------
Whereas GCC makes only two .rel sections and has REL and RELSZ equal
to the first of it (.rel.dyn):

Dynamic Section:
  ...
  REL         0x378
  RELSZ       0x38

Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  5 .rel.dyn      00000038  00000378  00000378  00000378  2**2
  6 .rel.plt      00000008  000003b0  000003b0  000003b0  2**2


------------------------------------------

The problem with the layout from TCC seem to be that the dynamic 
linker (/lib/ld-linux.so.2) thinks RELSZ is the size of rel.text, 
and then crashes when it goes over the end of it.

So bad news for now: Looks like TCC is something missing.  I don't 
understand the ELF linker very well, and don't have time to look 
into it anyway.  Maybe it is easy to fix, maybe not.

If someone wants to look into it, below is the test-example again.

--- grischka

mylib.c:

    const char s[] = "12345", *p[] = { s, 0 }; 
    int func(void)
    {
        return p[0][3];
    }

testlib.c:

    int func(void);
    int main()
    {
        printf("func: %d\n", func());
        return 0;
    }


run it:

    $ tcc mylib.c -o libmylib.so -shared
    $ tcc testlib.c -o testlib libmylib.so
    $ LD_LIBRARY_PATH=. ./testlib






reply via email to

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