aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Preud'homme <thomas.preudhomme@celest.fr>2010-09-10 21:09:07 +0200
committerThomas Preud'homme <thomas.preudhomme@celest.fr>2010-09-10 21:09:07 +0200
commit776364f395d786c4c27e1f7a49cbba38951d9820 (patch)
tree18b44c7021f8b96a055a2e6c65d7da779f7cbe89
parent2887f40f760b7d406422258bbdd6e8dc25696c59 (diff)
downloadtinycc-776364f395d786c4c27e1f7a49cbba38951d9820.tar.gz
tinycc-776364f395d786c4c27e1f7a49cbba38951d9820.tar.bz2
Add support for __FreeBSD_kernel__ kernel
Add support for kfreebsd-i386 and kfreebsd-amd64 Debian arch with thanks to Pierre Chifflier <chifflier@cpe.fr>.
-rw-r--r--lib/bcheck.c6
-rw-r--r--libtcc.c3
-rw-r--r--tcc.h3
-rw-r--r--tccelf.c14
-rw-r--r--tccrun.c8
5 files changed, 21 insertions, 13 deletions
diff --git a/lib/bcheck.c b/lib/bcheck.c
index 09f2a3a..9996649 100644
--- a/lib/bcheck.c
+++ b/lib/bcheck.c
@@ -21,7 +21,8 @@
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
-#if !defined(__FreeBSD__) && !defined(__DragonFly__) && !defined(__OpenBSD__)
+#if !defined(__FreeBSD__) && !defined(__FreeBSD_kernel__) \
+ && !defined(__DragonFly__) && !defined(__OpenBSD__)
#include <malloc.h>
#endif
@@ -35,7 +36,8 @@
#define CONFIG_TCC_MALLOC_HOOKS
#define HAVE_MEMALIGN
-#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(__dietlibc__) \
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \
+ || defined(__DragonFly__) || defined(__dietlibc__) \
|| defined(__UCLIBC__) || defined(__OpenBSD__) || defined(_WIN32)
#warning Bound checking does not support malloc (etc.) in this environment.
#undef CONFIG_TCC_MALLOC_HOOKS
diff --git a/libtcc.c b/libtcc.c
index a9920c3..a89ecc3 100644
--- a/libtcc.c
+++ b/libtcc.c
@@ -943,6 +943,9 @@ LIBTCCAPI TCCState *tcc_new(void)
tcc_define_symbol(s, "__FreeBSD__", str( __FreeBSD__));
#undef str
#endif
+#if defined(__FreeBSD_kernel__)
+ tcc_define_symbol(s, "__FreeBSD_kernel__", NULL);
+#endif
#if defined(__linux)
tcc_define_symbol(s, "__linux__", NULL);
tcc_define_symbol(s, "__linux", NULL);
diff --git a/tcc.h b/tcc.h
index d28d1ec..95a2efb 100644
--- a/tcc.h
+++ b/tcc.h
@@ -808,7 +808,8 @@ enum tcc_token {
#define strtof (float)strtod
#define strtoll (long long)strtol
#endif
-#elif defined(TCC_UCLIBC) || defined(__FreeBSD__) || defined(__DragonFly__) \
+#elif defined(TCC_UCLIBC) || defined(__FreeBSD__) \
+ || defined(__FreeBSD_kernel__) || defined(__DragonFly__) \
|| defined(__OpenBSD__)
/* currently incorrect */
static inline long double strtold(const char *nptr, char **endptr)
diff --git a/tccelf.c b/tccelf.c
index e5603eb..c93955b 100644
--- a/tccelf.c
+++ b/tccelf.c
@@ -1332,6 +1332,8 @@ ST_FUNC void tcc_add_linker_symbols(TCCState *s1)
/* name of ELF interpreter */
#if defined __FreeBSD__
static const char elf_interp[] = "/libexec/ld-elf.so.1";
+#elif defined __FreeBSD_kernel__
+static char elf_interp[] = "/lib/ld.so.1";
#elif defined TCC_ARM_EABI
static const char elf_interp[] = "/lib/ld-linux.so.3";
#elif defined(TCC_TARGET_X86_64)
@@ -1368,7 +1370,7 @@ static void tcc_output_binary(TCCState *s1, FILE *f,
}
}
-#if defined(__FreeBSD__)
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
#define HAVE_PHDR 1
#define EXTRA_RELITEMS 14
@@ -1851,7 +1853,7 @@ static int elf_output_file(TCCState *s1, const char *filename)
}
/* update dynamic relocation infos */
if (s->sh_type == SHT_RELX) {
-#if defined(__FreeBSD__)
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
if (!strcmp(strsec->data + s->sh_name, ".rel.got")) { // rel_size == 0) {
rel_addr = addr;
rel_size += s->sh_size; // XXX only first rel.
@@ -1892,7 +1894,7 @@ static int elf_output_file(TCCState *s1, const char *filename)
if (interp) {
ph = &phdr[0];
-#if defined(__FreeBSD__)
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
{
int len = phnum * sizeof(ElfW(Phdr));
@@ -2007,7 +2009,7 @@ static int elf_output_file(TCCState *s1, const char *filename)
put_dt(dynamic, DT_RELASZ, rel_size);
put_dt(dynamic, DT_RELAENT, sizeof(ElfW_Rel));
#else
-#if defined(__FreeBSD__)
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
put_dt(dynamic, DT_PLTGOT, s1->got->sh_addr);
put_dt(dynamic, DT_PLTRELSZ, rel_size);
put_dt(dynamic, DT_JMPREL, rel_addr);
@@ -2115,7 +2117,7 @@ static int elf_output_file(TCCState *s1, const char *filename)
ehdr.e_ident[4] = TCC_ELFCLASS;
ehdr.e_ident[5] = ELFDATA2LSB;
ehdr.e_ident[6] = EV_CURRENT;
-#ifdef __FreeBSD__
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
ehdr.e_ident[EI_OSABI] = ELFOSABI_FREEBSD;
#endif
#ifdef TCC_TARGET_ARM
@@ -2153,7 +2155,7 @@ static int elf_output_file(TCCState *s1, const char *filename)
for(i=1;i<s1->nb_sections;i++) {
s = s1->sections[section_order[i]];
if (s->sh_type != SHT_NOBITS) {
-#if defined(__FreeBSD__)
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
if (s->sh_type == SHT_DYNSYM)
patch_dynsym_undef(s1, s);
#endif
diff --git a/tccrun.c b/tccrun.c
index e24d95e..c45aeb6 100644
--- a/tccrun.c
+++ b/tccrun.c
@@ -438,7 +438,7 @@ static int rt_get_caller_pc(unsigned long *paddr, ucontext_t *uc, int level)
int i;
if (level == 0) {
-#if defined(__FreeBSD__)
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
*paddr = uc->uc_mcontext.mc_eip;
#elif defined(__dietlibc__)
*paddr = uc->uc_mcontext.eip;
@@ -447,7 +447,7 @@ static int rt_get_caller_pc(unsigned long *paddr, ucontext_t *uc, int level)
#endif
return 0;
} else {
-#if defined(__FreeBSD__)
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
fp = uc->uc_mcontext.mc_ebp;
#elif defined(__dietlibc__)
fp = uc->uc_mcontext.ebp;
@@ -477,14 +477,14 @@ static int rt_get_caller_pc(unsigned long *paddr,
if (level == 0) {
/* XXX: only support linux */
-#if defined(__FreeBSD__)
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
*paddr = uc->uc_mcontext.mc_rip;
#else
*paddr = uc->uc_mcontext.gregs[REG_RIP];
#endif
return 0;
} else {
-#if defined(__FreeBSD__)
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
fp = uc->uc_mcontext.mc_rbp;
#else
fp = uc->uc_mcontext.gregs[REG_RBP];