Merge pull request #26 from stikonas/musl

Musl
This commit is contained in:
fosslinux 2021-02-04 21:40:08 +11:00 committed by GitHub
commit e9c8313458
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 428 additions and 16 deletions

View file

@ -6,6 +6,7 @@ cd src/mes-libc
# Patch
patch -Np0 -i ../../patches/mes-libc-qsort.patch
patch -Np0 -i ../../patches/mes-libc-crt1.patch
# Recompile libc
cd ../tcc-0.9.27

View file

@ -0,0 +1,15 @@
Ignore duplicate symbols. Due to poor support for weak symbols in tcc-ar
we had to patch musl to replace weak symbols with strong symbols
--- tccelf.c 2021-02-02 17:41:08.662247892 +0000
+++ tccelf.c 2021-02-02 23:21:49.652080201 +0000
@@ -552,8 +552,9 @@
#if 0
printf("new_bind=%x new_shndx=%x new_vis=%x old_bind=%x old_shndx=%x old_vis=%x\n",
sym_bind, shndx, new_vis, esym_bind, esym->st_shndx, esym_vis);
-#endif
tcc_error_noabort("'%s' defined twice", name);
+#endif
+ goto do_patch;
}
} else {
do_patch:

View file

@ -0,0 +1,23 @@
Fix issue in mes-libc crt where argc was getting truncated to lower byte and
prevented programs with more than 255 arguments from working correctly.
--- lib/linux/x86-mes-gcc/crt1.c
+++ lib/linux/x86-mes-gcc/crt1.c
@@ -48,7 +48,7 @@ _start ()
asm (
"mov %%ebp,%%eax\n\t"
"add $4,%%eax\n\t"
- "movzbl (%%eax),%%eax\n\t"
+ "mov (%%eax),%%eax\n\t"
"add $3,%%eax\n\t"
"shl $2,%%eax\n\t"
"add %%ebp,%%eax\n\t"
@@ -64,7 +64,7 @@ _start ()
"mov %ebp,%eax\n\t"
"add $4,%eax\n\t"
- "movzbl (%eax),%eax\n\t"
+ "mov (%eax),%eax\n\t"
"push %eax\n\t"
"call main\n\t"

50
sysa/tcc-0.9.27/tcc-musl.sh Executable file
View file

@ -0,0 +1,50 @@
src_unpack() {
# Our cp does not support recursive copying
tar -c -C ../src/ -f tcc-0.9.27.tar tcc-0.9.27/
tar -xf tcc-0.9.27.tar
}
src_prepare() {
patch -Np0 -i ../../patches/ignore-duplicate-symbols.patch
}
src_compile() {
export prefix=/after
export libdir=${prefix}/lib/musl
export incdir=${prefix}/include/musl
export bindir=${prefix}/bin
mkdir -p ${libdir}/tcc
# We first have to recompile using tcc-0.9.26 as tcc-0.9.27 is not self-hosting,
# but when linked with musl it is.
for TCC in tcc-0.9.26 tcc-musl; do
${TCC} \
-v \
-static \
-o ${bindir}/tcc-musl \
-D TCC_TARGET_I386=1 \
-D CONFIG_TCCDIR=\"${libdir}/tcc\" \
-D CONFIG_TCC_CRTPREFIX=\"${libdir}\" \
-D CONFIG_TCC_ELFINTERP=\"/musl/loader\" \
-D CONFIG_TCC_LIBPATHS=\"${libdir}:${libdir}/tcc\" \
-D CONFIG_TCC_SYSINCLUDEPATHS=\"${incdir}\" \
-D TCC_LIBGCC=\"${libdir}/libc.a\" \
-D CONFIG_TCC_STATIC=1 \
-D CONFIG_USE_LIBGCC=1 \
-D TCC_VERSION=\"0.9.27\" \
-D ONE_SOURCE=1 \
tcc.c
# libtcc1.a
${TCC} -c -D HAVE_CONFIG_H=1 lib/libtcc1.c
${TCC} -ar cr ${libdir}/tcc/libtcc1.a libtcc1.o
done
}
src_install() {
# Remove old tcc binaries, keep one for tcc-0.9.27 with mes C library
mv ${bindir}/tcc ${bindir}/tcc-mes
rm ${bindir}/boot*-tcc ${bindir}/tcc-0.9.26 ${bindir}/mes-tcc
ln -s ${bindir}/tcc-musl ${bindir}/tcc
}