Compare commits

...

18 Commits

Author SHA1 Message Date
PeroSar 02735ff5e0 debug
continuous-integration/drone Build is failing Details
2023-10-02 18:37:10 +05:30
PeroSar 40541cc651 update gcc to 13.2.0 and binutils to 2.41
continuous-integration/drone Build is failing Details
2023-09-24 12:24:48 +05:30
PeroSar 917494dda3 back to tildegit 2023-09-24 10:09:04 +05:30
PeroSar 8ac0281347
Test build 2
Signed-off-by: PeroSar <perosar1111@gmail.com>
2022-06-04 14:08:26 +05:30
PeroSar 4866826814
emerald-get-relver: Fix for BusyBox grep
Signed-off-by: PeroSar <perosar1111@gmail.com>
2022-06-04 11:10:26 +05:30
PeroSar d88e689c3a
gcc: Use prebuilts from alpine repo to reduce compile time
Signed-off-by: PeroSar <perosar1111@gmail.com>
2022-06-04 10:50:01 +05:30
PeroSar 9fee6a0d25
emerald-post-gcc-build: Fix for BusyBox grep
Signed-off-by: PeroSar <perosar1111@gmail.com>
2022-06-04 10:35:26 +05:30
PeroSar 3ed698bc14
Test build with musl libc
Signed-off-by: PeroSar <perosar1111@gmail.com>
2022-06-04 10:10:58 +05:30
PeroSar ac43b015ba
Prepare for env git migration
Signed-off-by: PeroSar <perosar1111@gmail.com>
2022-06-03 23:00:30 +05:30
PeroSar 15255af004
bin: add emerald-alignfix
Fixes static executables to be able to run on device

