History

FreeBSD fixes - file type guessing - glibc2.2 fixes - ELF align issue

bellard committed 23 years ago

Commit 4df76251 parent b5259da1 file · +31 −15Browse files

Unified · Split

tcc.c+31−15
@@ -17,6 +17,7 @@ · 16 unmodified lines
1717 * along with this program; if not, write to the Free Software
1818 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
1919 */
20+#define _GNU_SOURCE
2021 #include <stdlib.h>
2122 #include <stdio.h>
2223 #include <stdarg.h>
@@ -534,7 +535,7 @@ static const char *tcc_keywords = · 511 unmodified lines
534535 #define vsnprintf _vsnprintf
535536 #endif
536537
537−#if defined(WIN32) || defined(TCC_UCLIBC)
538+#if defined(WIN32) || defined(TCC_UCLIBC) || defined(__FreeBSD__)
538539 /* currently incorrect */
539540 long double strtold(const char *nptr, char **endptr)
540541 {
@@ -3985,7 +3986,7 @@ void save_reg(int r) · 3444 unmodified lines
39853986 store(r, &sv);
39863987 #ifdef TCC_TARGET_I386
39873988 /* x86 specific: need to pop fp register ST0 if saved */
3988− if (r == REG_ST0) {
3989+ if (r == TREG_ST0) {
39893990 o(0xd9dd); /* fstp %st(1) */
39903991 }
39913992 #endif
@@ -4316,7 +4317,7 @@ void vpop(void) · 324 unmodified lines
43164317 v = vtop->r & VT_VALMASK;
43174318 #ifdef TCC_TARGET_I386
43184319 /* for x86, we need to pop the FP stack */
4319− if (v == REG_ST0 && !nocode_wanted) {
4320+ if (v == TREG_ST0 && !nocode_wanted) {
43204321 o(0xd9dd); /* fstp %st(1) */
43214322 } else
43224323 #endif
@@ -8152,6 +8153,7 @@ int tcc_compile_string(TCCState *s, const char *str) · 3829 unmodified lines
81528153 buf = tcc_malloc(len + 1);
81538154 if (!buf)
81548155 return -1;
8156+ memcpy(buf, str, len);
81558157 buf[len] = CH_EOB;
81568158 bf->buf_ptr = buf;
81578159 bf->buf_end = buf + len;
@@ -8338,23 +8340,32 @@ static void rt_printline(unsigned long wanted_pc) · 180 unmodified lines
83388340
83398341 #ifdef __i386__
83408342
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
83448347 #endif
83458348
83468349 /* return the PC at frame level 'level'. Return non zero if not found */
83478350 static int rt_get_caller_pc(unsigned long *paddr,
8348− struct ucontext *uc, int level)
8351+ ucontext_t *uc, int level)
83498352 {
83508353 unsigned long fp;
83518354 int i;
83528355
83538356 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
83558362 return 0;
83568363 } 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
83588369 for(i=1;i<level;i++) {
83598370 /* XXX: check address validity with program info */
83608371 if (fp <= 0x1000 || fp >= 0xc0000000)
@@ -8370,7 +8381,7 @@ static int rt_get_caller_pc(unsigned long *paddr, · 9 unmodified lines
83708381 #endif
83718382
83728383 /* 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, ...)
83748385 {
83758386 va_list ap;
83768387 unsigned long pc;
@@ -8396,7 +8407,7 @@ void rt_error(struct ucontext *uc, const char *fmt, ...) · 19 unmodified lines
83968407 /* signal handler for fatal errors */
83978408 static void sig_error(int signum, siginfo_t *siginf, void *puc)
83988409 {
8399− struct ucontext *uc = puc;
8410+ ucontext_t *uc = puc;
84008411
84018412 switch(signum) {
84028413 case SIGFPE:
@@ -8485,7 +8496,7 @@ int tcc_run(TCCState *s1, int argc, char **argv) · 82 unmodified lines
84858496 struct sigaction sigact;
84868497 /* install TCC signal handlers to print debug info on fatal
84878498 runtime errors */
8488− sigact.sa_flags = SA_SIGINFO | SA_ONESHOT;
8499+ sigact.sa_flags = SA_SIGINFO | SA_RESETHAND;
84898500 sigact.sa_sigaction = sig_error;
84908501 sigemptyset(&sigact.sa_mask);
84918502 sigaction(SIGFPE, &sigact, NULL);
@@ -8660,13 +8671,18 @@ int tcc_add_sysinclude_path(TCCState *s1, const char *pathname) · 168 unmodified lines
86608671
86618672 static int tcc_add_file_internal(TCCState *s1, const char *filename, int flags)
86628673 {
8663− const char *ext;
8674+ const char *ext, *filename1;
86648675 Elf32_Ehdr ehdr;
86658676 int fd, ret;
86668677 BufferedFile *saved_file;
86678678
86688679 /* 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, '.');
86708686 if (ext)
86718687 ext++;
86728688
@@ -8857,7 +8873,7 @@ static int64_t getclock_us(void) · 184 unmodified lines
88578873
88588874 void help(void)
88598875 {
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"
88618877 "usage: tcc [-c] [-o outfile] [-Bdir] [-bench] [-Idir] [-Dsym[=val]] [-Usym]\n"
88628878 " [-g] [-b] [-bt N] [-Ldir] [-llib] [-shared] [-static]\n"
88638879 " [--] infile1 [infile2... --] [infile_args...]\n"

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t