diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..976eb6c --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "submodules/debian-sysroot"] + path = submodules/debian-sysroot + url = https://github.com/AmanoTeam/debian-sysroot diff --git a/aarch64-unknown-linux-gnu.sh b/aarch64-unknown-linux-gnu.sh index f64f76f..5e7fb28 100644 --- a/aarch64-unknown-linux-gnu.sh +++ b/aarch64-unknown-linux-gnu.sh @@ -1,10 +1,10 @@ #!/bin/bash declare packages=( - 'https://web.archive.org/web/0if_/https://archive.debian.org/debian/pool/main/l/linux/linux-libc-dev_3.16.56-1+deb8u1_arm64.deb' - 'https://web.archive.org/web/0if_/https://archive.debian.org/debian/pool/main/g/glibc/libc6-dev_2.19-18+deb8u10_arm64.deb' - 'https://web.archive.org/web/0if_/https://archive.debian.org/debian/pool/main/g/glibc/libc6_2.19-18+deb8u10_arm64.deb' - 'https://web.archive.org/web/0if_/https://archive.debian.org/debian/pool/main/s/systemtap/systemtap-sdt-dev_2.6-0.2_arm64.deb' + 'https://archive.debian.org/debian/pool/main/l/linux/linux-libc-dev_3.16.56-1+deb8u1_arm64.deb' + 'https://archive.debian.org/debian/pool/main/g/glibc/libc6-dev_2.19-18+deb8u10_arm64.deb' + 'https://archive.debian.org/debian/pool/main/g/glibc/libc6_2.19-18+deb8u10_arm64.deb' + 'https://archive.debian.org/debian/pool/main/s/systemtap/systemtap-sdt-dev_2.6-0.2_arm64.deb' ) declare extra_configure_flags='' diff --git a/alpha-unknown-linux-gnu.sh b/alpha-unknown-linux-gnu.sh index c22780c..fd18d0d 100644 --- a/alpha-unknown-linux-gnu.sh +++ b/alpha-unknown-linux-gnu.sh @@ -1,9 +1,9 @@ #!/bin/bash declare packages=( - 'https://web.archive.org/web/0if_/https://archive.debian.org/debian/pool/main/l/linux-2.6/linux-libc-dev_2.6.26-29_alpha.deb' - 'https://web.archive.org/web/0if_/https://archive.debian.org/debian/pool/main/g/glibc/libc6.1-dev_2.7-18lenny7_alpha.deb' - 'https://web.archive.org/web/0if_/https://archive.debian.org/debian/pool/main/g/glibc/libc6.1_2.7-18lenny7_alpha.deb' + 'https://archive.debian.org/debian/pool/main/l/linux-2.6/linux-libc-dev_2.6.26-29_alpha.deb' + 'https://archive.debian.org/debian/pool/main/g/glibc/libc6.1-dev_2.7-18lenny7_alpha.deb' + 'https://archive.debian.org/debian/pool/main/g/glibc/libc6.1_2.7-18lenny7_alpha.deb' ) declare extra_configure_flags='' diff --git a/arm-unknown-linux-gnueabi.sh b/arm-unknown-linux-gnueabi.sh index f8ce144..713de09 100644 --- a/arm-unknown-linux-gnueabi.sh +++ b/arm-unknown-linux-gnueabi.sh @@ -1,9 +1,9 @@ #!/bin/bash declare packages=( - 'https://web.archive.org/web/0if_/https://archive.debian.org/debian/pool/main/l/linux-2.6/linux-libc-dev_2.6.26-29_armel.deb' - 'https://web.archive.org/web/0if_/https://archive.debian.org/debian/pool/main/g/glibc/libc6-dev_2.7-18lenny7_armel.deb' - 'https://web.archive.org/web/0if_/https://archive.debian.org/debian/pool/main/g/glibc/libc6_2.7-18lenny7_armel.deb' + 'https://archive.debian.org/debian/pool/main/l/linux-2.6/linux-libc-dev_2.6.26-29_armel.deb' + 'https://archive.debian.org/debian/pool/main/g/glibc/libc6-dev_2.7-18lenny7_armel.deb' + 'https://archive.debian.org/debian/pool/main/g/glibc/libc6_2.7-18lenny7_armel.deb' ) declare extra_configure_flags='--with-arch=armv4t --with-float=soft --disable-libsanitizer' diff --git a/arm-unknown-linux-gnueabihf.sh b/arm-unknown-linux-gnueabihf.sh index 5eebd09..3dc2aae 100644 --- a/arm-unknown-linux-gnueabihf.sh +++ b/arm-unknown-linux-gnueabihf.sh @@ -1,10 +1,10 @@ #!/bin/bash declare packages=( - 'https://web.archive.org/web/0if_/https://archive.debian.org/debian-security/pool/updates/main/l/linux/linux-libc-dev_3.2.102-1_armhf.deb' - 'https://web.archive.org/web/0if_/https://archive.debian.org/debian-security/pool/updates/main/e/eglibc/libc6-dev_2.13-38+deb7u12_armhf.deb' - 'https://web.archive.org/web/0if_/https://archive.debian.org/debian-security/pool/updates/main/e/eglibc/libc6_2.13-38+deb7u12_armhf.deb' - 'https://web.archive.org/web/0if_/https://archive.debian.org/debian/pool/main/s/systemtap/systemtap-sdt-dev_1.7-1+deb7u1_armhf.deb' + 'https://archive.debian.org/debian-security/pool/updates/main/l/linux/linux-libc-dev_3.2.102-1_armhf.deb' + 'https://archive.debian.org/debian-security/pool/updates/main/e/eglibc/libc6-dev_2.13-38+deb7u12_armhf.deb' + 'https://archive.debian.org/debian-security/pool/updates/main/e/eglibc/libc6_2.13-38+deb7u12_armhf.deb' + 'https://archive.debian.org/debian/pool/main/s/systemtap/systemtap-sdt-dev_1.7-1+deb7u1_armhf.deb' ) declare extra_configure_flags='--with-arch=armv7-a --with-fpu=vfpv3-d16 --with-float=hard --with-mode=thumb' diff --git a/build.sh b/build.sh index 4a54a2e..5a711c9 100644 --- a/build.sh +++ b/build.sh @@ -133,22 +133,22 @@ make all --jobs make install declare -ra targets=( - 'ia64-unknown-linux-gnu' - 'alpha-unknown-linux-gnu' + # 'ia64-unknown-linux-gnu' + # 'alpha-unknown-linux-gnu' 'x86_64-unknown-linux-gnu' - 'i386-unknown-linux-gnu' - 'arm-unknown-linux-gnueabi' - 'arm-unknown-linux-gnueabihf' - 'hppa-unknown-linux-gnu' - 'aarch64-unknown-linux-gnu' - 'mips-unknown-linux-gnu' - 'mipsel-unknown-linux-gnu' - 'powerpc-unknown-linux-gnu' - 's390-unknown-linux-gnu' - 's390x-unknown-linux-gnu' - 'sparc-unknown-linux-gnu' - 'powerpc64le-unknown-linux-gnu' - 'mips64el-unknown-linux-gnuabi64' + # 'i386-unknown-linux-gnu' + # 'arm-unknown-linux-gnueabi' + # 'arm-unknown-linux-gnueabihf' + # 'hppa-unknown-linux-gnu' + # 'aarch64-unknown-linux-gnu' + # 'mips-unknown-linux-gnu' + # 'mipsel-unknown-linux-gnu' + # 'powerpc-unknown-linux-gnu' + # 's390-unknown-linux-gnu' + # 's390x-unknown-linux-gnu' + # 'sparc-unknown-linux-gnu' + # 'powerpc64le-unknown-linux-gnu' + # 'mips64el-unknown-linux-gnuabi64' ) for target in "${targets[@]}"; do @@ -248,7 +248,7 @@ for target in "${targets[@]}"; do --with-static-standard-libraries \ --with-bugurl='https://github.com/AmanoTeam/obggcc/issues' \ --with-gcc-major-version-only \ - --with-pkgversion="OBGGCC v0.8-${obggcc_revision}" \ + --with-pkgversion="OBGGCC v0.9-${obggcc_revision}" \ --with-sysroot="${toolchain_directory}/${triple}" \ --with-native-system-header-dir='/include' \ --enable-__cxa_atexit \ @@ -301,3 +301,31 @@ for target in "${targets[@]}"; do patchelf --add-rpath '$ORIGIN/../../../../lib' "${toolchain_directory}/libexec/gcc/${triple}/"*'/cc1plus' patchelf --add-rpath '$ORIGIN/../../../../lib' "${toolchain_directory}/libexec/gcc/${triple}/"*'/lto1' done + +declare cc='gcc' + +if ! (( is_native )); then + cc="${CC}" +fi + +declare -r sysroot_tarball='/tmp/sysroot.tar.xz' +declare -r executable='/tmp/gcc-wrapper' + +while read item; do + declare glibc_version="$(jq '.glibc_version' <<< "${item}")" + declare triplet="$(jq --raw-output '.triplet' <<< "${item}")" + + "${cc}" \ + "${workdir}/tools/gcc-wrapper/filesystem.c" \ + "${workdir}/tools/gcc-wrapper/main.c" \ + "${workdir}/tools/gcc-wrapper/path.c" \ + -Os \ + -s \ + -o "${executable}" + + cp "${executable}" "${toolchain_directory}/bin/${triplet}${glibc_version}-gcc" + cp "${executable}" "${toolchain_directory}/bin/${triplet}${glibc_version}-g++" + + wget --no-verbose "https://github.com/AmanoTeam/debian-sysroot/releases/download/latest/${triplet}${glibc_version}.tar.xz" --output-document="${sysroot_tarball}" + tar --directory="${toolchain_directory}" --extract --file="${sysroot_tarball}" +done <<< "$(jq --compact-output '.[]' "${workdir}/submodules/debian-sysroot/dist.json")" diff --git a/hppa-unknown-linux-gnu.sh b/hppa-unknown-linux-gnu.sh index fd7d9cd..d69cfb1 100644 --- a/hppa-unknown-linux-gnu.sh +++ b/hppa-unknown-linux-gnu.sh @@ -1,9 +1,9 @@ #!/bin/bash declare packages=( - 'https://web.archive.org/web/0if_/https://archive.debian.org/debian/pool/main/l/linux-2.6/linux-libc-dev_2.6.26-29_hppa.deb' - 'https://web.archive.org/web/0if_/https://archive.debian.org/debian/pool/main/g/glibc/libc6-dev_2.7-18lenny7_hppa.deb' - 'https://web.archive.org/web/0if_/https://archive.debian.org/debian/pool/main/g/glibc/libc6_2.7-18lenny7_hppa.deb' + 'https://archive.debian.org/debian/pool/main/l/linux-2.6/linux-libc-dev_2.6.26-29_hppa.deb' + '/https://archive.debian.org/debian/pool/main/g/glibc/libc6-dev_2.7-18lenny7_hppa.deb' + 'https://archive.debian.org/debian/pool/main/g/glibc/libc6_2.7-18lenny7_hppa.deb' ) declare extra_configure_flags='--disable-libsanitizer' diff --git a/submodules/debian-sysroot b/submodules/debian-sysroot new file mode 160000 index 0000000..8cd10cc --- /dev/null +++ b/submodules/debian-sysroot @@ -0,0 +1 @@ +Subproject commit 8cd10ccf2efcf9f40742156632272842f79b9898 diff --git a/tools/builtin_symbols.json b/tools/builtin_symbols.json deleted file mode 100644 index ef680da..0000000 --- a/tools/builtin_symbols.json +++ /dev/null @@ -1,1102 +0,0 @@ -[ - { - "name": "acoshf", - "header": "math" - }, - { - "name": "acoshl", - "header": "math" - }, - { - "name": "acosh", - "header": "math" - }, - { - "name": "asinhf", - "header": "math" - }, - { - "name": "asinhl", - "header": "math" - }, - { - "name": "asinh", - "header": "math" - }, - { - "name": "atanhf", - "header": "math" - }, - { - "name": "atanhl", - "header": "math" - }, - { - "name": "atanh", - "header": "math" - }, - { - "name": "cabsf", - "header": "complex" - }, - { - "name": "cabsl", - "header": "complex" - }, - { - "name": "cabs", - "header": "complex" - }, - { - "name": "cacosf", - "header": "complex" - }, - { - "name": "cacoshf", - "header": "complex" - }, - { - "name": "cacoshl", - "header": "complex" - }, - { - "name": "cacosh", - "header": "complex" - }, - { - "name": "cacosl", - "header": "complex" - }, - { - "name": "cacos", - "header": "complex" - }, - { - "name": "cargf", - "header": "complex" - }, - { - "name": "cargl", - "header": "complex" - }, - { - "name": "carg", - "header": "complex" - }, - { - "name": "casinf", - "header": "complex" - }, - { - "name": "casinhf", - "header": "complex" - }, - { - "name": "casinhl", - "header": "complex" - }, - { - "name": "casinh", - "header": "complex" - }, - { - "name": "casinl", - "header": "complex" - }, - { - "name": "casin", - "header": "complex" - }, - { - "name": "catanf", - "header": "complex" - }, - { - "name": "catanhf", - "header": "complex" - }, - { - "name": "catanhl", - "header": "complex" - }, - { - "name": "catanh", - "header": "complex" - }, - { - "name": "catanl", - "header": "complex" - }, - { - "name": "catan", - "header": "complex" - }, - { - "name": "cbrtf", - "header": "complex" - }, - { - "name": "cbrtl", - "header": "complex" - }, - { - "name": "cbrt", - "header": "complex" - }, - { - "name": "ccosf", - "header": "complex" - }, - { - "name": "ccoshf", - "header": "complex" - }, - { - "name": "ccoshl", - "header": "complex" - }, - { - "name": "ccosh", - "header": "complex" - }, - { - "name": "ccosl", - "header": "complex" - }, - { - "name": "ccos", - "header": "complex" - }, - { - "name": "cexpf", - "header": "complex" - }, - { - "name": "cexpl", - "header": "complex" - }, - { - "name": "cexp", - "header": "complex" - }, - { - "name": "cimagf", - "header": "complex" - }, - { - "name": "cimagl", - "header": "complex" - }, - { - "name": "cimag", - "header": "complex" - }, - { - "name": "clogf", - "header": "complex" - }, - { - "name": "clogl", - "header": "complex" - }, - { - "name": "clog", - "header": "complex" - }, - { - "name": "conjf", - "header": "complex" - }, - { - "name": "conjl", - "header": "complex" - }, - { - "name": "conj", - "header": "complex" - }, - { - "name": "copysignf", - "header": "math" - }, - { - "name": "copysignl", - "header": "math" - }, - { - "name": "copysign", - "header": "math" - }, - { - "name": "cpowf", - "header": "complex" - }, - { - "name": "cpowl", - "header": "complex" - }, - { - "name": "cpow", - "header": "complex" - }, - { - "name": "cprojf", - "header": "complex" - }, - { - "name": "cprojl", - "header": "complex" - }, - { - "name": "cproj", - "header": "complex" - }, - { - "name": "crealf", - "header": "complex" - }, - { - "name": "creall", - "header": "complex" - }, - { - "name": "creal", - "header": "complex" - }, - { - "name": "csinf", - "header": "complex" - }, - { - "name": "csinhf", - "header": "complex" - }, - { - "name": "csinhl", - "header": "complex" - }, - { - "name": "csinh", - "header": "complex" - }, - { - "name": "csinl", - "header": "complex" - }, - { - "name": "csin", - "header": "complex" - }, - { - "name": "csqrtf", - "header": "complex" - }, - { - "name": "csqrtl", - "header": "complex" - }, - { - "name": "csqrt", - "header": "complex" - }, - { - "name": "ctanf", - "header": "complex" - }, - { - "name": "ctanhf", - "header": "complex" - }, - { - "name": "ctanhl", - "header": "complex" - }, - { - "name": "ctanh", - "header": "complex" - }, - { - "name": "ctanl", - "header": "complex" - }, - { - "name": "ctan", - "header": "complex" - }, - { - "name": "erfcf", - "header": "math" - }, - { - "name": "erfcl", - "header": "math" - }, - { - "name": "erfc", - "header": "math" - }, - { - "name": "erff", - "header": "math" - }, - { - "name": "erfl", - "header": "math" - }, - { - "name": "erf", - "header": "math" - }, - { - "name": "exp2f", - "header": "math" - }, - { - "name": "exp2l", - "header": "math" - }, - { - "name": "exp2", - "header": "math" - }, - { - "name": "expm1f", - "header": "math" - }, - { - "name": "expm1l", - "header": "math" - }, - { - "name": "expm1", - "header": "math" - }, - { - "name": "fdimf", - "header": "math" - }, - { - "name": "fdiml", - "header": "math" - }, - { - "name": "fdim", - "header": "math" - }, - { - "name": "fmaf", - "header": "math" - }, - { - "name": "fmal", - "header": "math" - }, - { - "name": "fmaxf", - "header": "math" - }, - { - "name": "fmaxl", - "header": "math" - }, - { - "name": "fmax", - "header": "math" - }, - { - "name": "fma", - "header": "math" - }, - { - "name": "fminf", - "header": "math" - }, - { - "name": "fminl", - "header": "math" - }, - { - "name": "fmin", - "header": "math" - }, - { - "name": "hypotf", - "header": "math" - }, - { - "name": "hypotl", - "header": "math" - }, - { - "name": "hypot", - "header": "math" - }, - { - "name": "ilogbf", - "header": "math" - }, - { - "name": "ilogbl", - "header": "math" - }, - { - "name": "ilogb", - "header": "math" - }, - { - "name": "imaxabs", - "header": "inttypes" - }, - { - "name": "isblank", - "header": "ctype" - }, - { - "name": "iswblank", - "header": "wctype" - }, - { - "name": "lgammaf", - "header": "math" - }, - { - "name": "lgammal", - "header": "math" - }, - { - "name": "lgamma", - "header": "math" - }, - { - "name": "llabs", - "header": "stdlib" - }, - { - "name": "llrintf", - "header": "math" - }, - { - "name": "llrintl", - "header": "math" - }, - { - "name": "llrint", - "header": "math" - }, - { - "name": "llroundf", - "header": "math" - }, - { - "name": "llroundl", - "header": "math" - }, - { - "name": "llround", - "header": "math" - }, - { - "name": "log1pf", - "header": "math" - }, - { - "name": "log1pl", - "header": "math" - }, - { - "name": "log1p", - "header": "math" - }, - { - "name": "log2f", - "header": "math" - }, - { - "name": "log2l", - "header": "math" - }, - { - "name": "log2", - "header": "math" - }, - { - "name": "logbf", - "header": "math" - }, - { - "name": "logbl", - "header": "math" - }, - { - "name": "logb", - "header": "math" - }, - { - "name": "lrintf", - "header": "math" - }, - { - "name": "lrintl", - "header": "math" - }, - { - "name": "lrint", - "header": "math" - }, - { - "name": "lroundf", - "header": "math" - }, - { - "name": "lroundl", - "header": "math" - }, - { - "name": "lround", - "header": "math" - }, - { - "name": "nearbyintf", - "header": "math" - }, - { - "name": "nearbyintl", - "header": "math" - }, - { - "name": "nearbyint", - "header": "math" - }, - { - "name": "nextafterf", - "header": "math" - }, - { - "name": "nextafterl", - "header": "math" - }, - { - "name": "nextafter", - "header": "math" - }, - { - "name": "nexttowardf", - "header": "math" - }, - { - "name": "nexttowardl", - "header": "math" - }, - { - "name": "nexttoward", - "header": "math" - }, - { - "name": "remainderf", - "header": "math" - }, - { - "name": "remainderl", - "header": "math" - }, - { - "name": "remainder", - "header": "math" - }, - { - "name": "remquof", - "header": "math" - }, - { - "name": "remquol", - "header": "math" - }, - { - "name": "remquo", - "header": "math" - }, - { - "name": "rintf", - "header": "math" - }, - { - "name": "rintl", - "header": "math" - }, - { - "name": "rint", - "header": "math" - }, - { - "name": "roundf", - "header": "math" - }, - { - "name": "roundl", - "header": "math" - }, - { - "name": "round", - "header": "math" - }, - { - "name": "scalblnf", - "header": "math" - }, - { - "name": "scalblnl", - "header": "math" - }, - { - "name": "scalbln", - "header": "math" - }, - { - "name": "scalbnf", - "header": "math" - }, - { - "name": "scalbnl", - "header": "math" - }, - { - "name": "scalbn", - "header": "math" - }, - { - "name": "snprintf", - "header": "stdio" - }, - { - "name": "tgammaf", - "header": "math" - }, - { - "name": "tgammal", - "header": "math" - }, - { - "name": "tgamma", - "header": "math" - }, - { - "name": "truncf", - "header": "math" - }, - { - "name": "truncl", - "header": "math" - }, - { - "name": "trunc", - "header": "math" - }, - { - "name": "vfscanf", - "header": "stdio" - }, - { - "name": "vscanf", - "header": "stdio" - }, - { - "name": "vsnprintf", - "header": "stdio" - }, - { - "name": "vsscanf", - "header": "stdio" - }, - { - "name": "_Exit", - "header": "stdlib" - }, - { - "name": "acosf", - "header": "math" - }, - { - "name": "acosl", - "header": "math" - }, - { - "name": "asinf", - "header": "math" - }, - { - "name": "asinl", - "header": "math" - }, - { - "name": "atan2f", - "header": "math" - }, - { - "name": "atan2l", - "header": "math" - }, - { - "name": "atanf", - "header": "math" - }, - { - "name": "atanl", - "header": "math" - }, - { - "name": "ceilf", - "header": "math" - }, - { - "name": "ceill", - "header": "math" - }, - { - "name": "cosf", - "header": "math" - }, - { - "name": "coshf", - "header": "math" - }, - { - "name": "coshl", - "header": "math" - }, - { - "name": "cosl", - "header": "math" - }, - { - "name": "expf", - "header": "math" - }, - { - "name": "expl", - "header": "math" - }, - { - "name": "fabsf", - "header": "math" - }, - { - "name": "fabsl", - "header": "math" - }, - { - "name": "floorf", - "header": "math" - }, - { - "name": "floorl", - "header": "math" - }, - { - "name": "fmodf", - "header": "math" - }, - { - "name": "fmodl", - "header": "math" - }, - { - "name": "frexpf", - "header": "math" - }, - { - "name": "frexpl", - "header": "math" - }, - { - "name": "ldexpf", - "header": "math" - }, - { - "name": "ldexpl", - "header": "math" - }, - { - "name": "log10f", - "header": "math" - }, - { - "name": "log10l", - "header": "math" - }, - { - "name": "logf", - "header": "math" - }, - { - "name": "logl", - "header": "math" - }, - { - "name": "modfl", - "header": "math" - }, - { - "name": "modff", - "header": "math" - }, - { - "name": "powf", - "header": "math" - }, - { - "name": "powl", - "header": "math" - }, - { - "name": "sinf", - "header": "math" - }, - { - "name": "sinhf", - "header": "math" - }, - { - "name": "sinhl", - "header": "math" - }, - { - "name": "sinl", - "header": "math" - }, - { - "name": "sqrtf", - "header": "math" - }, - { - "name": "sqrtl", - "header": "math" - }, - { - "name": "tanf", - "header": "math" - }, - { - "name": "tanhf", - "header": "math" - }, - { - "name": "tanhl", - "header": "math" - }, - { - "name": "tanl", - "header": "math" - }, - { - "name": "abs", - "header": "stdlib" - }, - { - "name": "acos", - "header": "math" - }, - { - "name": "asin", - "header": "math" - }, - { - "name": "atan2", - "header": "math" - }, - { - "name": "atan", - "header": "math" - }, - { - "name": "ceil", - "header": "math" - }, - { - "name": "cosh", - "header": "math" - }, - { - "name": "cos", - "header": "math" - }, - { - "name": "exp", - "header": "math" - }, - { - "name": "fabs", - "header": "math" - }, - { - "name": "floor", - "header": "math" - }, - { - "name": "fmod", - "header": "math" - }, - { - "name": "frexp", - "header": "math" - }, - { - "name": "isalnum", - "header": "ctype" - }, - { - "name": "isalpha", - "header": "ctype" - }, - { - "name": "iscntrl", - "header": "ctype" - }, - { - "name": "isdigit", - "header": "ctype" - }, - { - "name": "isgraph", - "header": "ctype" - }, - { - "name": "islower", - "header": "ctype" - }, - { - "name": "isprint", - "header": "ctype" - }, - { - "name": "ispunct", - "header": "ctype" - }, - { - "name": "isspace", - "header": "ctype" - }, - { - "name": "isupper", - "header": "ctype" - }, - { - "name": "isxdigit", - "header": "ctype" - }, - { - "name": "ldexp", - "header": "math" - }, - { - "name": "log10", - "header": "math" - }, - { - "name": "log", - "header": "math" - }, - { - "name": "labs", - "header": "stdlib" - }, - { - "name": "modf", - "header": "math" - }, - { - "name": "pow", - "header": "math" - }, - { - "name": "sinh", - "header": "math" - }, - { - "name": "sin", - "header": "math" - }, - { - "name": "sqrt", - "header": "math" - }, - { - "name": "tanh", - "header": "math" - }, - { - "name": "tan", - "header": "math" - }, - { - "name": "calloc", - "header": "stdlib" - }, - { - "name": "exit", - "header": "stdlib" - }, - { - "name": "fprintf", - "header": "stdio" - }, - { - "name": "fputs", - "header": "stdio" - }, - { - "name": "free", - "header": "stdlib" - }, - { - "name": "fscanf", - "header": "stdio" - }, - { - "name": "malloc", - "header": "stdlib" - }, - { - "name": "printf", - "header": "stdio" - }, - { - "name": "putchar", - "header": "stdio" - }, - { - "name": "puts", - "header": "stdio" - }, - { - "name": "realloc", - "header": "stdlib" - }, - { - "name": "scanf", - "header": "stdio" - }, - { - "name": "snprintf", - "header": "stdio" - }, - { - "name": "sprintf", - "header": "stdio" - }, - { - "name": "sscanf", - "header": "stdio" - }, - { - "name": "vfprintf", - "header": "stdio" - }, - { - "name": "vprintf", - "header": "stdio" - }, - { - "name": "vsprintf", - "header": "stdio" - } -] \ No newline at end of file diff --git a/tools/gcc-wrapper/filesystem.c b/tools/gcc-wrapper/filesystem.c new file mode 100644 index 0000000..7fd943e --- /dev/null +++ b/tools/gcc-wrapper/filesystem.c @@ -0,0 +1,26 @@ +#include +#include + +#include + +char* get_app_filename(void) { + /* + Returns the filename of the application's executable. + + Returns a null pointer on error. + */ + + char* app_filename = malloc(PATH_MAX); + + if (app_filename == NULL) { + return NULL; + } + + if (readlink("/proc/self/exe", app_filename, PATH_MAX) == -1) { + free(app_filename); + return NULL; + } + + return app_filename; + +} diff --git a/tools/gcc-wrapper/filesystem.h b/tools/gcc-wrapper/filesystem.h new file mode 100644 index 0000000..0c16add --- /dev/null +++ b/tools/gcc-wrapper/filesystem.h @@ -0,0 +1,6 @@ +#if !defined(FILESYSTEM_H) +#define FILESYSTEM_H + +char* get_app_filename(void); + +#endif diff --git a/tools/gcc-wrapper/main.c b/tools/gcc-wrapper/main.c new file mode 100644 index 0000000..b5d16bf --- /dev/null +++ b/tools/gcc-wrapper/main.c @@ -0,0 +1,198 @@ +#include +#include +#include +#include + +#include + +#include "filesystem.h" +#include "path.h" +#include "pathsep.h" + +#define GCC "gcc" +#define GPLUSPLUS "g++" + +int main(int argc, char* argv[], char* envp[]) { + + int status = EXIT_SUCCESS; + size_t size = 0; + + char** args = NULL; + char* arg = NULL; + + const char* cc = NULL; + const char* start = NULL; + const char* ptr = NULL; + + char* executable = NULL; + + char* sysroot_directory = NULL; + char* parent_directory = NULL; + + char* fname = NULL; + char* app_filename = NULL; + + char* triplet = NULL; + char* glibc_version = NULL; + + app_filename = get_app_filename(); + + if (app_filename == NULL) { + fprintf(stderr, "fatal error: could not get app filename\n"); + + status = EXIT_FAILURE; + goto end; + } + + fname = basename(app_filename); + + parent_directory = malloc(strlen(app_filename) + 1); + + if (parent_directory == NULL) { + fprintf(stderr, "fatal error: could not allocate memory\n"); + + status = EXIT_FAILURE; + goto end; + } + + get_parent_directory(app_filename, parent_directory, 1); + + ptr = strchr(fname, '\0'); + cc = ptr - 3; + + if (!(strcmp(cc, GCC) == 0 || strcmp(cc, GPLUSPLUS) == 0)) { + fprintf(stderr, "fatal error: unknown GCC compiler: %s\n", cc); + + status = EXIT_FAILURE; + goto end; + } + + ptr = fname; + + while (1) { + const unsigned char a = *ptr; + const unsigned char b = *(ptr + 1); + + if (isdigit(a) && b == '.') { + break; + } + + ptr++; + } + + size = (size_t) (ptr - fname); + + triplet = malloc(size + 1); + + if (triplet == NULL) { + fprintf(stderr, "fatal error: could not allocate memory\n"); + + status = EXIT_FAILURE; + goto end; + } + + memcpy(triplet, fname, size); + triplet[size] = '\0'; + + start = ptr; + + while (1) { + const unsigned char a = *ptr; + + if (a == '-') { + break; + } + + ptr++; + } + + size = (size_t) (ptr - start); + + glibc_version = malloc(size + 1); + + if (glibc_version == NULL) { + fprintf(stderr, "fatal error: could not allocate memory\n"); + + status = EXIT_FAILURE; + goto end; + } + + memcpy(glibc_version, start, size); + glibc_version[size] = '\0'; + + executable = malloc(strlen(parent_directory) + strlen(PATHSEP) + strlen(triplet) + 1 + strlen(cc) + 1); + + if (executable == NULL) { + fprintf(stderr, "fatal error: could not allocate memory\n"); + + status = EXIT_FAILURE; + goto end; + } + + strcpy(executable, parent_directory); + strcat(executable, PATHSEP); + strcat(executable, triplet); + strcat(executable, "-"); + strcat(executable, cc); + + get_parent_directory(app_filename, parent_directory, 2); + + sysroot_directory = malloc(strlen(parent_directory) + strlen(PATHSEP) + strlen(triplet) + strlen(glibc_version) + 1); + + if (sysroot_directory == NULL) { + fprintf(stderr, "fatal error: could not allocate memory\n"); + + status = EXIT_FAILURE; + goto end; + } + + strcpy(sysroot_directory, parent_directory); + strcat(sysroot_directory, PATHSEP); + strcat(sysroot_directory, triplet); + strcat(sysroot_directory, glibc_version); + + args = malloc(sizeof(char*) * (argc + 2)); + + if (args == NULL) { + fprintf(stderr, "fatal error: could not allocate memory\n"); + + status = EXIT_FAILURE; + goto end; + } + + arg = malloc(10 + strlen(sysroot_directory) + 1); + + if (arg == NULL) { + fprintf(stderr, "fatal error: could not allocate memory\n"); + + status = EXIT_FAILURE; + goto end; + } + + strcpy(arg, "--sysroot="); + strcat(arg, sysroot_directory); + + args[0] = executable; + args[1] = arg; + + memcpy(&args[2], &argv[1], argc * sizeof(*argv)); + + if (execve(executable, args, envp) == -1) { + status = EXIT_FAILURE; + goto end; + } + + end:; + + free(triplet); + free(glibc_version); + free(executable); + free(sysroot_directory); + free(app_filename); + free(args); + free(arg); + + return status; + +} + diff --git a/tools/gcc-wrapper/path.c b/tools/gcc-wrapper/path.c new file mode 100644 index 0000000..ea8ef0a --- /dev/null +++ b/tools/gcc-wrapper/path.c @@ -0,0 +1,93 @@ +#include +#include +#include + +#include "path.h" +#include "pathsep.h" + +static int isabsolute(const char* const path) { + + const int status = (*path == *PATHSEP); + return status; + +} + +char* basename(const char* const path) { + /* + Returns the final component of a path. + */ + + char* last_comp = (char*) path; + + while (1) { + char* slash_at = strchr(last_comp, PATHSEP[0]); + + if (slash_at == NULL) { + break; + } + + last_comp = slash_at + 1; + } + + return last_comp; + +} + +size_t get_parent_directory(const char* const source, char* const destination, const size_t maxdepth) { + /* + Get the parent directory up to the specified "maxdepth" depth of a path. + + Returns: + + - If the "destination" parameter is NULL, this will return the required size + for the buffer (not including the null-terminator). + + - If the "destination" parameter is not NULL, this will return the number of + characters written into the buffer (not including the null-terminator). + */ + + size_t index = 0; + size_t depth = 1; + size_t wsize = 0; + + if (destination != NULL) { + destination[0] = '\0'; + } + + for (index = strlen(source) - 1; index-- > 0;) { + const char ch = source[index]; + + if (ch == PATHSEP[0] && depth++ == maxdepth) { + const size_t size = (size_t) ((source + index) - source); + + if (destination != NULL) { + if (size > 0) { + memcpy(destination, source, size); + destination[size] = '\0'; + } else { + strcat(destination, PATHSEP); + } + } + + wsize += (size > 0) ? size : 1; + + break; + } + + if (index == 0 && isabsolute(source)) { + const size_t size = 1; + + wsize += size; + + if (destination != NULL) { + memcpy(destination, source, size); + destination[size] = '\0'; + } + + break; + } + } + + return wsize; + +} diff --git a/tools/gcc-wrapper/path.h b/tools/gcc-wrapper/path.h new file mode 100644 index 0000000..4ea024d --- /dev/null +++ b/tools/gcc-wrapper/path.h @@ -0,0 +1,7 @@ +#if !defined(PATH_H) +#define PATH_H + +char* basename(const char* const path); +size_t get_parent_directory(const char* const source, char* const destination, const size_t depth); + +#endif diff --git a/tools/gcc-wrapper/pathsep.h b/tools/gcc-wrapper/pathsep.h new file mode 100644 index 0000000..8b30bf4 --- /dev/null +++ b/tools/gcc-wrapper/pathsep.h @@ -0,0 +1,6 @@ +#if !defined(PATHSEP_H) +#define PATHSEP_H + +static const char PATHSEP[] = "/"; + +#endif diff --git a/tools/make_builtins.py b/tools/make_builtins.py deleted file mode 100644 index 1cb9b33..0000000 --- a/tools/make_builtins.py +++ /dev/null @@ -1,131 +0,0 @@ -import json -import os -import subprocess -import tempfile -import shutil - -headers = ( - "math", - "stdio", - "complex", - "stdlib", - "ctype", - "wctype", - "inttypes" -) - -source = """\ -#include <%s.h> - -int main(void) { - (void) %s; - return 0; -} -""" - -destination = """\ -/* This file is auto generated. */ -%s -""" - -temporary_file = os.path.join(tempfile.gettempdir(), "main.c") - -symbols_file = os.path.join( - os.path.dirname(p = __file__), - "builtin_symbols.json" -) - -class Builtins: - - def __init__(self): - self.math = [] - self.stdio = [] - self.complex = [] - self.stdlib = [] - self.ctype = [] - self.wctype = [] - self.inttypes = [] - -content = None - -cc = os.getenv(key = "CC") -c_include_path = os.getenv(key = "C_INCLUDE_PATH") - -assert cc is not None -assert c_include_path is not None - -def check_symbols_exists(symbol): - - (name, header) = (symbol["name"], symbol["header"]) - - text = source % (header, name) - - with open(file = temporary_file, mode = "w") as file: - file.write(text) - - process = subprocess.run([cc, "-std=c11", "-w", "-fno-builtin", temporary_file, "-o", "%s.o" % temporary_file]) - - return process.returncode == 0 - -def dump_builtins(builtins, name): - - s = "" - - items = getattr(builtins, name) - - if not items: - return None - - items.sort() - - for item in items: - s += ("\n#if !defined(%s)\n#define %s __builtin_%s\n#endif\n" % (item, item, item)) - - dump = destination % ( - s - ) - - with open(file = "builtin_%s.h" % (name), mode = "w") as file: - file.write(dump) - -with open(file = symbols_file, mode = "r") as file: - content = file.read() - -symbols = json.loads(s = content) - -builtins = Builtins() - -for symbol in symbols: - exists = check_symbols_exists(symbol = symbol) - - if exists: - continue - - (name, header) = ( - symbol["name"], - symbol["header"] - ) - - items = getattr(builtins, header) - items.append(name) - -for name in headers: - dump_builtins(builtins = builtins, name = name) - - src = "builtin_%s.h" % (name) - dst = os.path.join(c_include_path, "%s.h" % (name)) - - if not os.path.exists(path = src): - continue - - print("- Modifying '%s'" % (dst)) - - with open(file = dst, mode = "a+") as file: - file.write("\n\n#include <%s>" % (src)) - - dst = os.path.join(c_include_path, src) - - if os.path.exists(path = dst): - os.remove(dst) - - shutil.move(src = src, dst = dst)