Signed-off-by: PeroSar <perosar1111@gmail.com>
2022-05-13 16:31:41 +05:30
PeroSar 5d27e221b7
gcc: enable fortran support
continuous-integration/drone Build is passing Details
Signed-off-by: PeroSar <perosar1111@gmail.com>
2022-05-11 14:33:35 +05:30
PeroSar 3c7f57bb28
patches/gcc/12.1.0: remove useless patches
Signed-off-by: PeroSar <perosar1111@gmail.com>
2022-05-10 23:02:32 +05:30
PeroSar bdb8ca26fb
format shell scripts with shfmt
shfmt -sr -w -ci bin/* *.sh

Signed-off-by: PeroSar <perosar1111@gmail.com>
2022-05-10 01:41:29 +05:30
PeroSar 8bd28b305f
gcc: copy more options from Arch Linux PKGBUILD
continuous-integration/drone Build is passing Details
Signed-off-by: PeroSar <perosar1111@gmail.com>
2022-05-08 22:59:26 +05:30
PeroSar b194ea6e98
emerald-post-gcc-build: Fix static linking
Previously, building with cargo was fixed, but static linking was broken

Signed-off-by: PeroSar <perosar1111@gmail.com>
2022-05-08 22:59:25 +05:30
PeroSar f04103c117
common: Statically link libstdc++
continuous-integration/drone Build is passing Details
Issue: /lib/x86_64-linux-gnu/libstdc++.so.6: version `GLIBCXX_3.4.29' not found (required by aarch64-linux-android-<...>)

Effected executables: aarch64-linux-android-ld.gold aarch64-linux-android-dwp

Signed-off-by: PeroSar <perosar1111@gmail.com>
2022-05-07 13:29:58 +05:30
PeroSar 4f8c6cdcae
Bump gcc to 12.1.0
continuous-integration/drone Build is passing Details
Signed-off-by: PeroSar <perosar1111@gmail.com>
2022-05-07 12:47:08 +05:30
PeroSar 5ff9af7795
fix rust builds, add ldd
Signed-off-by: PeroSar <perosar1111@gmail.com>
2022-05-06 23:49:12 +05:30
22 changed files with 774 additions and 33 deletions

View File

@ -9,16 +9,15 @@ trigger:
steps:
- name: build
image: ubuntu:20.04
image: alpine:latest
commands:
- apt update -yqq && apt install software-properties-common -yqq >/dev/null 2>&1 && add-apt-repository ppa:ubuntu-toolchain-r/test -y && apt install build-essential flex texinfo curl xz-utils gcc-11 g++-11 -yqq >/dev/null 2>&1
- ln -sf $(which gcc-11) $(which gcc) && ln -sf $(which g++-11) $(which g++)
- bash emerald-binutils.sh && rm -rf build
- apk add --no-cache g++ texinfo make curl xz-static xz xz-dev bash patch isl-dev gmp-dev mpfr-dev libgomp mpc1-dev clang llvm libunwind-static compiler-rt lld bison linux-headers gettext-dev build-base gettext-static
- bash binutils-is-llvm.sh
- bash emerald-binutils.sh
- bash emerald-sysroot.sh
- bash emerald-gcc.sh
- bash emerald-post-gcc-build.sh
- env XZ_OPT="-9 -T0" tar -C /tmp -cJf aarch64-linux-android-emerald.tar.xz aarch64-linux-android-emerald
- bash emerald-get-relver.sh
- name: release
image: tystuyfzand/drone-gitea-release

View File

@ -1,6 +1,6 @@
# Emerald GCC
[![Drone CI](https://img.shields.io/drone/build/PeroSar/emerald-gcc?logo=drone&logoColor=blue&server=https%3A%2F%2Fdrone.tildegit.org)](https://drone.tildegit.org/PeroSar/emerald-gcc)
[![Drone CI](https://img.shields.io/drone/build/perosar/emerald-gcc?logo=drone&logoColor=blue&server=https%3A%2F%2Fdrone.tildegit.org)](https://drone.envs.netg/perosar/emerald-gcc)
## About
@ -16,7 +16,7 @@ Some projects still require GCC for building.
## How to use
- Get tarball from latest [gitea release](https://tildegit.org/PeroSar/emerald-gcc/releases)
- Get tarball from latest [gitea release](https://tildegit.org/perosar/emerald-gcc/releases)
- Extract
```bash
@ -46,4 +46,5 @@ Compiled executables should run properly on Android 8 and above.
- Patches from [its-pointless](https://github.com/its-pointless)
- Patches from [Android GCC 4.9](https://android.googlesource.com/toolchain/gcc)
- Sysroot from [NDK](https://github.com/android/ndk)
- Align fix script from [termux-ndk](https://github.com/Lzhiyong/termux-ndk/blob/master/patches/align_fix.py)
- Wiki pages from [Termux](https://github.com/termux)

12
bin/aarch64-linux-android-ldd Executable file
View File

@ -0,0 +1,12 @@
#!/usr/bin/env sh
USAGE="$(basename "$0") (Emerald GCC)
Usage: ldd FILE..."
BIN_PATH=$(dirname "$(realpath "$0")")
OBJDUMP="$BIN_PATH/aarch64-linux-android-objdump"
case $# in
0) echo "$USAGE" ;;
1) $OBJDUMP -p -- "$@" | grep NEEDED | cut -d' ' -f18 ;;
*) $OBJDUMP -p -- "$@" | grep 'NEEDED\|file format' | cut -d' ' -f1,18 ;;
esac

56
bin/emerald-alignfix Executable file
View File

@ -0,0 +1,56 @@
#!/usr/bin/env python3
import struct
import sys
import os
if len(sys.argv) < 2:
print('Usage: ' + os.path.basename(sys.argv[0]) + ' input_file')
exit()
with open(sys.argv[1], 'r+b') as f:
f.seek(0)
hdr = f.read(16)
if hdr[0] != 0x7f or hdr[1] != ord('E') or hdr[2] != ord('L') or hdr[3] != ord('F'):
raise Exception('Not an elf file')
if hdr[4] == 1:
# 32 bit code
f.seek(28)
offset = struct.unpack('<I', f.read(4))[0]
f.seek(42)
phsize = struct.unpack('<H', f.read(2))[0]
phnum = struct.unpack('<H', f.read(2))[0]
for i in range(0, phnum):
f.seek(offset + i * phsize)
t = struct.unpack('<I', f.read(4))[0]
if t == 7:
f.seek(28 - 4, 1)
align = struct.unpack('<I', f.read(4))[0]
print('Found TLS segment with align = ' + str(align))
if (align < 32):
print('TLS segment is underaligned, patching')
f.seek(-4, 1)
f.write(struct.pack('<I', 32))
elif hdr[4] == 2:
# 64 bit code
f.seek(32)
offset = struct.unpack('<Q', f.read(8))[0]
f.seek(54)
phsize = struct.unpack('<H', f.read(2))[0]
phnum = struct.unpack('<H', f.read(2))[0]
for i in range(0, phnum):
f.seek(offset + i * phsize)
t = struct.unpack('<I', f.read(4))[0]
if t == 7:
f.seek(48 - 4, 1)
align = struct.unpack('<Q', f.read(8))[0]
print('Found TLS segment with align = ' + str(align))
if (align < 64):
print('TLS segment is underaligned, patching')
f.seek(-8, 1)
f.write(struct.pack('<H', 64))
else:
raise Exception('Unknown file class')

9
binutils-is-llvm.sh Executable file
View File

@ -0,0 +1,9 @@
#!/usr/bin/env bash
cd /usr/bin
for b in addr2line ar as dwp nm objcopy objdump ranlib readelf size strings strip c++filt; do
ln -sf llvm-"${b/+/x}" "$b"
done
ln -sf lld ld

View File

@ -1,17 +1,24 @@
#!/usr/bin/env bash
TARGET=aarch64-linux-android
export TARGET=aarch64-linux-android
export PREFIX=/tmp/"$TARGET"-emerald
export CFLAGS="-O3"
export EMERALD_SCRIPT_DIR=$(dirname "$(realpath "$0")")
export EMERALD_BUILD_DIR="$EMERALD_SCRIPT_DIR"/build
export EMERALD_DL_DIR="$EMERALD_SCRIPT_DIR"/dl
export CC=clang
export CXX=clang++
export CFLAGS="-O3 -march=x86-64 -mtune=generic"
export CPPFLAGS="$CFLAGS"
export CXXFLAGS="$CFLAGS"
export LDFLAGS="-s -w"
export LDFLAGS="-Wl,--as-needed -L/usr/lib -lintl -llzma -s -w -static --static -rtlib=compiler-rt -unwindlib=libunwind"
export CFLAGS_FOR_TARGET="$CFLAGS"
export CPPFLAGS_FOR_TARGET="$CFLAGS"
export CXXFLAGS_FOR_TARGET="$CFLAGS"
export LDFLAGS_FOR_TARGET="$LDFLAGS"
export LDFLAGS_FOR_TARGET="-s -w"
download() {
if [ $# != 3 ]; then

View File

@ -4,11 +4,9 @@ set -euo pipefail
EMERALD_SCRIPT_DIR=$(dirname "$(realpath "$0")")
BINUTILS_VER=2.38
BINUTILS_SHA256=e316477a914f567eccc34d5d29785b8b0f5a10208d36bbacedcc39048ecfe024
BINUTILS_VER=2.41
BINUTILS_SHA256=ae9a5789e23459e59606e6714723f2d3ffc31c03174191ef0d015bdf06007450
EMERALD_BUILD_DIR="$EMERALD_SCRIPT_DIR"/build
EMERALD_DL_DIR="$EMERALD_SCRIPT_DIR"/dl
source "$EMERALD_SCRIPT_DIR"/common.sh
# Make sure build/dl directory exists
@ -23,14 +21,19 @@ fi
cd "$EMERALD_BUILD_DIR"/binutils-"$BINUTILS_VER"
# Bit of patching
sed -i 's|DCL_FGETPOS64 (fgetpos64)||g' gprofng/libcollector/iotrace.c
sed -i 's|DCL_FSETPOS (fsetpos)||g' gprofng/libcollector/iotrace.c
sed -i 's|DCL_OPEN64 (open64)||g' gprofng/libcollector/iotrace.c
# Its suggested to run configure from a seperate directory
mkdir -vp build && cd "$_"
# Configuration
../configure --target="$TARGET" --prefix="$PREFIX" \
--disable-werror --enable-gold \
--enable-plugins --disable-nls
--enable-plugins --disable-nls || cat config.log
# Building
make -j4
make -j$(nproc --all)
make install -j1

View File

@ -4,11 +4,9 @@ set -euo pipefail
EMERALD_SCRIPT_DIR=$(dirname "$(realpath "$0")")
GCC_VER=11.3.0
GCC_SHA256=b47cf2818691f5b1e21df2bb38c795fac2cfbd640ede2d0a5e1c89e338a3ac39
GCC_VER=13.2.0
GCC_SHA256=e275e76442a6067341a27f04c5c6b83d8613144004c0413528863dc6b5c743da
EMERALD_BUILD_DIR="$EMERALD_SCRIPT_DIR"/build
EMERALD_DL_DIR="$EMERALD_SCRIPT_DIR"/dl
source "$EMERALD_SCRIPT_DIR"/common.sh
# Make sure build and dl directory exists
@ -18,28 +16,32 @@ mkdir -vp "$EMERALD_BUILD_DIR" "$EMERALD_DL_DIR"
download https://ftp.gnu.org/gnu/gcc/gcc-"$GCC_VER"/gcc-"$GCC_VER".tar.xz "$EMERALD_DL_DIR"/gcc-"$GCC_VER".tar.xz "$GCC_SHA256"
if [ ! -d "$EMERALD_BUILD_DIR"/gcc-"$GCC_VER" ]; then
tar --directory="$EMERALD_BUILD_DIR" -xJf "$EMERALD_DL_DIR"/gcc-"$GCC_VER".tar.xz
tar --directory="$EMERALD_BUILD_DIR" -xJf "$EMERALD_DL_DIR"/gcc-"$GCC_VER".tar.xz
fi
cd "$EMERALD_BUILD_DIR"/gcc-"$GCC_VER"
# Download prerequisites
./contrib/download_prerequisites
# Apply patches
find "$EMERALD_SCRIPT_DIR"/patches/gcc/"$GCC_VER" -type f -name '*.patch' -exec patch -p0 -i {} \;
./contrib/download_prerequisites
# Its suggested to run configure from a seperate directory
mkdir -vp build && cd "$_"
# Configuration
../configure --target="$TARGET" --prefix="$PREFIX" \
--enable-plugins --without-headers \
--with-gnu-as --with-gnu-ld \
--enable-languages=c,c++ --with-pkgversion='Emerald' \
--enable-default-pie --enable-gnu-indirect-function \
--disable-libsanitizer --disable-nls
--enable-plugins --without-headers \
--with-gnu-as --with-gnu-ld \
--enable-languages=c,c++,fortran --with-pkgversion='Emerald' \
--enable-default-pie --enable-gnu-indirect-function \
--disable-libsanitizer --disable-nls \
--enable-threads=posix --enable-__cxa_atexit \
--enable-clocale=gnu --disable-libstdcxx-pch \
--with-bugurl='https://tildegit.org/PeroSar/emerald-gcc/issues'
# Building
make -j4
make -j$(nproc --all)
export PATH="$PREFIX/bin:$PATH"
make install-strip -j1

View File

@ -1,7 +1,7 @@
#!/usr/bin/env bash
GCC_VER=$(grep -P -m1 '^GCC_VER=' emerald-gcc.sh | cut -d= -f2)
BINUTILS_VER=$(grep -P -m1 '^BINUTILS_VER=' emerald-binutils.sh | cut -d= -f2)
GCC_VER=$(grep -m1 '^GCC_VER=' emerald-gcc.sh | cut -d= -f2)
BINUTILS_VER=$(grep -m1 '^BINUTILS_VER=' emerald-binutils.sh | cut -d= -f2)
echo "emerald: GCC v$GCC_VER, Binutils v$BINUTILS_VER" > title.txt
echo "$GCC_VER" > tag.txt

21
emerald-post-gcc-build.sh Executable file
View File

@ -0,0 +1,21 @@
#!/usr/bin/env bash
set -euo pipefail
EMERALD_SCRIPT_DIR=$(dirname "$(realpath "$0")")
GCC_VER=$(grep -m1 '^GCC_VER=' "$EMERALD_SCRIPT_DIR"/emerald-gcc.sh | cut -d= -f2)
source "$EMERALD_SCRIPT_DIR"/common.sh
AR=$PREFIX/$TARGET/bin/ar
cd "$PREFIX"
# Fix rust builds
(
cd lib/gcc/"$TARGET"/"$GCC_VER"/
LIBGCC_FILENAME=libgcc_$(base64 <<< $RANDOM$RANDOM | sed 's|=||g').a
mv libgcc.a "$LIBGCC_FILENAME"
$AR crsT libgcc.a "$LIBGCC_FILENAME" libgcc_eh.a
)
# Install helper scripts
install -Dm755 -t bin "$EMERALD_SCRIPT_DIR"/bin/*

View File

@ -0,0 +1,69 @@
--- /dev/null 2022-03-10 14:56:30.584000000 +1100
+++ gcc/config/aarch64/aarch64-linux-android.h 2022-04-26 15:48:56.533607085 +1000
@@ -0,0 +1,66 @@
+/* Machine description for AArch64 architecture.
+ Copyright (C) 2014 Free Software Foundation, Inc.
+
+ This file is part of GCC.
+
+ GCC is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your option)
+ any later version.
+
+ GCC is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GCC; see the file COPYING3. If not see
+ <http://www.gnu.org/licenses/>. */
+
+#ifndef GCC_AARCH64_LINUX_ANDROID_H
+#define GCC_AARCH64_LINUX_ANDROID_H
+
+
+#undef TARGET_OS_CPP_BUILTINS
+#define TARGET_OS_CPP_BUILTINS() \
+ do \
+ { \
+ GNU_USER_TARGET_OS_CPP_BUILTINS(); \
+ ANDROID_TARGET_OS_CPP_BUILTINS(); \
+ } \
+ while (0)
+
+#undef LINK_SPEC
+#define LINK_SPEC \
+ LINUX_OR_ANDROID_LD (LINUX_TARGET_LINK_SPEC, \
+ LINUX_TARGET_LINK_SPEC " " ANDROID_LINK_SPEC)
+
+#undef CC1_SPEC
+#define CC1_SPEC \
+ LINUX_OR_ANDROID_CC (GNU_USER_TARGET_CC1_SPEC, \
+ GNU_USER_TARGET_CC1_SPEC " " ANDROID_CC1_SPEC("-fpic"))
+
+#define CC1PLUS_SPEC \
+ LINUX_OR_ANDROID_CC ("", ANDROID_CC1PLUS_SPEC)
+
+#undef LIB_SPEC
+#define LIB_SPEC \
+ LINUX_OR_ANDROID_LD (GNU_USER_TARGET_LIB_SPEC, \
+ GNU_USER_TARGET_NO_PTHREADS_LIB_SPEC " " ANDROID_LIB_SPEC)
+
+#undef STARTFILE_SPEC
+#define STARTFILE_SPEC \
+ LINUX_OR_ANDROID_LD (GNU_USER_TARGET_STARTFILE_SPEC, ANDROID_STARTFILE_SPEC)
+
+#undef ENDFILE_SPEC
+#define ENDFILE_SPEC \
+ LINUX_OR_ANDROID_LD (GNU_USER_TARGET_ENDFILE_SPEC, ANDROID_ENDFILE_SPEC)
+
+#ifdef IN_LIBGCC2
+#define LIBGCC2_UNWIND_ATTRIBUTE __attribute__((visibility("default")))
+#endif
+
+#define STARTFILE_PREFIX_SPEC \
+ "/usr/lib/"
+
+#endif /* GCC_AARCH64_LINUX_ANDROID_H */

