[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Tinycc-devel] wrong PLT generated by tcc 0.9.16
From: |
Basile STARYNKEVITCH |
Subject: |
[Tinycc-devel] wrong PLT generated by tcc 0.9.16 |
Date: |
Tue, 31 Dec 2002 17:23:14 +0100 |
Dear All,
It seems to me that tcc generate a wrong Procedure Linkage Table.
I am on Linux Debian Sid (x86=Athlon) - libc6 2.3.1-8, gcc 2.3.2,
binutils 2.13.90.0.16-1, kernel 2.4.20
I have the following two test files
################################################################
// file esstccdl.c
// emacs Time-stamp: <2002 De 31 Tue 14h15:24 cet {esstccdl.c} >
// prcsid $Id: esstccdl.c 1.1 Tue, 31 Dec 2002 16:31:38 +0100 basile $
#include <stdlib.h>
#include <stdio.h>
#include <dlfcn.h>
int
main (int argc, char **argv)
{
char linbuf[300];
char *funam = "fun";
char *sonam = "./esstccso.so";
void *h = 0;
FILE *f = 0;
void (*fptr) ();
if (argc > 2)
funam = argv[1];
if (argc > 3)
sonam = argv[2];
puts (__FILE__ " compiled at " __DATE__ " on " __TIME__ "\n");
h = dlopen (sonam, RTLD_NOW);
if (!h) {
fprintf (stderr, "dlopen %s failed : %s\n", sonam, dlerror ());
exit (1);
};
printf ("dlopen %s => %p\n", sonam, h);
fptr = dlsym (h, funam);
if (!fptr) {
fprintf (stderr, "dlsym %s failed : %s\n", funam, dlerror ());
exit (1);
};
printf ("dlsym %s => %p\n", funam, (void *) fptr);
f = fopen("/proc/self/maps", "r");
printf("\n*** our (pid %d) memory map:\n", (int)getpid());
while (!feof(f)) {
memset(linbuf, 0, sizeof(linbuf));
fgets(linbuf, sizeof(linbuf)-1, f);
fputs(linbuf, stdout);
};
fclose(f);
puts("*** end of map\n");
printf("before call fptr=%p\n", (void*)fptr);
(*fptr) ();
printf ("end test\n");
return 0;
} // end of main
// eof esstccdl.c
################################################################
// file esstccso.c
// emacs Time-stamp: <2002 De 31 Tue 12h40:05 cet {esstccso.c} >
// prcsid $Id: esstccso.c 1.1 Tue, 31 Dec 2002 16:31:38 +0100 basile $
#include <stdio.h>
#include <unistd.h>
void fun(void) {
puts (__FILE__ " compiled at " __DATE__ " on " __TIME__ "\n");
printf("pid %d\n", (int)getpid());
}
// eof esstccso.c
################################################################
The test file esstccdl.c is compiled with
tcc -o esstccdl esstccdl.c -ldl
(adding the -g flag dont help and dont harm)
esstccdl.c dlopen the esstccso.so file and indirectly calls the fun
function there using dlsym.
The test file esstccso.c should be compiled into a shared object. With
tcc -o esstccso.so -shared esstccso.c
the resulting file has a bad PLT entry at file offset 0xff0; when
running ./esstccdl which dlopens it, a SIGSEGV occurs there (in
process adress 0x40013ff0 on my system, where the esstccso.so mapping
starts at 0x40013000).
If I compile esstccso.c with gcc using
gcc -o esstccso.so -shared esstccso.c
the resulting file has a good PLT and the ./esstccdl program runs ok.
using objdump and readelf
The gcc generated esstccso.so has
Contents of section .plt:
0558 ffb30400 0000ffa3 08000000 00000000 ................
0568 ffa30c00 00006800 000000e9 e0ffffff ......h.........
0578 ffa31000 00006808 000000e9 d0ffffff ......h.........
Relocation section '.rel.plt' at offset 0x530 contains 2 entries:
Offset Info Type Sym.Value Sym. Name
0000180c 00001e07 R_386_JUMP_SLOT 00000000 __cxa_finalize
00001810 00002207 R_386_JUMP_SLOT 00000000 _Jv_RegisterClasses
The tcc generated esstccso.so has
Hex dump of section '.plt':
0x00000fe0 00000000 00002128 25ff0000 212435ff .5$!...%(!......
0x00000ff0 ffffffe0 e9000000 00680000 212025ff .% !..h.........
0x00001000 ffffffd0 e9000000 08680000 212025ff .% !..h.........
0x00001010 ffffffc0 e9000000 10680000 212025ff .% !..h.........
0x00001020 080724a0 00000018 00000091 00000048 H............$..
0x00001030 00000001 00000009 0000003c 00000020 ...<...........
0x00001040 00000000 00000001 00000000 00000006 ................
0x00001050 00000000 00000f85 00000f85 00000018 ................
0x00001060 00000000 00000000 080755b8 00000000 .....U..........
it has no relocation of .plt (ie no .rel.plt section)
I have no idea of how to correct tcc for this.
--
Basile STARYNKEVITCH http://starynkevitch.net/Basile/
email: basile<at>starynkevitch<dot>net
alias: basile<at>tunes<dot>org
8, rue de la Faïencerie, 92340 Bourg La Reine, France
- [Tinycc-devel] wrong PLT generated by tcc 0.9.16,
Basile STARYNKEVITCH <=