Unified · Split
| @@ -17,6 +17,7 @@ · 16 unmodified lines | ||
| 17 | 17 | * along with this program; if not, write to the Free Software |
| 18 | 18 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 19 | 19 | */ |
| 20 | +#define _GNU_SOURCE | |
| 20 | 21 | #include <stdlib.h> |
| 21 | 22 | #include <stdio.h> |
| 22 | 23 | #include <stdarg.h> |
| @@ -534,7 +535,7 @@ static const char *tcc_keywords = · 511 unmodified lines | ||
| 534 | 535 | #define vsnprintf _vsnprintf |
| 535 | 536 | #endif |
| 536 | 537 | |
| 537 | −#if defined(WIN32) || defined(TCC_UCLIBC) | |
| 538 | +#if defined(WIN32) || defined(TCC_UCLIBC) || defined(__FreeBSD__) | |
| 538 | 539 | /* currently incorrect */ |
| 539 | 540 | long double strtold(const char *nptr, char **endptr) |
| 540 | 541 | { |
| @@ -3985,7 +3986,7 @@ void save_reg(int r) · 3444 unmodified lines | ||
| 3985 | 3986 | store(r, &sv); |
| 3986 | 3987 | #ifdef TCC_TARGET_I386 |
| 3987 | 3988 | /* x86 specific: need to pop fp register ST0 if saved */ |
| 3988 | − if (r == REG_ST0) { | |
| 3989 | + if (r == TREG_ST0) { | |
| 3989 | 3990 | o(0xd9dd); /* fstp %st(1) */ |
| 3990 | 3991 | } |
| 3991 | 3992 | #endif |
| @@ -4316,7 +4317,7 @@ void vpop(void) · 324 unmodified lines | ||
| 4316 | 4317 | v = vtop->r & VT_VALMASK; |
| 4317 | 4318 | #ifdef TCC_TARGET_I386 |
| 4318 | 4319 | /* for x86, we need to pop the FP stack */ |
| 4319 | − if (v == REG_ST0 && !nocode_wanted) { | |
| 4320 | + if (v == TREG_ST0 && !nocode_wanted) { | |
| 4320 | 4321 | o(0xd9dd); /* fstp %st(1) */ |
| 4321 | 4322 | } else |
| 4322 | 4323 | #endif |
| @@ -8152,6 +8153,7 @@ int tcc_compile_string(TCCState *s, const char *str) · 3829 unmodified lines | ||
| 8152 | 8153 | buf = tcc_malloc(len + 1); |
| 8153 | 8154 | if (!buf) |
| 8154 | 8155 | return -1; |
| 8156 | + memcpy(buf, str, len); | |
| 8155 | 8157 | buf[len] = CH_EOB; |
| 8156 | 8158 | bf->buf_ptr = buf; |
| 8157 | 8159 | bf->buf_end = buf + len; |
| @@ -8338,23 +8340,32 @@ static void rt_printline(unsigned long wanted_pc) · 180 unmodified lines | ||
| 8338 | 8340 | |
| 8339 | 8341 | #ifdef __i386__ |
| 8340 | 8342 | |
| 8341 | −#ifndef EIP | |
| 8342 | −#define EIP 14 | |
| 8343 | −#define EBP 6 | |
| 8343 | +/* fix for glibc 2.1 */ | |
| 8344 | +#ifndef REG_EIP | |
| 8345 | +#define REG_EIP EIP | |
| 8346 | +#define REG_EBP EBP | |
| 8344 | 8347 | #endif |
| 8345 | 8348 | |
| 8346 | 8349 | /* return the PC at frame level 'level'. Return non zero if not found */ |
| 8347 | 8350 | static int rt_get_caller_pc(unsigned long *paddr, |
| 8348 | − struct ucontext *uc, int level) | |
| 8351 | + ucontext_t *uc, int level) | |
| 8349 | 8352 | { |
| 8350 | 8353 | unsigned long fp; |
| 8351 | 8354 | int i; |
| 8352 | 8355 | |
| 8353 | 8356 | if (level == 0) { |
| 8354 | − *paddr = uc->uc_mcontext.gregs[EIP]; | |
| 8357 | +#ifdef __FreeBSD__ | |
| 8358 | + *paddr = uc->uc_mcontext.mc_eip; | |
| 8359 | +#else | |
| 8360 | + *paddr = uc->uc_mcontext.gregs[REG_EIP]; | |
| 8361 | +#endif | |
| 8355 | 8362 | return 0; |
| 8356 | 8363 | } else { |
| 8357 | − fp = uc->uc_mcontext.gregs[EBP]; | |
| 8364 | +#ifdef __FreeBSD__ | |
| 8365 | + fp = uc->uc_mcontext.mc_ebp; | |
| 8366 | +#else | |
| 8367 | + fp = uc->uc_mcontext.gregs[REG_EBP]; | |
| 8368 | +#endif | |
| 8358 | 8369 | for(i=1;i<level;i++) { |
| 8359 | 8370 | /* XXX: check address validity with program info */ |
| 8360 | 8371 | if (fp <= 0x1000 || fp >= 0xc0000000) |
| @@ -8370,7 +8381,7 @@ static int rt_get_caller_pc(unsigned long *paddr, · 9 unmodified lines | ||
| 8370 | 8381 | #endif |
| 8371 | 8382 | |
| 8372 | 8383 | /* emit a run time error at position 'pc' */ |
| 8373 | −void rt_error(struct ucontext *uc, const char *fmt, ...) | |
| 8384 | +void rt_error(ucontext_t *uc, const char *fmt, ...) | |
| 8374 | 8385 | { |
| 8375 | 8386 | va_list ap; |
| 8376 | 8387 | unsigned long pc; |
| @@ -8396,7 +8407,7 @@ void rt_error(struct ucontext *uc, const char *fmt, ...) · 19 unmodified lines | ||
| 8396 | 8407 | /* signal handler for fatal errors */ |
| 8397 | 8408 | static void sig_error(int signum, siginfo_t *siginf, void *puc) |
| 8398 | 8409 | { |
| 8399 | − struct ucontext *uc = puc; | |
| 8410 | + ucontext_t *uc = puc; | |
| 8400 | 8411 | |
| 8401 | 8412 | switch(signum) { |
| 8402 | 8413 | case SIGFPE: |
| @@ -8485,7 +8496,7 @@ int tcc_run(TCCState *s1, int argc, char **argv) · 82 unmodified lines | ||
| 8485 | 8496 | struct sigaction sigact; |
| 8486 | 8497 | /* install TCC signal handlers to print debug info on fatal |
| 8487 | 8498 | runtime errors */ |
| 8488 | − sigact.sa_flags = SA_SIGINFO | SA_ONESHOT; | |
| 8499 | + sigact.sa_flags = SA_SIGINFO | SA_RESETHAND; | |
| 8489 | 8500 | sigact.sa_sigaction = sig_error; |
| 8490 | 8501 | sigemptyset(&sigact.sa_mask); |
| 8491 | 8502 | sigaction(SIGFPE, &sigact, NULL); |
| @@ -8660,13 +8671,18 @@ int tcc_add_sysinclude_path(TCCState *s1, const char *pathname) · 168 unmodified lines | ||
| 8660 | 8671 | |
| 8661 | 8672 | static int tcc_add_file_internal(TCCState *s1, const char *filename, int flags) |
| 8662 | 8673 | { |
| 8663 | − const char *ext; | |
| 8674 | + const char *ext, *filename1; | |
| 8664 | 8675 | Elf32_Ehdr ehdr; |
| 8665 | 8676 | int fd, ret; |
| 8666 | 8677 | BufferedFile *saved_file; |
| 8667 | 8678 | |
| 8668 | 8679 | /* find source file type with extension */ |
| 8669 | − ext = strrchr(filename, '.'); | |
| 8680 | + filename1 = strrchr(filename, '/'); | |
| 8681 | + if (filename1) | |
| 8682 | + filename1++; | |
| 8683 | + else | |
| 8684 | + filename1 = filename; | |
| 8685 | + ext = strrchr(filename1, '.'); | |
| 8670 | 8686 | if (ext) |
| 8671 | 8687 | ext++; |
| 8672 | 8688 | |
| @@ -8857,7 +8873,7 @@ static int64_t getclock_us(void) · 184 unmodified lines | ||
| 8857 | 8873 | |
| 8858 | 8874 | void help(void) |
| 8859 | 8875 | { |
| 8860 | − printf("tcc version 0.9.14 - Tiny C Compiler - Copyright (C) 2001, 2002 Fabrice Bellard\n" | |
| 8876 | + printf("tcc version 0.9.15 - Tiny C Compiler - Copyright (C) 2001, 2002 Fabrice Bellard\n" | |
| 8861 | 8877 | "usage: tcc [-c] [-o outfile] [-Bdir] [-bench] [-Idir] [-Dsym[=val]] [-Usym]\n" |
| 8862 | 8878 | " [-g] [-b] [-bt N] [-Ldir] [-llib] [-shared] [-static]\n" |
| 8863 | 8879 | " [--] infile1 [infile2... --] [infile_args...]\n" |