View File

@ -0,0 +1,20 @@
--- gcc/config/aarch64/aarch64-linux.h.bak 2022-04-26 15:37:28.201223209 +1000
+++ gcc/config/aarch64/aarch64-linux.h 2022-04-26 15:40:40.671532123 +1000
@@ -21,7 +21,16 @@
#ifndef GCC_AARCH64_LINUX_H
#define GCC_AARCH64_LINUX_H
-#define GLIBC_DYNAMIC_LINKER "/lib/ld-linux-aarch64%{mbig-endian:_be}%{mabi=ilp32:_ilp32}.so.1"
+#ifndef RUNTIME_ROOT_PREFIX
+#define RUNTIME_ROOT_PREFIX ""
+#endif
+
+#define GLIBC_DYNAMIC_LINKER RUNTIME_ROOT_PREFIX "/lib/ld-linux-aarch64%{mbig-endian:_be}%{mabi=ilp32:_ilp32}.so.1"
+
+#ifdef BIONIC_DYNAMIC_LINKER
+#undef BIONIC_DYNAMIC_LINKER
+#endif
+#define BIONIC_DYNAMIC_LINKER RUNTIME_ROOT_PREFIX "/system/bin/linker64"
#undef MUSL_DYNAMIC_LINKER
#define MUSL_DYNAMIC_LINKER "/lib/ld-musl-aarch64%{mbig-endian:_be}%{mabi=ilp32:_ilp32}.so.1"

