Add support for __FreeBSD_kernel__ kernel

Add support for kfreebsd-i386 and kfreebsd-amd64 Debian arch with
thanks to Pierre Chifflier <chifflier@cpe.fr>.
This commit is contained in:
Thomas Preud'homme 2010-09-10 21:09:07 +02:00
parent 2887f40f76
commit 776364f395
5 changed files with 21 additions and 13 deletions

View File

@ -21,7 +21,8 @@
#include <stdio.h> #include <stdio.h>
#include <stdarg.h> #include <stdarg.h>
#include <string.h> #include <string.h>
#if !defined(__FreeBSD__) && !defined(__DragonFly__) && !defined(__OpenBSD__) #if !defined(__FreeBSD__) && !defined(__FreeBSD_kernel__) \
&& !defined(__DragonFly__) && !defined(__OpenBSD__)
#include <malloc.h> #include <malloc.h>
#endif #endif
@ -35,7 +36,8 @@
#define CONFIG_TCC_MALLOC_HOOKS #define CONFIG_TCC_MALLOC_HOOKS
#define HAVE_MEMALIGN #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) || defined(__UCLIBC__) || defined(__OpenBSD__) || defined(_WIN32)
#warning Bound checking does not support malloc (etc.) in this environment. #warning Bound checking does not support malloc (etc.) in this environment.
#undef CONFIG_TCC_MALLOC_HOOKS #undef CONFIG_TCC_MALLOC_HOOKS

View File

@ -943,6 +943,9 @@ LIBTCCAPI TCCState *tcc_new(void)
tcc_define_symbol(s, "__FreeBSD__", str( __FreeBSD__)); tcc_define_symbol(s, "__FreeBSD__", str( __FreeBSD__));
#undef str #undef str
#endif #endif
#if defined(__FreeBSD_kernel__)
tcc_define_symbol(s, "__FreeBSD_kernel__", NULL);
#endif
#if defined(__linux) #if defined(__linux)
tcc_define_symbol(s, "__linux__", NULL); tcc_define_symbol(s, "__linux__", NULL);
tcc_define_symbol(s, "__linux", NULL); tcc_define_symbol(s, "__linux", NULL);

3
tcc.h
View File

