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 <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

View File

@ -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);

3
tcc.h
View File

@ -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)

View File

@ -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

View File

@ -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];