View File

@ -0,0 +1,26 @@
--- gcc/config/linux-android.h.bak 2022-04-26 15:52:59.964626084 +1000
+++ gcc/config/linux-android.h 2022-04-26 15:59:36.466061086 +1000
@@ -44,15 +44,18 @@
"%{" NOANDROID "|tno-android-ld:" LINUX_SPEC ";:" ANDROID_SPEC "}"
#define ANDROID_LINK_SPEC \
- "%{shared: -Bsymbolic}"
+ "%{shared: -Bsymbolic} -z noexecstack -z relro -z now"
-#define ANDROID_CC1_SPEC \
+#define ANDROID_CC1_SPEC(ANDROID_PIC_DEFAULT) \
"%{!mglibc:%{!muclibc:%{!mbionic: -mbionic}}} " \
- "%{!fno-pic:%{!fno-PIC:%{!fpic:%{!fPIC: -fPIC}}}}"
+ "%{!fno-pic:%{!fno-PIC:%{!fpic:%{!fPIC: " ANDROID_PIC_DEFAULT "}}}}"
#define ANDROID_CC1PLUS_SPEC \
- "%{!fexceptions:%{!fno-exceptions: -fno-exceptions}} " \
- "%{!frtti:%{!fno-rtti: -fno-rtti}}"
+ "%{!fexceptions:%{!fno-exceptions: -fexceptions}} " \
+ "%{!frtti:%{!fno-rtti: -frtti}}"
+
+#define ANDROID_ASM_SPEC \
+ "--noexecstack"
#define ANDROID_LIB_SPEC \
"%{!static: -ldl}"

View File

@ -0,0 +1,22 @@
--- gcc/config.gcc.bak 2022-04-26 15:19:45.302214622 +1000
+++ gcc/config.gcc 2022-04-26 15:26:29.605836585 +1000
@@ -1136,14 +1136,18 @@
extra_options="${extra_options} netbsd.opt netbsd-elf.opt"
;;
aarch64*-*-linux*)
- tm_file="${tm_file} dbxelf.h elfos.h gnu-user.h linux.h glibc-stdint.h"
+ tm_file="${tm_file} dbxelf.h elfos.h gnu-user.h linux.h linux-android.h glibc-stdint.h"
tm_file="${tm_file} aarch64/aarch64-elf.h aarch64/aarch64-errata.h aarch64/aarch64-linux.h"
+ extra_options="${extra_options} linux-android.opt"
tmake_file="${tmake_file} aarch64/t-aarch64 aarch64/t-aarch64-linux"
tm_defines="${tm_defines} TARGET_DEFAULT_ASYNC_UNWIND_TABLES=1"
case $target in
aarch64_be-*)
tm_defines="${tm_defines} TARGET_BIG_ENDIAN_DEFAULT=1"
;;
+ aarch64*-*-linux-android*)
+ tm_file="${tm_file} aarch64/aarch64-linux-android.h"
+ ;;
esac
aarch64_multilibs="${with_multilib_list}"
if test "$aarch64_multilibs" = "default"; then