@ -808,7 +808,8 @@ enum tcc_token {
#define strtof (float)strtod #define strtof (float)strtod
#define strtoll (long long)strtol #define strtoll (long long)strtol
#endif #endif
#elif defined(TCC_UCLIBC) || defined(__FreeBSD__) || defined(__DragonFly__) \ #elif defined(TCC_UCLIBC) || defined(__FreeBSD__) \
|| defined(__FreeBSD_kernel__) || defined(__DragonFly__) \
|| defined(__OpenBSD__) || defined(__OpenBSD__)
/* currently incorrect */ /* currently incorrect */
static inline long double strtold(const char *nptr, char **endptr) static inline long double strtold(const char *nptr, char **endptr)

View File

@ -1332,6 +1332,8 @@ ST_FUNC void tcc_add_linker_symbols(TCCState *s1)
/* name of ELF interpreter */ /* name of ELF interpreter */
#if defined __FreeBSD__ #if defined __FreeBSD__
static const char elf_interp[] = "/libexec/ld-elf.so.1"; 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 #elif defined TCC_ARM_EABI
static const char elf_interp[] = "/lib/ld-linux.so.3"; static const char elf_interp[] = "/lib/ld-linux.so.3";
#elif defined(TCC_TARGET_X86_64) #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 HAVE_PHDR 1
#define EXTRA_RELITEMS 14 #define EXTRA_RELITEMS 14
@ -1851,7 +1853,7 @@ static int elf_output_file(TCCState *s1, const char *filename)
} }
/* update dynamic relocation infos */ /* update dynamic relocation infos */
if (s->sh_type == SHT_RELX) { 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) { if (!strcmp(strsec->data + s->sh_name, ".rel.got")) { // rel_size == 0) {
rel_addr = addr; rel_addr = addr;
rel_size += s->sh_size; // XXX only first rel. 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) { if (interp) {
ph = &phdr[0]; ph = &phdr[0];
#if defined(__FreeBSD__) #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
{ {
int len = phnum * sizeof(ElfW(Phdr)); 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_RELASZ, rel_size);
put_dt(dynamic, DT_RELAENT, sizeof(ElfW_Rel)); put_dt(dynamic, DT_RELAENT, sizeof(ElfW_Rel));
#else #else
#if defined(__FreeBSD__) #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
put_dt(dynamic, DT_PLTGOT, s1->got->sh_addr); put_dt(dynamic, DT_PLTGOT, s1->got->sh_addr);
put_dt(dynamic, DT_PLTRELSZ, rel_size); put_dt(dynamic, DT_PLTRELSZ, rel_size);
put_dt(dynamic, DT_JMPREL, rel_addr); 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[4] = TCC_ELFCLASS;
ehdr.e_ident[5] = ELFDATA2LSB; ehdr.e_ident[5] = ELFDATA2LSB;
ehdr.e_ident[6] = EV_CURRENT; ehdr.e_ident[6] = EV_CURRENT;
#ifdef __FreeBSD__ #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
ehdr.e_ident[EI_OSABI] = ELFOSABI_FREEBSD; ehdr.e_ident[EI_OSABI] = ELFOSABI_FREEBSD;
#endif #endif
#ifdef TCC_TARGET_ARM #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++) { for(i=1;i<s1->nb_sections;i++) {
s = s1->sections[section_order[i]]; s = s1->sections[section_order[i]];
if (s->sh_type != SHT_NOBITS) { if (s->sh_type != SHT_NOBITS) {
#if defined(__FreeBSD__) #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
if (s->sh_type == SHT_DYNSYM) if (s->sh_type == SHT_DYNSYM)
patch_dynsym_undef(s1, s); patch_dynsym_undef(s1, s);
#endif #endif

View File

@ -438,7 +438,7 @@ static int rt_get_caller_pc(unsigned long *paddr, ucontext_t *uc, int level)
int i; int i;
if (level == 0) { if (level == 0) {
#if defined(__FreeBSD__) #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
*paddr = uc->uc_mcontext.mc_eip; *paddr = uc->uc_mcontext.mc_eip;
#elif defined(__dietlibc__) #elif defined(__dietlibc__)
*paddr = uc->uc_mcontext.eip; *paddr = uc->uc_mcontext.eip;
@ -447,7 +447,7 @@ static int rt_get_caller_pc(unsigned long *paddr, ucontext_t *uc, int level)
#endif #endif
return 0; return 0;
} else { } else {
#if defined(__FreeBSD__) #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
fp = uc->uc_mcontext.mc_ebp; fp = uc->uc_mcontext.mc_ebp;
#elif defined(__dietlibc__) #elif defined(__dietlibc__)
fp = uc->uc_mcontext.ebp; fp = uc->uc_mcontext.ebp;
@ -477,14 +477,14 @@ static int rt_get_caller_pc(unsigned long *paddr,
if (level == 0) { if (level == 0) {
/* XXX: only support linux */ /* XXX: only support linux */
#if defined(__FreeBSD__) #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
*paddr = uc->uc_mcontext.mc_rip; *paddr = uc->uc_mcontext.mc_rip;
#else #else
*paddr = uc->uc_mcontext.gregs[REG_RIP]; *paddr = uc->uc_mcontext.gregs[REG_RIP];
#endif #endif
return 0; return 0;
} else { } else {
#if defined(__FreeBSD__) #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
fp = uc->uc_mcontext.mc_rbp; fp = uc->uc_mcontext.mc_rbp;
#else #else
fp = uc->uc_mcontext.gregs[REG_RBP]; fp = uc->uc_mcontext.gregs[REG_RBP];