Add support for kfreebsd-i386 and kfreebsd-amd64 Debian arch with thanks to Pierre Chifflier <chifflier@cpe.fr>.
Unified · Split
| @@ -21,7 +21,8 @@ · 20 unmodified lines | ||
| 21 | 21 | #include <stdio.h> |
| 22 | 22 | #include <stdarg.h> |
| 23 | 23 | #include <string.h> |
| 24 | −#if !defined(__FreeBSD__) && !defined(__DragonFly__) && !defined(__OpenBSD__) | |
| 24 | +#if !defined(__FreeBSD__) && !defined(__FreeBSD_kernel__) \ | |
| 25 | + && !defined(__DragonFly__) && !defined(__OpenBSD__) | |
| 25 | 26 | #include <malloc.h> |
| 26 | 27 | #endif |
| 27 | 28 | |
| @@ -35,7 +36,8 @@ · 7 unmodified lines | ||
| 35 | 36 | #define CONFIG_TCC_MALLOC_HOOKS |
| 36 | 37 | #define HAVE_MEMALIGN |
| 37 | 38 | |
| 38 | −#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(__dietlibc__) \ | |
| 39 | +#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \ | |
| 40 | + || defined(__DragonFly__) || defined(__dietlibc__) \ | |
| 39 | 41 | || defined(__UCLIBC__) || defined(__OpenBSD__) || defined(_WIN32) |
| 40 | 42 | #warning Bound checking does not support malloc (etc.) in this environment. |
| 41 | 43 | #undef CONFIG_TCC_MALLOC_HOOKS |
| @@ -943,6 +943,9 @@ LIBTCCAPI TCCState *tcc_new(void) · 942 unmodified lines | ||
| 943 | 943 | tcc_define_symbol(s, "__FreeBSD__", str( __FreeBSD__)); |
| 944 | 944 | #undef str |
| 945 | 945 | #endif |
| 946 | +#if defined(__FreeBSD_kernel__) | |
| 947 | + tcc_define_symbol(s, "__FreeBSD_kernel__", NULL); | |
| 948 | +#endif | |
| 946 | 949 | #if defined(__linux) |
| 947 | 950 | tcc_define_symbol(s, "__linux__", NULL); |
| 948 | 951 | tcc_define_symbol(s, "__linux", NULL); |
| @@ -808,7 +808,8 @@ enum tcc_token { · 807 unmodified lines | ||
| 808 | 808 | #define strtof (float)strtod |
| 809 | 809 | #define strtoll (long long)strtol |
| 810 | 810 | #endif |
| 811 | −#elif defined(TCC_UCLIBC) || defined(__FreeBSD__) || defined(__DragonFly__) \ | |
| 811 | +#elif defined(TCC_UCLIBC) || defined(__FreeBSD__) \ | |
| 812 | + || defined(__FreeBSD_kernel__) || defined(__DragonFly__) \ | |
| 812 | 813 | || defined(__OpenBSD__) |
| 813 | 814 | /* currently incorrect */ |
| 814 | 815 | static inline long double strtold(const char *nptr, char **endptr) |
| @@ -1332,6 +1332,8 @@ ST_FUNC void tcc_add_linker_symbols(TCCState *s1) · 1331 unmodified lines | ||
| 1332 | 1332 | /* name of ELF interpreter */ |
| 1333 | 1333 | #if defined __FreeBSD__ |
| 1334 | 1334 | static const char elf_interp[] = "/libexec/ld-elf.so.1"; |
| 1335 | +#elif defined __FreeBSD_kernel__ | |
| 1336 | +static char elf_interp[] = "/lib/ld.so.1"; | |
| 1335 | 1337 | #elif defined TCC_ARM_EABI |
| 1336 | 1338 | static const char elf_interp[] = "/lib/ld-linux.so.3"; |
| 1337 | 1339 | #elif defined(TCC_TARGET_X86_64) |
| @@ -1368,7 +1370,7 @@ static void tcc_output_binary(TCCState *s1, FILE *f, · 30 unmodified lines | ||
| 1368 | 1370 | } |
| 1369 | 1371 | } |
| 1370 | 1372 | |
| 1371 | −#if defined(__FreeBSD__) | |
| 1373 | +#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) | |
| 1372 | 1374 | #define HAVE_PHDR 1 |
| 1373 | 1375 | #define EXTRA_RELITEMS 14 |
| 1374 | 1376 | |
| @@ -1851,7 +1853,7 @@ static int elf_output_file(TCCState *s1, const char *filename) · 476 unmodified lines | ||
| 1851 | 1853 | } |
| 1852 | 1854 | /* update dynamic relocation infos */ |
| 1853 | 1855 | if (s->sh_type == SHT_RELX) { |
| 1854 | −#if defined(__FreeBSD__) | |
| 1856 | +#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) | |
| 1855 | 1857 | if (!strcmp(strsec->data + s->sh_name, ".rel.got")) { // rel_size == 0) { |
| 1856 | 1858 | rel_addr = addr; |
| 1857 | 1859 | rel_size += s->sh_size; // XXX only first rel. |
| @@ -1892,7 +1894,7 @@ static int elf_output_file(TCCState *s1, const char *filename) · 34 unmodified lines | ||
| 1892 | 1894 | if (interp) { |
| 1893 | 1895 | ph = &phdr[0]; |
| 1894 | 1896 | |
| 1895 | −#if defined(__FreeBSD__) | |
| 1897 | +#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) | |
| 1896 | 1898 | { |
| 1897 | 1899 | int len = phnum * sizeof(ElfW(Phdr)); |
| 1898 | 1900 | |
| @@ -2007,7 +2009,7 @@ static int elf_output_file(TCCState *s1, const char *filename) · 108 unmodified lines | ||
| 2007 | 2009 | put_dt(dynamic, DT_RELASZ, rel_size); |
| 2008 | 2010 | put_dt(dynamic, DT_RELAENT, sizeof(ElfW_Rel)); |
| 2009 | 2011 | #else |
| 2010 | −#if defined(__FreeBSD__) | |
| 2012 | +#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) | |
| 2011 | 2013 | put_dt(dynamic, DT_PLTGOT, s1->got->sh_addr); |
| 2012 | 2014 | put_dt(dynamic, DT_PLTRELSZ, rel_size); |
| 2013 | 2015 | put_dt(dynamic, DT_JMPREL, rel_addr); |
| @@ -2115,7 +2117,7 @@ static int elf_output_file(TCCState *s1, const char *filename) · 101 unmodified lines | ||
| 2115 | 2117 | ehdr.e_ident[4] = TCC_ELFCLASS; |
| 2116 | 2118 | ehdr.e_ident[5] = ELFDATA2LSB; |
| 2117 | 2119 | ehdr.e_ident[6] = EV_CURRENT; |
| 2118 | −#ifdef __FreeBSD__ | |
| 2120 | +#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) | |
| 2119 | 2121 | ehdr.e_ident[EI_OSABI] = ELFOSABI_FREEBSD; |
| 2120 | 2122 | #endif |
| 2121 | 2123 | #ifdef TCC_TARGET_ARM |
| @@ -2153,7 +2155,7 @@ static int elf_output_file(TCCState *s1, const char *filename) · 31 unmodified lines | ||
| 2153 | 2155 | for(i=1;i<s1->nb_sections;i++) { |
| 2154 | 2156 | s = s1->sections[section_order[i]]; |
| 2155 | 2157 | if (s->sh_type != SHT_NOBITS) { |
| 2156 | −#if defined(__FreeBSD__) | |
| 2158 | +#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) | |
| 2157 | 2159 | if (s->sh_type == SHT_DYNSYM) |
| 2158 | 2160 | patch_dynsym_undef(s1, s); |
| 2159 | 2161 | #endif |
| @@ -438,7 +438,7 @@ static int rt_get_caller_pc(unsigned long *paddr, ucontext_t *uc, int level) · 437 unmodified lines | ||
| 438 | 438 | int i; |
| 439 | 439 | |
| 440 | 440 | if (level == 0) { |
| 441 | −#if defined(__FreeBSD__) | |
| 441 | +#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) | |
| 442 | 442 | *paddr = uc->uc_mcontext.mc_eip; |
| 443 | 443 | #elif defined(__dietlibc__) |
| 444 | 444 | *paddr = uc->uc_mcontext.eip; |
| @@ -447,7 +447,7 @@ static int rt_get_caller_pc(unsigned long *paddr, ucontext_t *uc, int level) · 2 unmodified lines | ||
| 447 | 447 | #endif |
| 448 | 448 | return 0; |
| 449 | 449 | } else { |
| 450 | −#if defined(__FreeBSD__) | |
| 450 | +#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) | |
| 451 | 451 | fp = uc->uc_mcontext.mc_ebp; |
| 452 | 452 | #elif defined(__dietlibc__) |
| 453 | 453 | fp = uc->uc_mcontext.ebp; |
| @@ -477,14 +477,14 @@ static int rt_get_caller_pc(unsigned long *paddr, · 23 unmodified lines | ||
| 477 | 477 | |
| 478 | 478 | if (level == 0) { |
| 479 | 479 | /* XXX: only support linux */ |
| 480 | −#if defined(__FreeBSD__) | |
| 480 | +#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) | |
| 481 | 481 | *paddr = uc->uc_mcontext.mc_rip; |
| 482 | 482 | #else |
| 483 | 483 | *paddr = uc->uc_mcontext.gregs[REG_RIP]; |
| 484 | 484 | #endif |
| 485 | 485 | return 0; |
| 486 | 486 | } else { |
| 487 | −#if defined(__FreeBSD__) | |
| 487 | +#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) | |
| 488 | 488 | fp = uc->uc_mcontext.mc_rbp; |
| 489 | 489 | #else |
| 490 | 490 | fp = uc->uc_mcontext.gregs[REG_RBP]; |