View File

@ -0,0 +1,153 @@
--- gcc/system.h.bak 2022-04-26 16:18:06.956629449 +1000
+++ gcc/system.h 2022-04-26 16:21:36.747332234 +1000
@@ -50,150 +50,6 @@
#define NULL 0
#endif
-/* Use the unlocked open routines from libiberty. */
-
-/* Some of these are #define on some systems, e.g. on AIX to redirect
- the names to 64bit capable functions for LARGE_FILES support. These
- redefs are pointless here so we can override them. */
-
-#undef fopen
-#undef freopen
-
-#define fopen(PATH, MODE) fopen_unlocked (PATH, MODE)
-#define fdopen(FILDES, MODE) fdopen_unlocked (FILDES, MODE)
-#define freopen(PATH, MODE, STREAM) freopen_unlocked (PATH, MODE, STREAM)
-
-/* The compiler is not a multi-threaded application and therefore we
- do not have to use the locking functions. In fact, using the locking
- functions can cause the compiler to be significantly slower under
- I/O bound conditions (such as -g -O0 on very large source files).
-
- HAVE_DECL_PUTC_UNLOCKED actually indicates whether or not the stdio
- code is multi-thread safe by default. If it is set to 0, then do
- not worry about using the _unlocked functions.
-
- fputs_unlocked, fwrite_unlocked, and fprintf_unlocked are
- extensions and need to be prototyped by hand (since we do not
- define _GNU_SOURCE). */
-
-#if defined HAVE_DECL_PUTC_UNLOCKED && HAVE_DECL_PUTC_UNLOCKED
-
-# ifdef HAVE_PUTC_UNLOCKED
-# undef putc
-# define putc(C, Stream) putc_unlocked (C, Stream)
-# endif
-# ifdef HAVE_PUTCHAR_UNLOCKED
-# undef putchar
-# define putchar(C) putchar_unlocked (C)
-# endif
-# ifdef HAVE_GETC_UNLOCKED
-# undef getc
-# define getc(Stream) getc_unlocked (Stream)
-# endif
-# ifdef HAVE_GETCHAR_UNLOCKED
-# undef getchar
-# define getchar() getchar_unlocked ()
-# endif
-# ifdef HAVE_FPUTC_UNLOCKED
-# undef fputc
-# define fputc(C, Stream) fputc_unlocked (C, Stream)
-# endif
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-# ifdef HAVE_CLEARERR_UNLOCKED
-# undef clearerr
-# define clearerr(Stream) clearerr_unlocked (Stream)
-# if defined (HAVE_DECL_CLEARERR_UNLOCKED) && !HAVE_DECL_CLEARERR_UNLOCKED
-extern void clearerr_unlocked (FILE *);
-# endif
-# endif
-# ifdef HAVE_FEOF_UNLOCKED
-# undef feof
-# define feof(Stream) feof_unlocked (Stream)
-# if defined (HAVE_DECL_FEOF_UNLOCKED) && !HAVE_DECL_FEOF_UNLOCKED
-extern int feof_unlocked (FILE *);
-# endif
-# endif
-# ifdef HAVE_FILENO_UNLOCKED
-# undef fileno
-# define fileno(Stream) fileno_unlocked (Stream)
-# if defined (HAVE_DECL_FILENO_UNLOCKED) && !HAVE_DECL_FILENO_UNLOCKED
-extern int fileno_unlocked (FILE *);
-# endif
-# endif
-# ifdef HAVE_FFLUSH_UNLOCKED
-# undef fflush
-# define fflush(Stream) fflush_unlocked (Stream)
-# if defined (HAVE_DECL_FFLUSH_UNLOCKED) && !HAVE_DECL_FFLUSH_UNLOCKED
-extern int fflush_unlocked (FILE *);
-# endif
-# endif
-# ifdef HAVE_FGETC_UNLOCKED
-# undef fgetc
-# define fgetc(Stream) fgetc_unlocked (Stream)
-# if defined (HAVE_DECL_FGETC_UNLOCKED) && !HAVE_DECL_FGETC_UNLOCKED
-extern int fgetc_unlocked (FILE *);
-# endif
-# endif
-# ifdef HAVE_FGETS_UNLOCKED
-# undef fgets
-# define fgets(S, n, Stream) fgets_unlocked (S, n, Stream)
-# if defined (HAVE_DECL_FGETS_UNLOCKED) && !HAVE_DECL_FGETS_UNLOCKED
-extern char *fgets_unlocked (char *, int, FILE *);
-# endif
-# endif
-# ifdef HAVE_FPUTS_UNLOCKED
-# undef fputs
-# define fputs(String, Stream) fputs_unlocked (String, Stream)
-# if defined (HAVE_DECL_FPUTS_UNLOCKED) && !HAVE_DECL_FPUTS_UNLOCKED
-extern int fputs_unlocked (const char *, FILE *);
-# endif
-# endif
-# ifdef HAVE_FERROR_UNLOCKED
-# undef ferror
-# define ferror(Stream) ferror_unlocked (Stream)
-# if defined (HAVE_DECL_FERROR_UNLOCKED) && !HAVE_DECL_FERROR_UNLOCKED
-extern int ferror_unlocked (FILE *);
-# endif
-# endif
-# ifdef HAVE_FREAD_UNLOCKED
-# undef fread
-# define fread(Ptr, Size, N, Stream) fread_unlocked (Ptr, Size, N, Stream)
-# if defined (HAVE_DECL_FREAD_UNLOCKED) && !HAVE_DECL_FREAD_UNLOCKED
-extern size_t fread_unlocked (void *, size_t, size_t, FILE *);
-# endif
-# endif
-# ifdef HAVE_FWRITE_UNLOCKED
-# undef fwrite
-# define fwrite(Ptr, Size, N, Stream) fwrite_unlocked (Ptr, Size, N, Stream)
-# if defined (HAVE_DECL_FWRITE_UNLOCKED) && !HAVE_DECL_FWRITE_UNLOCKED
-extern size_t fwrite_unlocked (const void *, size_t, size_t, FILE *);
-# endif
-# endif
-# ifdef HAVE_FPRINTF_UNLOCKED
-# undef fprintf
-/* We can't use a function-like macro here because we don't know if
- we have varargs macros. */
-# define fprintf fprintf_unlocked
-# if defined (HAVE_DECL_FPRINTF_UNLOCKED) && !HAVE_DECL_FPRINTF_UNLOCKED
-extern int fprintf_unlocked (FILE *, const char *, ...);
-# endif
-# endif
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
-
-/* ??? Glibc's fwrite/fread_unlocked macros cause
- "warning: signed and unsigned type in conditional expression". */
-#undef fread_unlocked
-#undef fwrite_unlocked
-
/* Include <string> before "safe-ctype.h" to avoid GCC poisoning
the ctype macros through safe-ctype.h */

