Every executable compiled using tcc segfaults. Interestingly, if the "-run" is used, the program executes as expected. See the "how to repeat the problem" below. I tried tcc version 0.9.24 (via pkg_add) and 0.9.25 (via ports, using gcc 4.2.1) with the same results. This seems to be FreeBSD specific since I cannot reproduce this on Linux (Arch, with gcc 4.4.1) at all. How-To-Repeat: echo 'main(){puts("hello");}' | tcc -o output - && ./output Segmentation fault (core dumped) And with "-run": echo 'main(){puts("hello");}' | tcc -run - hello
Responsible Changed From-To: freebsd-ports-bugs->dinoex Over to maintainer (via the GNATS Auto Assign Tool)
State Changed From-To: open->analyzed Verfied, the executables are not valid for FreeBSD 6 or FreeBSD 7 even ldd crashes on analyzing the executabe. The problem is known upstream, but no patch availible: http://www.mail-archive.com/tinycc-devel@nongnu.org/msg00129.html --------- Sergey Lyubka Sat, 23 Jul 2005 05:44:45 -0700 tcc builds ELF executable in the way not understood by FreeBSD. There is no quick fix for that, afaik. ELF executable linkage part of tcc must be adopted for building native FreeBSD exe-s. However, building Linux executables and linking them against /usr/compat/linux libraries might work. I spent some time before, trying to make 'native linkage' work on FreeBSD, but not finished the work yet. It is half-way complete. Simple programs do execute, more complex ones coredump. --------- Patches welcome.
I think i have managed to solve the problem and produce almost valid elf files on FreeBSD. The two patches attached should go in ports/tcc/files (patch-libtcc.c replaces the existing one with the same name) and bumping PORTREVISION should complete the job. I can do the commit myself if the maintainer has no time. The patches address a few problems (trying to explain to the best of my knowledge; i am not very familiar with ELF and the FreeBSD ELF conventions): 1. ELF file format tcc produces an ELF executable which is good for linux but not for FreeBSD. It misses the PHDR section which is almost mandatory for shared executables, puts in the .dynsym section some relocation info that FreeBSD expects to be in .got, and expect the relocation sections to be contiguous. patch-tccelf.c tries to address the above problem using conditional sections (so hopefully can be imported upstream) and also adds the ability to override the name of the dynamic loader through an environment variable (this is important to debug tcc). 2. predefined macros patch-libtcc.c adds/fixes some predefined macros when compiling on FreeBSD: these are __FreeBSD__ and the usual set of __i386__ and __unix__ variants. It also sets __INTEL_COMPILER so we can grab the __aligned macro from cdefs.h , otherwise many programs would fail The resulting elf file is still not 100% correct -- if you strip it, the program will not run (presumably there is some dangling reference). Other than that, program do seem to run correctly. I am going to submit the patch upstream to see if the maintainers want to integrate it cheers luigi
dinoex 2009-11-29 07:59:08 UTC FreeBSD ports repository Modified files: lang/tcc Makefile lang/tcc/files patch-libtcc.c Added files: lang/tcc/files README.tccelf patch-tccelf.c Log: - fix segfaults for linked elfs binaries PR: 138481 Submitted by: Luigi Rizzo Revision Changes Path 1.13 +1 -0 ports/lang/tcc/Makefile 1.1 +43 -0 ports/lang/tcc/files/README.tccelf (new) 1.2 +32 -2 ports/lang/tcc/files/patch-libtcc.c 1.1 +175 -0 ports/lang/tcc/files/patch-tccelf.c (new) _______________________________________________ cvs-all@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/cvs-all To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
State Changed From-To: analyzed->closed committed, thank you very much for the work.