mirror of
https://github.com/mirror/tinycc.git
synced 2025-01-15 05:20:06 +08:00
FreeBSD fixes - file type guessing - glibc2.2 fixes - ELF align issue
This commit is contained in:
parent
b5259da4f2
commit
4df76253ad
46
tcc.c
46
tcc.c
@ -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 @@ static const char *tcc_keywords =
|
||||
#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 @@ void save_reg(int r)
|
||||
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 @@ void vpop(void)
|
||||
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 @@ int tcc_compile_string(TCCState *s, const char *str)
|
||||
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 @@ static void rt_printline(unsigned long wanted_pc)
|
||||
|
||||
#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 @@ static int rt_get_caller_pc(unsigned long *paddr,
|
||||
#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 @@ void rt_error(struct ucontext *uc, const char *fmt, ...)
|
||||
/* 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 @@ int tcc_run(TCCState *s1, int argc, char **argv)
|
||||
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 @@ int tcc_add_sysinclude_path(TCCState *s1, const char *pathname)
|
||||
|
||||
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 @@ static int64_t getclock_us(void)
|
||||
|
||||
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"
|
||||
|
Loading…
Reference in New Issue
Block a user