View File

@ -0,0 +1,25 @@
--- libstdc++-v3/config/os/bionic/ctype_base.h.bak 2022-04-27 12:37:53.088346124 +0000
+++ libstdc++-v3/config/os/bionic/ctype_base.h 2022-04-27 12:39:38.444403143 +0000
@@ -28,6 +28,22 @@
// Information as gleaned from /usr/include/ctype.h
+#if defined (__ANDROID__)
+#if !defined(_U)
+#if !defined(_CTYPE_U)
+#error Bionic header ctype.h does not define either _U nor _CTYPE_U
+#endif
+#define _U _CTYPE_U
+#define _L _CTYPE_L
+#define _N _CTYPE_N
+#define _S _CTYPE_S
+#define _P _CTYPE_P
+#define _C _CTYPE_C
+#define _X _CTYPE_X
+#define _B _CTYPE_B
+#endif
+#endif /* __ANDROID__ */
+
namespace std _GLIBCXX_VISIBILITY(default)
{
_GLIBCXX_BEGIN_NAMESPACE_VERSION

View File

@ -0,0 +1,69 @@
--- /dev/null 2022-03-10 14:56:30.584000000 +1100
+++ gcc/config/aarch64/aarch64-linux-android.h 2022-04-26 15:48:56.533607085 +1000
@@ -0,0 +1,66 @@
+/* Machine description for AArch64 architecture.
+ Copyright (C) 2014 Free Software Foundation, Inc.
+
+ This file is part of GCC.
+
+ GCC is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your option)
+ any later version.
+
+ GCC is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GCC; see the file COPYING3. If not see
+ <http://www.gnu.org/licenses/>. */
+
+#ifndef GCC_AARCH64_LINUX_ANDROID_H
+#define GCC_AARCH64_LINUX_ANDROID_H
+
+
+#undef TARGET_OS_CPP_BUILTINS
+#define TARGET_OS_CPP_BUILTINS() \
+ do \
+ { \
+ GNU_USER_TARGET_OS_CPP_BUILTINS(); \
+ ANDROID_TARGET_OS_CPP_BUILTINS(); \
+ } \
+ while (0)
+
+#undef LINK_SPEC
+#define LINK_SPEC \
+ LINUX_OR_ANDROID_LD (LINUX_TARGET_LINK_SPEC, \
+ LINUX_TARGET_LINK_SPEC " " ANDROID_LINK_SPEC)
+
+#undef CC1_SPEC
+#define CC1_SPEC \
+ LINUX_OR_ANDROID_CC (GNU_USER_TARGET_CC1_SPEC, \
+ GNU_USER_TARGET_CC1_SPEC " " ANDROID_CC1_SPEC("-fpic"))
+
+#define CC1PLUS_SPEC \
+ LINUX_OR_ANDROID_CC ("", ANDROID_CC1PLUS_SPEC)
+
+#undef LIB_SPEC
+#define LIB_SPEC \
+ LINUX_OR_ANDROID_LD (GNU_USER_TARGET_LIB_SPEC, \
+ GNU_USER_TARGET_NO_PTHREADS_LIB_SPEC " " ANDROID_LIB_SPEC)
+
+#undef STARTFILE_SPEC
+#define STARTFILE_SPEC \
+ LINUX_OR_ANDROID_LD (GNU_USER_TARGET_STARTFILE_SPEC, ANDROID_STARTFILE_SPEC)
+
+#undef ENDFILE_SPEC
+#define ENDFILE_SPEC \
+ LINUX_OR_ANDROID_LD (GNU_USER_TARGET_ENDFILE_SPEC, ANDROID_ENDFILE_SPEC)
+
+#ifdef IN_LIBGCC2
+#define LIBGCC2_UNWIND_ATTRIBUTE __attribute__((visibility("default")))
+#endif
+
+#define STARTFILE_PREFIX_SPEC \
+ "/usr/lib/"
+
+#endif /* GCC_AARCH64_LINUX_ANDROID_H */

View File

@ -0,0 +1,20 @@
--- gcc/config/aarch64/aarch64-linux.h.bak 2022-04-26 15:37:28.201223209 +1000
+++ gcc/config/aarch64/aarch64-linux.h 2022-04-26 15:40:40.671532123 +1000
@@ -21,7 +21,16 @@
#ifndef GCC_AARCH64_LINUX_H
#define GCC_AARCH64_LINUX_H
-#define GLIBC_DYNAMIC_LINKER "/lib/ld-linux-aarch64%{mbig-endian:_be}%{mabi=ilp32:_ilp32}.so.1"
+#ifndef RUNTIME_ROOT_PREFIX
+#define RUNTIME_ROOT_PREFIX ""
+#endif
+
+#define GLIBC_DYNAMIC_LINKER RUNTIME_ROOT_PREFIX "/lib/ld-linux-aarch64%{mbig-endian:_be}%{mabi=ilp32:_ilp32}.so.1"
+
+#ifdef BIONIC_DYNAMIC_LINKER
+#undef BIONIC_DYNAMIC_LINKER
+#endif
+#define BIONIC_DYNAMIC_LINKER RUNTIME_ROOT_PREFIX "/system/bin/linker64"
#undef MUSL_DYNAMIC_LINKER
#define MUSL_DYNAMIC_LINKER "/lib/ld-musl-aarch64%{mbig-endian:_be}%{mabi=ilp32:_ilp32}.so.1"

View File

@ -0,0 +1,26 @@
--- gcc/config/linux-android.h.bak 2022-04-26 15:52:59.964626084 +1000
+++ gcc/config/linux-android.h 2022-04-26 15:59:36.466061086 +1000
@@ -44,15 +44,18 @@
"%{" NOANDROID "|tno-android-ld:" LINUX_SPEC ";:" ANDROID_SPEC "}"
#define ANDROID_LINK_SPEC \
- "%{shared: -Bsymbolic}"
+ "%{shared: -Bsymbolic} -z noexecstack -z relro -z now"
-#define ANDROID_CC1_SPEC \
+#define ANDROID_CC1_SPEC(ANDROID_PIC_DEFAULT) \
"%{!mglibc:%{!muclibc:%{!mbionic: -mbionic}}} " \
- "%{!fno-pic:%{!fno-PIC:%{!fpic:%{!fPIC: -fPIC}}}}"
+ "%{!fno-pic:%{!fno-PIC:%{!fpic:%{!fPIC: " ANDROID_PIC_DEFAULT "}}}}"
#define ANDROID_CC1PLUS_SPEC \
- "%{!fexceptions:%{!fno-exceptions: -fno-exceptions}} " \
- "%{!frtti:%{!fno-rtti: -fno-rtti}}"
+ "%{!fexceptions:%{!fno-exceptions: -fexceptions}} " \
+ "%{!frtti:%{!fno-rtti: -frtti}}"
+
+#define ANDROID_ASM_SPEC \
+ "--noexecstack"
#define ANDROID_LIB_SPEC \
"%{!static: -ldl}"

View File

@ -0,0 +1,23 @@
--- gcc/config.gcc.bak 2023-09-24 05:57:10.995496760 +0000
+++ gcc/config.gcc 2023-09-24 06:03:25.199104067 +0000
@@ -1145,6 +1145,9 @@
aarch64_be-*)
tm_defines="${tm_defines} TARGET_BIG_ENDIAN_DEFAULT=1"
;;
+ aarch64*-*-linux-android*)
+ tm_file="${tm_file} aarch64/aarch64-linux-android.h"
+ ;;
esac
aarch64_multilibs="${with_multilib_list}"
if test "$aarch64_multilibs" = "default"; then
@@ -1176,8 +1179,9 @@
extra_options="${extra_options} netbsd.opt netbsd-elf.opt"
;;
aarch64*-*-linux*)
- tm_file="${tm_file} elfos.h gnu-user.h linux.h glibc-stdint.h"
+ tm_file="${tm_file} elfos.h gnu-user.h linux.h linux-android.h glibc-stdint.h"
tm_file="${tm_file} aarch64/aarch64-elf.h aarch64/aarch64-errata.h aarch64/aarch64-linux.h"
+ extra_options="${extra_options} linux-android.opt"
tmake_file="${tmake_file} aarch64/t-aarch64 aarch64/t-aarch64-linux"
tm_defines="${tm_defines} TARGET_DEFAULT_ASYNC_UNWIND_TABLES=1"
case $target in

