[Tinycc-devel] Re: Only load libtcc1 if available
"Thomas Preud'homme" wrote > libtcc1.a isn't built on arm architecture but tcc_add_runtime add libtcc1.a > unconditionally. I used a macro to not load libtcc1.a on arm but a replacement > of tcc_add_file by something like : libtcc1.a wasn't being built on Linux either, so my mob branch patches started building it as tcc1.def (It's really libtcc1.a renamed to tcc1.def). This is working well for me building windows executables because i386-win32-tcc looks for tcc1.def first, as proven by $ i386-win32-tcc fib.c -vvv (shows that i386-win32-tcc is looking for tcc1.def. If it does not find tcc1.def it looks for libtcc1.a) It should work on ARM as well, but I don't have ARM to test with. If it is building tcc1.def for you then you can use that I think. Cross-compiling 32 bit windows programs (on Linux): The problem with libtcc1.a (tcc1.def) is it is difficult to build without windows because it contains ELF objects and so it is built with 32 bit version of i386-win32-tcc (renamed to tcc.exe on Linux). I tried building it with 64 bit version of i386-win32-tcc but the resulting libtcc1.a did not work. It's a big hack, building libtcc1.a, so I put it last in the Makefile and made it recursive. That way if it doesn't build, it won't matter too much. Cross-compiling 64 bit windows programs (on Linux): Now, apparently, a 64 bit version of libtcc1.a (tcc1.def) needs to be built if x86_64-win32-tcc is to be used to build 64 bit windows files on Linux. I get "tcc1.def: error: invalid object file" when I try to use my 32 bit tcc1.def with the 64 bit x86_64-win32-tcc. Luckily 32 bit windows programs work just fine on 64 bit windows, so nobody is really asking for 64 bit cross-compiler yet. And I'm going fishing for the Summer, so I probably won't get around to it for a while. :) ___ Tinycc-devel mailing list Tinycc-devel@nongnu.org http://lists.nongnu.org/mailman/listinfo/tinycc-devel
[Tinycc-devel] re: latest mob Makefile and LIBS=.
The LIBS=. line was left over from experimental work on --disable-static, sorry. It has been removed. I think everything is back to normal. I tried to make all the changes atomic, but it looks like that one got out of the box. ___ Tinycc-devel mailing list Tinycc-devel@nongnu.org http://lists.nongnu.org/mailman/listinfo/tinycc-devel
[Tinycc-devel] A program that uses the new dynamic tcc library
I thought you might find this interesting. I've made a pseudocode compiler and learning aid that integrates with TCC, but doesn't depend on it. If I can get TCC into Fedora, I plan to eventually use the new dynamic library, libtcc.so at runtime instead of wrapping "tcc -run" with a script like it does now. http://anch.org/anchor.html ___ Tinycc-devel mailing list Tinycc-devel@nongnu.org http://lists.nongnu.org/mailman/listinfo/tinycc-devel
[Tinycc-devel] re: Selinux patch fixup
I was a really bad coder. Sorry. I get it working first, then go back and find out how to do it standardly. I think this last push fixed up most of the major problems in my branch. This brings things in line with the Fedora rpm I'm building. http://thenerdshow.com/rpm/tinycc-git20100114-2.fc13.src.rpm ___ Tinycc-devel mailing list Tinycc-devel@nongnu.org http://lists.nongnu.org/mailman/listinfo/tinycc-devel
[Tinycc-devel] Selinux patch fixup.
I fixed my selinux patch, so it's better integrated into the way tcc does things. It was really quite terrible. Now it works with programs that use libtcc, if ever there be ones... I also pushed a script to build a win32 version of libtcc1.a for cross-compiling on x86 and x86_64 arch. And another patch for making a shared lib, libtcc.so.1 which has not made it into the install: target yet. I need to add simlinks to it as well. My distro wants shared, not static libs. Too busy to finish and my folks think I'm spending way too much time on the computer, so I hope this will at least give somebody ideas. :) ___ Tinycc-devel mailing list Tinycc-devel@nongnu.org http://lists.nongnu.org/mailman/listinfo/tinycc-devel
[Tinycc-devel] Selinux support added
I recently committed a patch to the mob branch for Selinux compatibility using information obtained from http://people.redhat.com/drepper/selinux-mem.html Selinux is a security package that is installed by default on Fedora. TCC -run segfaults on Fedora because Selinux prevents writing and executing the same block of memory. This patch replaces tcc_run's call to malloc with mmap as described in the above link. A copy of the patch is attached for your perusal. diff --git a/configure b/configure index f80eb40..f9b91a7 100755 --- a/configure +++ b/configure @@ -130,6 +130,8 @@ for opt do ;; --with-libgcc) use_libgcc="yes" ;; + --with-selinux) have_selinux="yes" + ;; --help|-h) show_help="yes" ;; esac @@ -229,7 +231,9 @@ echo " --cross-prefix=PREFIXuse PREFIX for compile tools [$cross_prefix]" echo " --sysroot=PREFIX prepend PREFIX to library/include paths []" echo " --cc=CC use C compiler CC [$cc]" echo " --with-libgccuse /lib/libgcc_s.so.1 instead of libtcc1.a" -echo "" +echo " --with-selinux use mmap instead of exec mem" +echo " [needs +wx perms. on /tmp]" +echo "" #echo "NOTE: The object files are build at the place where configure is launched" exit 1 fi @@ -357,6 +360,10 @@ if test "$use_libgcc" = "yes" ; then echo "#define CONFIG_USE_LIBGCC" >> $TMPH echo "CONFIG_USE_LIBGCC=yes" >> config.mak fi +if test "$have_selinux" = "yes" ; then + echo "#define HAVE_SELINUX" >> $TMPH + echo "HAVE_SELINUX=yes" >> config.mak +fi version=`head $source_path/VERSION` echo "VERSION=$version" >>config.mak echo "#define TCC_VERSION \"$version\"" >> $TMPH diff --git a/tccrun.c b/tccrun.c index 25f2477..f2946a0 100644 --- a/tccrun.c +++ b/tccrun.c @@ -50,10 +50,34 @@ int tcc_relocate(TCCState *s1) int tcc_run(TCCState *s1, int argc, char **argv) { int (*prog_main)(int, char **); - +int ret; +#ifdef HAVE_SELINUX +int rret; +void *ptr,*writep; +char tmpfname[] = "/tmp/.tccrunXX"; +int fd = mkstemp (tmpfname); +unlink (tmpfname); +ftruncate (fd, 1000); + if ((rret= tcc_relocate_ex(s1,NULL)) < 0) + return -1; + /* Use mmap instead of malloc for Selinux */ + writep = mmap (NULL, rret, PROT_READ|PROT_WRITE, +MAP_SHARED, fd, 0); +if(writep == MAP_FAILED){ +error("/tmp not writeable"); +return -1; + } +ptr = mmap (NULL, rret, PROT_READ|PROT_EXEC, +MAP_SHARED, fd, 0); + if(ptr == MAP_FAILED){ +error("/tmp not executable"); +return -1; + } +tcc_relocate_ex(s1, writep); +#else if (tcc_relocate(s1) < 0) return -1; - +#endif prog_main = tcc_get_symbol_err(s1, "main"); #ifdef CONFIG_TCC_BACKTRACE @@ -65,7 +89,6 @@ int tcc_run(TCCState *s1, int argc, char **argv) if (s1->do_bounds_check) { void (*bound_init)(void); void (*bound_exit)(void); -int ret; /* set error function */ rt_bound_error_msg = tcc_get_symbol_err(s1, "__bound_error_msg"); rt_prog_main = prog_main; @@ -85,7 +108,13 @@ int tcc_run(TCCState *s1, int argc, char **argv) if (p) *p = 0; } #endif -return (*prog_main)(argc, argv); +ret=(*prog_main)(argc, argv); +#ifdef HAVE_SELINUX +munmap (writep, rret); +munmap (ptr, rret); + +#endif +return ret; } ___ Tinycc-devel mailing list Tinycc-devel@nongnu.org http://lists.nongnu.org/mailman/listinfo/tinycc-devel