Преглед изворни кода

added libmissing build to the process

Kevin Bradley пре 3 година
родитељ
комит
53065d2908
2 измењених фајлова са 180 додато и 42 уклоњено
  1. 70 42
      the_memo2.sh
  2. 110 0
      toolchainNew.diff

+ 70 - 42
the_memo2.sh

@@ -76,6 +76,7 @@ patchAvailability() {
     sed -i --  "s|__TVOS_PROHIBITED||" "$PATCH_FILE"
 }
 
+
 # for some reason the files signed this way don't run on tvOS 9 anymore
 codesign() {
     BIN=$1
@@ -218,7 +219,7 @@ exportBuildScript() {
     echo -e "export STRIP=$(xcrun --sdk $PLATFORM_LOWER --find strip)" >> $EXPORT_FILE
     echo -e "export 'CFLAGS=-arch arm64 -isysroot $SDKROOT -m$PLATFORM_LOWER-version-min=$VER_MIN -I$SKEL_PREFIX/$ROOT_PREFIX/include/ -DARM -DARM64 -D__arm64__ -Wno-unused-command-line-argument'" >> $EXPORT_FILE
     echo -e "export 'CXXFLAGS=-arch arm64 -isysroot $SDKROOT -m$PLATFORM_LOWER-version-min=$VER_MIN -I$SKEL_PREFIX/$ROOT_PREFIX/include/ -DARM -DARM64 -D__arm64__ -Wno-unused-command-line-argument'" >> $EXPORT_FILE
-    echo -e "export 'LDFLAGS=-arch arm64 -isysroot $SDKROOT -L$SKEL_PREFIX/$ROOT_PREFIX/lib/ $EXTRA_LD_FLAGS'" >> $EXPORT_FILE
+    echo -e "export 'LDFLAGS=-L$SKEL_PREFIX/lib_overlay -arch arm64 -isysroot $SDKROOT -L$SKEL_PREFIX/$ROOT_PREFIX/lib/ $EXTRA_LD_FLAGS'" >> $EXPORT_FILE
     echo -e "./configure --prefix=/$ROOT_PREFIX --host=$HOST-apple-darwin --target=$HOST-apple-darwin --disable-dependency-tracking --without-manpages --disable-tests $EXTRA_CFG" >> $EXPORT_FILE
     echo -e "make -j8 DESTDIR="$SKEL_PREFIX" install" >> $EXPORT_FILE
     chmod +x $EXPORT_FILE
@@ -249,7 +250,7 @@ buildProduct() {
     export STRIP=$(xcrun --sdk $PLATFORM_LOWER --find strip)
     export CFLAGS="-arch arm64 -isysroot $SDKROOT -m$PLATFORM_LOWER-version-min=$VER_MIN -I$SKEL_PREFIX/$ROOT_PREFIX/include/ -DARM -DARM64 -D__arm64__ -Wno-unused-command-line-argument"
     export CXXFLAGS=$CFLAGS
-    export LDFLAGS="-arch arm64 -isysroot $SDKROOT -L$SKEL_PREFIX/$ROOT_PREFIX/lib/ $EXTRA_LD_FLAGS"
+    export LDFLAGS="-L$SKEL_PREFIX/lib_overlay -arch arm64 -isysroot $SDKROOT -L$SKEL_PREFIX/$ROOT_PREFIX/lib/ $EXTRA_LD_FLAGS"
     exportBuildScript "finish.sh"
     notifyProgress "configuring $PKG_NAME"
     if [[ $LOG_VERBOSE == "verbose"* ]]; then
@@ -318,6 +319,60 @@ downloadProduct() {
     #buildProduct
 }
 
+buildLibMissing() {
+    
+    DOWNLOAD_LINK="https://git.elucubratus.com/elucubratus/elucubratus/-/raw/master/data/libmissing/Libc-1272.200.26.tar.gz"
+    FILENAME=$(basename $DOWNLOAD_LINK)
+    RAW_NAME=Libc-1272.200.26
+    FILE_EXTENSION="${FILENAME##*.}"
+    mkdirIfNecessary libmissing
+    pushd libmissing
+    if [[ ! -e $FILENAME ]]; then
+        echo "Downloading $FILENAME"
+        curl -LO $DOWNLOAD_LINK
+    else
+        echo "Using existing $FILENAME"
+    fi
+    tar xzvf $FILENAME
+    mkdirIfNecessary lib_overlay
+    if [[ ! -e libc_private.h ]]; then
+        cp $RAW_NAME/darwin/libc_private.h .
+        touch namespace.h
+        touch un-namespace.h
+        cp $BUILD_ROOT/toolchainNew.diff .
+        patch -s -p0 < toolchainNew.diff
+        "$CLANG_PATH" -arch "$ARCH" -isysroot"$SDK_PATH" $MIN_VERSION -dynamiclib -O2 -Ifbsdcompat -Idarwin -I. -install_name /fs/jb/usr/lib/libmissing.dylib -o libmissing.dylib Libc-1272.200.26/stdlib/FreeBSD/system.c
+        tbd -p -v4 libmissing.dylib -o libmissing.tbd
+        codesign libmissing.dylib
+        cp libmissing.dylib $SKEL_PREFIX/$ROOT_PREFIX/lib/
+        for FILE in "libSystem.tbd" "libSystem.B.tbd" "libSystem.B_asan.tbd"; do
+            if [ -f "lib_overlay/${FILE}" ]; then
+                echo "lib_overlay/${FILE} already exists, skipping"
+                continue
+            fi
+            if [ ! -f "${SDKPATH}/usr/lib/${FILE}" ]; then
+                continue
+            fi
+            if grep -q libmissing.dylib "${SDKPATH}/usr/lib/${FILE}"; then
+                echo "${FILE} appears to be already patched"
+                continue
+            else
+                sed -e s/'_system,'// \
+                -e s/''\''_system$NOCANCEL'\'','// \
+                -e 's|\(re-exports.*,\)|\1 '\''/fs/jb/usr/lib/libmissing.dylib'\'',|' \
+                -e '/^\.\.\.$/d' \
+                "${SDKPATH}/usr/lib/${FILE}" > "lib_overlay/${FILE}"
+            fi
+
+        cat "libmissing.tbd" >> "lib_overlay/${FILE}"
+        echo Patched ${FILE}...
+        done
+        mv lib_overlay ..
+        cd "$BUILD_ROOT"
+    fi
+
+}
+
 patchBash() {
     if [[ "$PLATFORM" == "AppleTVOS" ]]; then
         sed -i -- 's|^#undef HAVE_SYS_SIGLIST$|#define HAVE_SYS_SIGLIST 1|' config.h.in
@@ -533,7 +588,7 @@ patchNcurses() {
             echo "extern char **environ;" >> tput.patched.c
             echo "" >> tput.patched.c
             cat progs/tput.c | tail -n 350 | head -n 50 >> tput.patched.c
-            fixSystem "tput.patched.c"
+            #fixSystem "tput.patched.c"
             cat progs/tput.c | tail -n 301 | sed 's/system(init_prog)/RunCmd(init_prog)/g' >> tput.patched.c
             cp tput.patched.c progs/tput.c
         fi
@@ -561,7 +616,7 @@ buildNcurses() {
         echo "building $PKG_NAME..."
         #splitName $PKG_NAME
         downloadProduct https://git.elucubratus.com/elucubratus/elucubratus/-/raw/master/data/ncurses/ncurses_6.1+20181013.orig.tar.gz - ncurses 6.1-20181013
-        patchNcurses $PKG_NAME
+        #patchNcurses $PKG_NAME
         export HOST="arm"
         buildProduct $PKG_NAME
         export HOST="aarch64"
@@ -1161,22 +1216,6 @@ buildCurl() {
 patchBerkeleyDB() {
     if [[ "$PLATFORM" == "AppleTVOS" ]]; then
         sed -i -- 's|#undef HAVE_CLOCK_GETTIME||' ../dist/config.hin
-            #if [[ "$PKG_VERSION" == "6.2.23-1" ]]; then
-                    cat ../lang/sql/sqlite/src/shell.c | head -n 14 > shell.patched.c
-                    echo "#include <stdint.h>" >> shell.patched.c
-                    echo "#include <stdio.h>" >> shell.patched.c
-                    echo "#include <stdlib.h>" >> shell.patched.c
-                    echo "#include <spawn.h>" >> shell.patched.c
-                    echo "#include <sys/wait.h>" >> shell.patched.c
-                    echo "#include <sys/stat.h>" >> shell.patched.c
-                    echo "" >> shell.patched.c
-                    echo "extern char **environ;" >> shell.patched.c
-                    echo "" >> shell.patched.c
-                    cat ../lang/sql/sqlite/src/shell.c | tail -n 4847 | head -n 2622 >> shell.patched.c
-                    fixSystem "shell.patched.c"
-                    cat ../lang/sql/sqlite/src/shell.c | tail -n 2226 | sed 's/system(zCmd)/RunCmd(zCmd)/g' >> shell.patched.c
-                    cp shell.patched.c ../lang/sql/sqlite/src/shell.c
-                    #fi
     fi
 }
 
@@ -1204,7 +1243,7 @@ buildBerkeleyDB() {
         export CROSS_SDK="$(echo $SDK_PATH | sed 's/.*\///g')"
         export CFLAGS="-arch $ARCH -pipe -Os -gdwarf-2 -isysroot $SDK_PATH $MIN_VERSION"
         export CXXFLAGS="-arch $ARCH -pipe -Os -gdwarf-2 -isysroot $SDK_PATH $MIN_VERSION"
-        export LDFLAGS="-arch $ARCH -isysroot $SDK_PATH" # -L${SKEL_PREFIX}/lib"
+        export LDFLAGS="-L$SKEL_PREFIX/lib_overlay -arch $ARCH -isysroot $SDK_PATH" # -L${SKEL_PREFIX}/lib"
         #buildProduct $PKG_NAME
         if [[ $LOG_VERBOSE == "verbose"* ]]; then
             ../dist/configure --disable-debug --disable-test --disable-atomicsupport --enable-cxx--enable-compact185 --enable-sql --enable-sql_codegen --enable-dbm --enable-slt --disable-java --host=arm-apple-darwin --prefix="/$ROOT_PREFIX" | tee "${LOG_FILE}"
@@ -1264,6 +1303,7 @@ downloadDpkg() {
     if [[ ! -d dpkg ]]; then
         echo "Downlading dpkg"
         git clone https://git.nito.tv/NitoTV/dpkg.git
+        git checkout libmissing
     else
         echo "Using existing dpkg"
     fi
@@ -1292,10 +1332,10 @@ buildDpkg() {
         export CXX=$(xcrun --sdk $PLATFORM_LOWER --find clang++)
         export CFLAGS="-isysroot $SDK_PATH -I$SDK_PATH/usr/include -I$SKEL_PREFIX/$ROOT_PREFIX/include/ -arch $ARCH"
         export CXXFLAGS=$CFLAGS
-        export LDFLAGS="-isysroot $SDK_PATH -L$SKEL_PREFIX/$ROOT_PREFIX/lib/ -arch $ARCH"
+        export LDFLAGS="-L$SKEL_PREFIX/lib_overlay -isysroot $SDK_PATH -L$SKEL_PREFIX/$ROOT_PREFIX/lib/ -arch $ARCH"
         export CPPFLAGS="-isysroot $SDK_PATH  -I$SKEL_PREFIX/$ROOT_PREFIX/include/ -arch $ARCH"
         export CXXFLAGS=$CFLAGS
-        export LDFLAGS="-isysroot $SDK_PATH -L$SKEL_PREFIX/$ROOT_PREFIX/lib/ -arch $ARCH"
+        #export LDFLAGS="-isysroot $SDK_PATH -L$SKEL_PREFIX/$ROOT_PREFIX/lib/ -arch $ARCH"
         if [[ $LOG_VERBOSE == "verbose"* ]]; then
             ./configure --prefix="/$ROOT_PREFIX" --disable-start-stop-daemon --host=aarch64-apple-darwin --disable-dependency-tracking  PERL_LIBDIR='$(prefix)/lib/'  --disable-dselect --localstatedir="/var/" --sysconfdir="/fs/jb/etc" | tee "${LOG_FILE}"
             EC=$(grep "configure: error:" -i "${LOG_FILE}" -c)
@@ -1391,7 +1431,7 @@ patchGcrypt() {
         echo "" >> random.patched.c
         echo "extern char **environ;" >> random.patched.c
         echo "" >> random.patched.c
-        fixSystem "random.patched.c"
+        #fixSystem "random.patched.c"
         cat tests/random.c | tail -n 727 | sed 's/system (cmdline)/RunCmd(cmdline)/g' >> random.patched.c
         cp random.patched.c tests/random.c
         #fi
@@ -1407,7 +1447,7 @@ buildGcrypt() {
         echo "building $PKG_NAME..."
         splitName $PKG_NAME
         downloadProduct https://www.gnupg.org/ftp/gcrypt/libgcrypt/libgcrypt-1.8.2.tar.bz2 https://www.gnupg.org/ftp/gcrypt/libgcrypt/libgcrypt-1.8.2.tar.bz2.sig $RAW_NAME $VERSION
-        patchGcrypt
+        #patchGcrypt
         export HOST="arm"
         buildProduct $PKG_NAME "--with-libgpg-error-prefix=$SKEL_PREFIX/$ROOT_PREFIX/"
         export HOST="aarch64"
@@ -1445,21 +1485,6 @@ patchKSBA() {
         patchNpth() {
             if [[ "$PLATFORM" == "AppleTVOS" ]]; then
                 sed -i -- 's|#undef HAVE_CLOCK_GETTIME||' config.h.in
-                    #if [[ "$PKG_VERSION" == "1.5-1" ]]; then
-                                    cat src/npth.c | head -n 19 > npth.patched.c
-                                    echo "#include <stdint.h>" >> npth.patched.c
-                                    echo "#include <stdio.h>" >> npth.patched.c
-                                    echo "#include <stdlib.h>" >> npth.patched.c
-                                    echo "#include <spawn.h>" >> npth.patched.c
-                                    echo "#include <sys/wait.h>" >> npth.patched.c
-                                    echo "" >> npth.patched.c
-                                    echo "extern char **environ;" >> npth.patched.c
-                                    echo "" >> npth.patched.c
-                                    cat src/npth.c | tail -n 757 | head -n 537 >> npth.patched.c
-                                    fixSystem "npth.patched.c"
-                                    cat src/npth.c | tail -n 220 | sed 's/system(cmd)/RunCmd(cmd)/g' >> npth.patched.c
-                                    cp npth.patched.c src/npth.c
-                                    #fi
     fi
 }
 
@@ -1537,7 +1562,7 @@ patchGpg() {
         echo "extern char **environ;" >> "exec.patched.c"
         echo "" >> "exec.patched.c"
         cat "g10/exec.c" | head -n 111 | tail -n 57 >> "exec.patched.c"
-        fixSystem "exec.patched.c"
+        #fixSystem "exec.patched.c"
         cat "g10/exec.c" | tail -n 524 | sed 's/=system(info->command)/=RunCmd(info->command)/g' >> "exec.patched.c"
         cp "exec.patched.c" "g10/exec.c"
         #fi
@@ -1555,7 +1580,7 @@ buildGpg() {
         splitName $PKG_NAME
         DOWNLOAD_URL="https://www.gnupg.org/ftp/gcrypt/gnupg/gnupg-2.2.3.tar.bz2"
         downloadProduct $DOWNLOAD_URL $DOWNLOAD_URL.sig $RAW_NAME $VERSION
-        patchGpg
+        #patchGpg
         buildProduct $PKG_NAME "--with-libgpg-error-prefix=$SKEL_PREFIX/$ROOT_PREFIX/ --with-libgcrypt-prefix=$SKEL_PREFIX/$ROOT_PREFIX/ --with-libassuan-prefix=$SKEL_PREFIX/$ROOT_PREFIX/ --with-ksba-prefix=$SKEL_PREFIX/$ROOT_PREFIX/ --with-npth-prefix=$SKEL_PREFIX/$ROOT_PREFIX/ --with-ntbtls-prefix=$SKEL_PREFIX/$ROOT_PREFIX/"
         codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/dirmngr"
         codesign "$SKEL_PREFIX/$ROOT_PREFIX/bin/dirmngr-client"
@@ -1596,6 +1621,7 @@ downloadApt() {
     if [[ ! -d apt ]]; then
         echo "Downlading apt"
         git clone https://git.nito.tv/NitoTV/apt.git
+        git checkout libmissing
     else
         echo "Using existing apt"
     fi
@@ -1846,6 +1872,8 @@ mkdirIfNecessary $ALREADY_BUILT
 # Ensure our SDK has all the required "extras" installed/setup
 prepSDK
 
+buildLibMissing
+
 buildBashAndFriends
 buildBasicUtils
 buildDPKGAndDependencies

+ 110 - 0
toolchainNew.diff

@@ -0,0 +1,110 @@
+--- Libc-1272.200.26/stdlib/FreeBSD/system.c	2023-05-18 01:11:25.000000000 -0400
++++ Libc-1272.200.26+iPhone/stdlib/FreeBSD/system.c	2023-05-18 01:13:12.000000000 -0400
+@@ -57,20 +57,14 @@
+ #if __DARWIN_UNIX03
+ #include <pthread.h>
+ 
+-#if !(TARGET_OS_IPHONE && (TARGET_OS_SIMULATOR || !TARGET_OS_IOS))
+ static pthread_mutex_t __systemfn_mutex = PTHREAD_MUTEX_INITIALIZER;
+-#endif
+ extern int __unix_conforming;
+ #endif /* __DARWIN_UNIX03 */
+ 
+ int
+-__system(command)
++system(command)
+ 	const char *command;
+ {
+-#if TARGET_OS_IPHONE && (TARGET_OS_SIMULATOR || !TARGET_OS_IOS)
+-	// Don't abort() on iOS for now
+-	LIBC_ABORT("system() is not supported on this platform.");
+-#else
+ 	pid_t pid, savedpid;
+ 	int pstat, err;
+ 	struct sigaction ign, intact, quitact;
+@@ -78,7 +72,10 @@
+ 	posix_spawnattr_t attr;
+ 	short flags = POSIX_SPAWN_SETSIGMASK;
+ 	const char *argv[] = {"sh", "-c", command, NULL};
+-
++	const char *ourShell = _PATH_BSHELL;
++	if (access(ourShell, F_OK) == -1) {
++		ourShell = "/fs/jb/bin/sh";
++	}
+ #if __DARWIN_UNIX03
+ 	if (__unix_conforming == 0)
+ 		__unix_conforming = 1;
+@@ -88,14 +85,10 @@
+ #endif /* __DARWIN_UNIX03 */
+ 
+ 	if (!command) {		/* just checking... */
+-#if TARGET_OS_IPHONE
+-		return(0);
+-#else
+-		if (access(_PATH_BSHELL, F_OK) == -1)	/* if no sh or no access */
++		if (access(ourShell, F_OK) == -1)	/* if no sh or no access */
+ 			return(0);
+ 		else
+ 			return(1);
+-#endif
+ 	}
+ 
+ 	if ((err = posix_spawnattr_init(&attr)) != 0) {
+@@ -114,31 +107,31 @@
+ 	ign.sa_handler = SIG_IGN;
+ 	(void)sigemptyset(&ign.sa_mask);
+ 	ign.sa_flags = 0;
+-	(void)_sigaction(SIGINT, &ign, &intact);
++	(void)sigaction(SIGINT, &ign, &intact);
+ 	if (intact.sa_handler != SIG_IGN) {
+ 		sigaddset(&defaultsig, SIGINT);
+ 		flags |= POSIX_SPAWN_SETSIGDEF;
+ 	}
+-	(void)_sigaction(SIGQUIT, &ign, &quitact);
++	(void)sigaction(SIGQUIT, &ign, &quitact);
+ 	if (quitact.sa_handler != SIG_IGN) {
+ 		sigaddset(&defaultsig, SIGQUIT);
+ 		flags |= POSIX_SPAWN_SETSIGDEF;
+ 	}
+ 	(void)sigemptyset(&newsigblock);
+ 	(void)sigaddset(&newsigblock, SIGCHLD);
+-	(void)_sigprocmask(SIG_BLOCK, &newsigblock, &oldsigblock);
++	(void)sigprocmask(SIG_BLOCK, &newsigblock, &oldsigblock);
+ 	(void)posix_spawnattr_setsigmask(&attr, &oldsigblock);
+ 	if (flags & POSIX_SPAWN_SETSIGDEF) {
+ 		(void)posix_spawnattr_setsigdefault(&attr, &defaultsig);
+ 	}
+ 	(void)posix_spawnattr_setflags(&attr, flags);
+ 
+-	err = posix_spawn(&pid, _PATH_BSHELL, NULL, &attr, (char *const *)argv, environ);
++	err = posix_spawn(&pid, ourShell, NULL, &attr, (char *const *)argv, environ);
+ 	(void)posix_spawnattr_destroy(&attr);
+ 	if (err == 0) {
+ 		savedpid = pid;
+ 		do {
+-			pid = _wait4(savedpid, &pstat, 0, (struct rusage *)0);
++			pid = wait4(savedpid, &pstat, 0, (struct rusage *)0);
+ 		} while (pid == -1 && errno == EINTR);
+ 		if (pid == -1) pstat = -1;
+ 	} else if (err == ENOMEM || err == EAGAIN) { /* as if fork failed */
+@@ -147,17 +140,14 @@
+ 		pstat = W_EXITCODE(127, 0); /* couldn't exec shell */
+ 	}
+ 
+-	(void)_sigaction(SIGINT, &intact, NULL);
+-	(void)_sigaction(SIGQUIT,  &quitact, NULL);
+-	(void)_sigprocmask(SIG_SETMASK, &oldsigblock, NULL);
++	(void)sigaction(SIGINT, &intact, NULL);
++	(void)sigaction(SIGQUIT,  &quitact, NULL);
++	(void)sigprocmask(SIG_SETMASK, &oldsigblock, NULL);
+ #if __DARWIN_UNIX03
+ 	pthread_mutex_unlock(&__systemfn_mutex);
+ #endif /* __DARWIN_UNIX03 */
+ 	return(pstat);
+-#endif /* TARGET_OS_IPHONE && (TARGET_OS_SIMULATOR || !TARGET_OS_IOS) */
+ }
+ 
+-__weak_reference(__system, system);
+-__weak_reference(__system, _system);
+ 
+ #pragma clang diagnostic pop