View File

@ -0,0 +1,153 @@
--- gcc/system.h.bak 2022-04-26 16:18:06.956629449 +1000
+++ gcc/system.h 2022-04-26 16:21:36.747332234 +1000
@@ -50,150 +50,6 @@
#define NULL 0
#endif
-/* Use the unlocked open routines from libiberty. */
-
-/* Some of these are #define on some systems, e.g. on AIX to redirect
- the names to 64bit capable functions for LARGE_FILES support. These
- redefs are pointless here so we can override them. */
-
-#undef fopen
-#undef freopen
-
-#define fopen(PATH, MODE) fopen_unlocked (PATH, MODE)
-#define fdopen(FILDES, MODE) fdopen_unlocked (FILDES, MODE)
-#define freopen(PATH, MODE, STREAM) freopen_unlocked (PATH, MODE, STREAM)
-
-/* The compiler is not a multi-threaded application and therefore we
- do not have to use the locking functions. In fact, using the locking
- functions can cause the compiler to be significantly slower under
- I/O bound conditions (such as -g -O0 on very large source files).
-
- HAVE_DECL_PUTC_UNLOCKED actually indicates whether or not the stdio
- code is multi-thread safe by default. If it is set to 0, then do
- not worry about using the _unlocked functions.
-
- fputs_unlocked, fwrite_unlocked, and fprintf_unlocked are
- extensions and need to be prototyped by hand (since we do not
- define _GNU_SOURCE). */
-
-#if defined HAVE_DECL_PUTC_UNLOCKED && HAVE_DECL_PUTC_UNLOCKED
-
-# ifdef HAVE_PUTC_UNLOCKED
-# undef putc
-# define putc(C, Stream) putc_unlocked (C, Stream)
-# endif
-# ifdef HAVE_PUTCHAR_UNLOCKED
-# undef putchar
-# define putchar(C) putchar_unlocked (C)
-# endif
-# ifdef HAVE_GETC_UNLOCKED
-# undef getc
-# define getc(Stream) getc_unlocked (Stream)
-# endif
-# ifdef HAVE_GETCHAR_UNLOCKED
-# undef getchar
-# define getchar() getchar_unlocked ()
-# endif
-# ifdef HAVE_FPUTC_UNLOCKED
-# undef fputc
-# define fputc(C, Stream) fputc_unlocked (C, Stream)
-# endif
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-# ifdef HAVE_CLEARERR_UNLOCKED
-# undef clearerr
-# define clearerr(Stream) clearerr_unlocked (Stream)
-# if defined (HAVE_DECL_CLEARERR_UNLOCKED) && !HAVE_DECL_CLEARERR_UNLOCKED
-extern void clearerr_unlocked (FILE *);
-# endif
-# endif
-# ifdef HAVE_FEOF_UNLOCKED
-# undef feof
-# define feof(Stream) feof_unlocked (Stream)
-# if defined (HAVE_DECL_FEOF_UNLOCKED) && !HAVE_DECL_FEOF_UNLOCKED
-extern int feof_unlocked (FILE *);
-# endif
-# endif
-# ifdef HAVE_FILENO_UNLOCKED
-# undef fileno
-# define fileno(Stream) fileno_unlocked (Stream)
-# if defined (HAVE_DECL_FILENO_UNLOCKED) && !HAVE_DECL_FILENO_UNLOCKED
-extern int fileno_unlocked (FILE *);
-# endif
-# endif
-# ifdef HAVE_FFLUSH_UNLOCKED
-# undef fflush
-# define fflush(Stream) fflush_unlocked (Stream)
-# if defined (HAVE_DECL_FFLUSH_UNLOCKED) && !HAVE_DECL_FFLUSH_UNLOCKED
-extern int fflush_unlocked (FILE *);
-# endif
-# endif
-# ifdef HAVE_FGETC_UNLOCKED
-# undef fgetc
-# define fgetc(Stream) fgetc_unlocked (Stream)
-# if defined (HAVE_DECL_FGETC_UNLOCKED) && !HAVE_DECL_FGETC_UNLOCKED
-extern int fgetc_unlocked (FILE *);
-# endif
-# endif
-# ifdef HAVE_FGETS_UNLOCKED
-# undef fgets
-# define fgets(S, n, Stream) fgets_unlocked (S, n, Stream)
-# if defined (HAVE_DECL_FGETS_UNLOCKED) && !HAVE_DECL_FGETS_UNLOCKED
-extern char *fgets_unlocked (char *, int, FILE *);
-# endif
-# endif
-# ifdef HAVE_FPUTS_UNLOCKED
-# undef fputs
-# define fputs(String, Stream) fputs_unlocked (String, Stream)
-# if defined (HAVE_DECL_FPUTS_UNLOCKED) && !HAVE_DECL_FPUTS_UNLOCKED
-extern int fputs_unlocked (const char *, FILE *);
-# endif
-# endif
-# ifdef HAVE_FERROR_UNLOCKED
-# undef ferror
-# define ferror(Stream) ferror_unlocked (Stream)
-# if defined (HAVE_DECL_FERROR_UNLOCKED) && !HAVE_DECL_FERROR_UNLOCKED
-extern int ferror_unlocked (FILE *);
-# endif
-# endif
-# ifdef HAVE_FREAD_UNLOCKED
-# undef fread
-# define fread(Ptr, Size, N, Stream) fread_unlocked (Ptr, Size, N, Stream)
-# if defined (HAVE_DECL_FREAD_UNLOCKED) && !HAVE_DECL_FREAD_UNLOCKED
-extern size_t fread_unlocked (void *, size_t, size_t, FILE *);
-# endif
-# endif
-# ifdef HAVE_FWRITE_UNLOCKED
-# undef fwrite
-# define fwrite(Ptr, Size, N, Stream) fwrite_unlocked (Ptr, Size, N, Stream)
-# if defined (HAVE_DECL_FWRITE_UNLOCKED) && !HAVE_DECL_FWRITE_UNLOCKED
-extern size_t fwrite_unlocked (const void *, size_t, size_t, FILE *);
-# endif
-# endif
-# ifdef HAVE_FPRINTF_UNLOCKED
-# undef fprintf
-/* We can't use a function-like macro here because we don't know if
- we have varargs macros. */
-# define fprintf fprintf_unlocked
-# if defined (HAVE_DECL_FPRINTF_UNLOCKED) && !HAVE_DECL_FPRINTF_UNLOCKED
-extern int fprintf_unlocked (FILE *, const char *, ...);
-# endif
-# endif
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
-
-/* ??? Glibc's fwrite/fread_unlocked macros cause
- "warning: signed and unsigned type in conditional expression". */
-#undef fread_unlocked
-#undef fwrite_unlocked
-
/* Include <string> before "safe-ctype.h" to avoid GCC poisoning
the ctype macros through safe-ctype.h */

View File

@ -0,0 +1,25 @@
--- libstdc++-v3/config/os/bionic/ctype_base.h.bak 2022-04-27 12:37:53.088346124 +0000
+++ libstdc++-v3/config/os/bionic/ctype_base.h 2022-04-27 12:39:38.444403143 +0000
@@ -28,6 +28,22 @@
// Information as gleaned from /usr/include/ctype.h
+#if defined (__ANDROID__)
+#if !defined(_U)
+#if !defined(_CTYPE_U)
+#error Bionic header ctype.h does not define either _U nor _CTYPE_U
+#endif
+#define _U _CTYPE_U
+#define _L _CTYPE_L
+#define _N _CTYPE_N
+#define _S _CTYPE_S
+#define _P _CTYPE_P
+#define _C _CTYPE_C
+#define _X _CTYPE_X
+#define _B _CTYPE_B
+#endif
+#endif /* __ANDROID__ */
+
namespace std _GLIBCXX_VISIBILITY(default)
{
_GLIBCXX_BEGIN_NAMESPACE_VERSION