Add support of musl-libc

The port is functional. Bound checking is not supported yet.
This commit is contained in:
Marc Vertes 2017-04-20 22:01:50 +02:00
parent 328b826e8a
commit 0ac29b53dc
8 changed files with 33 additions and 6 deletions

View File

@ -73,6 +73,7 @@ NATIVE_DEFINES_$(CONFIG_i386) += -DTCC_TARGET_I386
NATIVE_DEFINES_$(CONFIG_x86_64) += -DTCC_TARGET_X86_64
NATIVE_DEFINES_$(CONFIG_WIN32) += -DTCC_TARGET_PE
NATIVE_DEFINES_$(CONFIG_uClibc) += -DTCC_UCLIBC
NATIVE_DEFINES_$(CONFIG_musl) += -DTCC_MUSL
NATIVE_DEFINES_$(CONFIG_arm) += -DTCC_TARGET_ARM
NATIVE_DEFINES_$(CONFIG_arm_eabihf) += -DTCC_ARM_EABI -DTCC_ARM_HARDFLOAT
NATIVE_DEFINES_$(CONFIG_arm_eabi) += -DTCC_ARM_EABI

2
configure vendored
View File

@ -352,6 +352,8 @@ if test -z "$cross_prefix" ; then
if test -f "/lib/ld-uClibc.so.0" ; then
confvars="$confvars uClibc"
elif test -f "/lib/ld-musl-$cpu.so.1"; then
confvars="$confvars musl"
fi
fi
else

View File

@ -16,7 +16,11 @@ typedef struct {
char *reg_save_area;
} __va_list_struct;
/* Avoid conflicting definition for va_list on musl libc */
#ifndef __DEFINED_va_list
typedef __va_list_struct va_list[1];
#define __DEFINED_va_list
#endif
void __va_start(__va_list_struct *ap, void *fp);
void *__va_arg(__va_list_struct *ap, int arg_type, int size, int align);

View File

@ -30,6 +30,10 @@ ifeq ($(TARGETOS),Darwin)
BCHECK_O =
endif
ifeq ($(CONFIG_musl),yes)
BCHECK_O =
endif
I386_O = libtcc1.o alloca86.o alloca86-bt.o $(BCHECK_O)
X86_64_O = libtcc1.o alloca86_64.o alloca86_64-bt.o $(BCHECK_O)
ARM_O = libtcc1.o armeabi.o alloca-arm.o

View File

@ -48,7 +48,7 @@
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \
|| defined(__DragonFly__) || defined(__dietlibc__) \
|| defined(__UCLIBC__) || defined(__OpenBSD__) || defined(__NetBSD__) \
|| defined(_WIN32) || defined(TCC_UCLIBC)
|| defined(_WIN32) || defined(TCC_UCLIBC) || defined(TCC_MUSL)
//#warning Bound checking does not support malloc (etc.) in this environment.
#undef CONFIG_TCC_MALLOC_HOOKS
#undef HAVE_MEMALIGN

View File

@ -851,6 +851,10 @@ LIBTCCAPI TCCState *tcc_new(void)
tcc_define_symbol(s, "__ILP32__", NULL);
#endif
#if defined(TCC_MUSL)
tcc_define_symbol(s, "__builtin_va_list", "void *");
#endif /* TCC_MUSL */
#ifdef TCC_TARGET_PE
tcc_define_symbol(s, "__WCHAR_TYPE__", "unsigned short");
tcc_define_symbol(s, "__WINT_TYPE__", "unsigned short");

20
tcc.h
View File

@ -136,7 +136,7 @@
#if !defined(TCC_UCLIBC) && !defined(TCC_TARGET_ARM) && \
!defined(TCC_TARGET_ARM64) && !defined(TCC_TARGET_C67) && \
!defined(CONFIG_USE_LIBGCC)
!defined(CONFIG_USE_LIBGCC) && !defined(TCC_MUSL)
#define CONFIG_TCC_BCHECK /* enable bound checking code */
#endif
@ -239,11 +239,23 @@
# elif defined(TCC_UCLIBC)
# define CONFIG_TCC_ELFINTERP "/lib/ld-uClibc.so.0" /* is there a uClibc for x86_64 ? */
# elif defined TCC_TARGET_ARM64
# define CONFIG_TCC_ELFINTERP "/lib/ld-linux-aarch64.so.1"
# if defined(TCC_MUSL)
# define CONFIG_TCC_ELFINTERP "/lib/ld-musl-aarch64.so.1"
# else
# define CONFIG_TCC_ELFINTERP "/lib/ld-linux-aarch64.so.1"
# endif
# elif defined(TCC_TARGET_X86_64)
# define CONFIG_TCC_ELFINTERP "/lib64/ld-linux-x86-64.so.2"
# if defined(TCC_MUSL)
# define CONFIG_TCC_ELFINTERP "/lib/ld-musl-x86_64.so.1"
# else
# define CONFIG_TCC_ELFINTERP "/lib64/ld-linux-x86-64.so.2"
# endif
# elif !defined(TCC_ARM_EABI)
# define CONFIG_TCC_ELFINTERP "/lib/ld-linux.so.2"
# if defined(TCC_MUSL)
# define CONFIG_TCC_ELFINTERP "/lib/ld-musl-arm.so.1"
# else
# define CONFIG_TCC_ELFINTERP "/lib/ld-linux.so.2"
# endif
# endif
#endif

View File

@ -1718,7 +1718,7 @@ static int final_sections_reloc(TCCState *s1)
/* XXX: ignore sections with allocated relocations ? */
for(i = 1; i < s1->nb_sections; i++) {
s = s1->sections[i];
#ifdef TCC_TARGET_I386
#if defined(TCC_TARGET_I386) || defined(TCC_MUSL)
if (s->reloc && s != s1->got && (s->sh_flags & SHF_ALLOC)) //gr
/* On X86 gdb 7.3 works in any case but gdb 6.6 will crash if SHF_ALLOC
checking is removed */