commit: e0fba919a2aa6402a43a5a2000774736e27e712f
parent 9ddc0bcee6c1ac12112a66d5d3d91c2de8b61ffe
Author: Andrius Štikonas <andrius@stikonas.eu>
Date: Wed, 3 Feb 2021 00:16:39 +0000
Build tcc-musl.
Diffstat:
6 files changed, 82 insertions(+), 0 deletions(-)
diff --git a/README.md b/README.md
@@ -266,6 +266,7 @@ cope here.
macros to be defined and files to be generated from those macros.
#### Part 22: flex 2.5.11
+
`flex` is a tool for generating lexers or scanners: programs that recognize lexical patters.
Unfortunately `flex` also depends on itself for compiling its own scanner, so
@@ -274,6 +275,7 @@ it can be processed by lex for the Heirloom project (the required modifications
are mostly syntactical, plus a few workarounds to avoid some flex advanced features).
#### Part 23 flex 2.5.14
+
Then we recompile unpatched `flex` using its own lexer.
#### Part 24 musl 1.1.24
@@ -282,3 +284,13 @@ Then we recompile unpatched `flex` using its own lexer.
in the sense of standards-conformance and safety. `musl` is used by some distributions of GNU/Linux
as their C library. Our previous Mes C library was incomplete which prevented us from building many
newer or more complex programs.
+
+`tcc` has slight problems when building and linking `musl`, so we apply a few patches. In particular,
+we replace all weak symbols with strong symbols and will patch `tcc` in the next step to ignore duplicate
+symbols.
+
+#### Part 25 tcc 0.9.27 (musl)
+
+We recompile `tcc` against musl. This is a two stage process. First we build tcc-0.9.27 that itself
+links to Mes C library but produces binaries linked to musl. Then we recompile newly produced tcc
+with itself. Interestingly, tcc-0.9.27 linked against musl is self hosting.
diff --git a/sysa/musl-1.1.24/patches/makefile.patch b/sysa/musl-1.1.24/patches/makefile.patch
@@ -1,3 +1,4 @@
+tcc -ar does not support creating empty archives
--- Makefile 2019-10-13 22:58:27.000000000 +0100
+++ Makefile 2021-02-01 00:21:14.974687663 +0000
@@ -167,7 +167,7 @@
diff --git a/sysa/musl-1.1.24/patches/tcc_static.patch b/sysa/musl-1.1.24/patches/tcc_static.patch
@@ -1,3 +1,4 @@
+tinycc-0.9.27 does not support the use of the static keyword within an array length or index.
diff -U3 -r src/internal/syscall.h src/internal/syscall.h
--- src/internal/syscall.h 2019-10-13 22:58:27.000000000 +0100
+++ src/internal/syscall.h 2021-02-01 00:24:02.099200492 +0000
diff --git a/sysa/run.sh b/sysa/run.sh
@@ -21,4 +21,7 @@ build flex-2.5.14
# Part 24
build musl-1.1.24
+# Part 25
+build tcc-0.9.27 tcc-musl.sh
+
echo "Bootstrapping completed."
diff --git a/sysa/tcc-0.9.27/patches/ignore-duplicate-symbols.patch b/sysa/tcc-0.9.27/patches/ignore-duplicate-symbols.patch
@@ -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:
diff --git a/sysa/tcc-0.9.27/tcc-musl.sh b/sysa/tcc-0.9.27/tcc-musl.sh
@@ -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
+}