changeset 211:aea76b59cbc3

[project @ 2002-12-08 14:35:31 by bellard] FreeBSD fixes - file type guessing - glibc2.2 fixes - ELF align issue
author bellard
date Sun, 08 Dec 2002 14:35:31 +0000
parents d0952d266352
children b106d9cd31dc
files tcc.c
diffstat 1 files changed, 31 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/tcc.c	Sun Dec 08 14:34:48 2002 +0000
+++ b/tcc.c	Sun Dec 08 14:35:31 2002 +0000
@@ -17,6 +17,7 @@
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
+#define _GNU_SOURCE
 #include <stdlib.h>
 #include <stdio.h>
 #include <stdarg.h>
@@ -534,7 +535,7 @@
 #define vsnprintf _vsnprintf
 #endif
 
-#if defined(WIN32) || defined(TCC_UCLIBC)
+#if defined(WIN32) || defined(TCC_UCLIBC) || defined(__FreeBSD__)
 /* currently incorrect */
 long double strtold(const char *nptr, char **endptr)
 {
@@ -3985,7 +3986,7 @@
                 store(r, &sv);
 #ifdef TCC_TARGET_I386
                 /* x86 specific: need to pop fp register ST0 if saved */
-                if (r == REG_ST0) {
+                if (r == TREG_ST0) {
                     o(0xd9dd); /* fstp %st(1) */
                 }
 #endif
@@ -4316,7 +4317,7 @@
     v = vtop->r & VT_VALMASK;
 #ifdef TCC_TARGET_I386
     /* for x86, we need to pop the FP stack */
-    if (v == REG_ST0 && !nocode_wanted) {
+    if (v == TREG_ST0 && !nocode_wanted) {
         o(0xd9dd); /* fstp %st(1) */
     } else
 #endif
@@ -8152,6 +8153,7 @@
     buf = tcc_malloc(len + 1);
     if (!buf)
         return -1;
+    memcpy(buf, str, len);
     buf[len] = CH_EOB;
     bf->buf_ptr = buf;
     bf->buf_end = buf + len;
@@ -8338,23 +8340,32 @@
 
 #ifdef __i386__
 
-#ifndef EIP
-#define EIP 14
-#define EBP 6
+/* fix for glibc 2.1 */
+#ifndef REG_EIP
+#define REG_EIP EIP
+#define REG_EBP EBP
 #endif
 
 /* return the PC at frame level 'level'. Return non zero if not found */
 static int rt_get_caller_pc(unsigned long *paddr, 
-                            struct ucontext *uc, int level)
+                            ucontext_t *uc, int level)
 {
     unsigned long fp;
     int i;
 
     if (level == 0) {
-        *paddr = uc->uc_mcontext.gregs[EIP];
+#ifdef __FreeBSD__
+        *paddr = uc->uc_mcontext.mc_eip;
+#else
+        *paddr = uc->uc_mcontext.gregs[REG_EIP];
+#endif
         return 0;
     } else {
-        fp = uc->uc_mcontext.gregs[EBP];
+#ifdef __FreeBSD__
+        fp = uc->uc_mcontext.mc_ebp;
+#else
+        fp = uc->uc_mcontext.gregs[REG_EBP];
+#endif
         for(i=1;i<level;i++) {
             /* XXX: check address validity with program info */
             if (fp <= 0x1000 || fp >= 0xc0000000)
@@ -8370,7 +8381,7 @@
 #endif
 
 /* emit a run time error at position 'pc' */
-void rt_error(struct ucontext *uc, const char *fmt, ...)
+void rt_error(ucontext_t *uc, const char *fmt, ...)
 {
     va_list ap;
     unsigned long pc;
@@ -8396,7 +8407,7 @@
 /* signal handler for fatal errors */
 static void sig_error(int signum, siginfo_t *siginf, void *puc)
 {
-    struct ucontext *uc = puc;
+    ucontext_t *uc = puc;
 
     switch(signum) {
     case SIGFPE:
@@ -8485,7 +8496,7 @@
         struct sigaction sigact;
         /* install TCC signal handlers to print debug info on fatal
            runtime errors */
-        sigact.sa_flags = SA_SIGINFO | SA_ONESHOT;
+        sigact.sa_flags = SA_SIGINFO | SA_RESETHAND;
         sigact.sa_sigaction = sig_error;
         sigemptyset(&sigact.sa_mask);
         sigaction(SIGFPE, &sigact, NULL);
@@ -8660,13 +8671,18 @@
 
 static int tcc_add_file_internal(TCCState *s1, const char *filename, int flags)
 {
-    const char *ext;
+    const char *ext, *filename1;
     Elf32_Ehdr ehdr;
     int fd, ret;
     BufferedFile *saved_file;
     
     /* find source file type with extension */
-    ext = strrchr(filename, '.');
+    filename1 = strrchr(filename, '/');
+    if (filename1)
+        filename1++;
+    else
+        filename1 = filename;
+    ext = strrchr(filename1, '.');
     if (ext)
         ext++;
 
@@ -8857,7 +8873,7 @@
 
 void help(void)
 {
-    printf("tcc version 0.9.14 - Tiny C Compiler - Copyright (C) 2001, 2002 Fabrice Bellard\n" 
+    printf("tcc version 0.9.15 - Tiny C Compiler - Copyright (C) 2001, 2002 Fabrice Bellard\n" 
            "usage: tcc [-c] [-o outfile] [-Bdir] [-bench] [-Idir] [-Dsym[=val]] [-Usym]\n"
            "           [-g] [-b] [-bt N] [-Ldir] [-llib] [-shared] [-static]\n"
            "           [--] infile1 [infile2... --] [infile_args...]\n"