Skip to content

Commit

Permalink
new package: gcc-14
Browse files Browse the repository at this point in the history
  • Loading branch information
termux-pacman-bot committed May 26, 2024
1 parent fa8637e commit 383298e
Show file tree
Hide file tree
Showing 10 changed files with 538 additions and 0 deletions.
223 changes: 223 additions & 0 deletions tur/gcc-14/0001-android-related-modifications.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,223 @@
Based on https://github.com/crystax/android-toolchain-gcc-6/commit/080803512c8f6f87c2f1f711170d54033144d628 and
https://github.com/its-pointless/gcc_termux/tree/5d83a14dfb87cb86b9d47e3c36ead328546f315c/termux-packages/experimental-packages/gcc-6

diff -uNr a/gcc/config/aarch64/aarch64-linux-android.h b/gcc/config/aarch64/aarch64-linux-android.h
--- a/gcc/config/aarch64/aarch64-linux-android.h
+++ b/gcc/config/aarch64/aarch64-linux-android.h
@@ -0,0 +1,59 @@
+/* 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)
+
+#endif /* GCC_AARCH64_LINUX_ANDROID_H */
diff -uNr a/gcc/config/aarch64/aarch64-linux.h b/gcc/config/aarch64/aarch64-linux.h
--- a/gcc/config/aarch64/aarch64-linux.h
+++ b/gcc/config/aarch64/aarch64-linux.h
@@ -26,6 +26,9 @@
#undef MUSL_DYNAMIC_LINKER
#define MUSL_DYNAMIC_LINKER "/lib/ld-musl-aarch64%{mbig-endian:_be}%{mabi=ilp32:_ilp32}.so.1"

+#undef BIONIC_DYNAMIC_LINKER
+#define BIONIC_DYNAMIC_LINKER "/system/bin/linker64"
+
#undef ASAN_CC1_SPEC
#define ASAN_CC1_SPEC "%{%:sanitize(address):-funwind-tables}"

diff -uNr a/gcc/config/arm/elf.h b/gcc/config/arm/elf.h
--- a/gcc/config/arm/elf.h
+++ b/gcc/config/arm/elf.h
@@ -56,8 +56,7 @@
#undef SUBSUBTARGET_EXTRA_SPECS
#define SUBSUBTARGET_EXTRA_SPECS

-#ifndef ASM_SPEC
-#define ASM_SPEC "\
+#define DEFAULT_ASM_SPEC "\
%{mbig-endian:-EB} \
%{mlittle-endian:-EL} \
%(asm_cpu_spec) \
@@ -66,6 +65,8 @@
%{mthumb-interwork:-mthumb-interwork} \
%{mfloat-abi=*} %{!mfpu=auto: %{mfpu=*}} \
%(subtarget_extra_asm_spec)"
+#ifndef ASM_SPEC
+#define ASM_SPEC DEFAULT_ASM_SPEC
#endif

/* The ARM uses @ are a comment character so we need to redefine
diff -uNr a/gcc/config/arm/linux-eabi.h b/gcc/config/arm/linux-eabi.h
--- a/gcc/config/arm/linux-eabi.h
+++ b/gcc/config/arm/linux-eabi.h
@@ -108,11 +108,16 @@
LINUX_OR_ANDROID_CC (GNU_USER_TARGET_CC1_SPEC " " ASAN_CC1_SPEC " " \
FDPIC_CC1_SPEC, \
GNU_USER_TARGET_CC1_SPEC " " ASAN_CC1_SPEC " " \
- ANDROID_CC1_SPEC)
+ ANDROID_CC1_SPEC("-fpic"))

#define CC1PLUS_SPEC \
LINUX_OR_ANDROID_CC ("", ANDROID_CC1PLUS_SPEC)

+#undef ASM_SPEC
+#define ASM_SPEC \
+ LINUX_OR_ANDROID_CC (DEFAULT_ASM_SPEC, \
+ DEFAULT_ASM_SPEC " " ANDROID_ASM_SPEC)
+
#undef LIB_SPEC
#define LIB_SPEC \
LINUX_OR_ANDROID_LD (GNU_USER_TARGET_LIB_SPEC, \
diff -uNr a/gcc/config/i386/gnu-user.h b/gcc/config/i386/gnu-user.h
--- a/gcc/config/i386/gnu-user.h
+++ b/gcc/config/i386/gnu-user.h
@@ -59,9 +59,13 @@
When the -shared link option is used a final link is not being
done. */

+#undef ANDROID_TARGET_CC1_SPEC
+#define ANDROID_TARGET_CC1_SPEC \
+ " -mssse3 -fno-short-enums " \
+
#undef ASM_SPEC
#define ASM_SPEC \
- "--32 %{msse2avx:%{!mavx:-msse2avx}}"
+ "--32 %{msse2avx:%{!mavx:-msse2avx}}" LINUX_OR_ANDROID_CC ("", ANDROID_ASM_SPEC)

#undef SUBTARGET_EXTRA_SPECS
#define SUBTARGET_EXTRA_SPECS \
diff -uNr a/gcc/config/i386/gnu-user64.h b/gcc/config/i386/gnu-user64.h
--- a/gcc/config/i386/gnu-user64.h
+++ b/gcc/config/i386/gnu-user64.h
@@ -46,6 +46,11 @@
#define SPEC_X32 "mx32"
#endif

+#undef ANDROID_TARGET_CC1_SPEC
+#define ANDROID_TARGET_CC1_SPEC \
+ "%{m32:-mssse3 -fno-short-enums}" \
+ "%{!m32:-msse4.2 -mpopcnt}"
+
#undef ASM_SPEC
#define ASM_SPEC "%{" SPEC_32 ":--32} \
%{" SPEC_64 ":--64} \
diff -uNr a/gcc/config/i386/linux-common.h b/gcc/config/i386/linux-common.h
--- a/gcc/config/i386/linux-common.h
+++ b/gcc/config/i386/linux-common.h
@@ -33,7 +33,13 @@
#undef CC1_SPEC
#define CC1_SPEC \
LINUX_OR_ANDROID_CC (GNU_USER_TARGET_CC1_SPEC, \
- GNU_USER_TARGET_CC1_SPEC " " ANDROID_CC1_SPEC)
+ GNU_USER_TARGET_CC1_SPEC \
+ ANDROID_TARGET_CC1_SPEC \
+ " " \
+ ANDROID_CC1_SPEC("-fPIC"))
+
+#define CC1PLUS_SPEC \
+ LINUX_OR_ANDROID_CC ("", ANDROID_CC1PLUS_SPEC)

#undef LINK_SPEC
#define LINK_SPEC \
diff -uNr a/gcc/config/linux-android.h b/gcc/config/linux-android.h
--- a/gcc/config/linux-android.h
+++ b/gcc/config/linux-android.h
@@ -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}"
diff -uNr a/gcc/config.gcc b/gcc/config.gcc
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -1176,14 +1176,18 @@
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
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
25 changes: 25 additions & 0 deletions tur/gcc-14/0002-fix-missing-_L.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Based on https://android.googlesource.com/toolchain/gcc/+/44ea170a62f4bb566c5487c446a31300d1e0e319%5E%21/

--- a/libstdc++-v3/config/os/bionic/ctype_base.h
+++ b/libstdc++-v3/config/os/bionic/ctype_base.h
@@ -28,6 +28,20 @@

// Information as gleaned from /usr/include/ctype.h

+#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
+
namespace std _GLIBCXX_VISIBILITY(default)
{
_GLIBCXX_BEGIN_NAMESPACE_VERSION
19 changes: 19 additions & 0 deletions tur/gcc-14/0003-disable-call-ssp-local.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
GCC uses a wrapper of function `__stack_chk_fail` (named `__stack_chk_fail_local`)
to optimize for PIC code on x86 architecture, but this function is now removed from
the prebuilt crtbegin.o, so we should make GCC NOT call this wrapper.

[1]: https://android.googlesource.com/platform/bionic/+/5501003be73b73de59044b44b12f6e20ba6e0021
[2]: https://android.googlesource.com/platform/bionic/+/8f7120b/libc/arch-x86/bionic/__stack_chk_fail_local.h
--- a/gcc/config/i386/i386.cc
+++ b/gcc/config/i386/i386.cc
@@ -21810,9 +21810,7 @@
static tree ATTRIBUTE_UNUSED
ix86_stack_protect_fail (void)
{
- return TARGET_64BIT
- ? default_external_stack_protect_fail ()
- : default_hidden_stack_protect_fail ();
+ return default_external_stack_protect_fail ();
}

/* Select a format to encode pointers in exception handling data. CODE
23 changes: 23 additions & 0 deletions tur/gcc-14/0004-avoid-hard-link-install.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Hard link is not supported on Android, but GCC's Makefile use hard link by default.
--- a/Makefile.in
+++ b/Makefile.in
@@ -84,7 +84,7 @@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_SCRIPT = @INSTALL_SCRIPT@
INSTALL_DATA = @INSTALL_DATA@
-LN = @LN@
+LN = @LN_S@
LN_S = @LN_S@
MAINT = @MAINT@
MAINTAINER_MODE_FALSE = @MAINTAINER_MODE_FALSE@
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -310,7 +310,7 @@
INSTALL = @INSTALL@
# Some systems may be missing symbolic links, regular links, or both.
# Allow configure to check this and use "ln -s", "ln", or "cp" as appropriate.
-LN=@LN@
+LN=@LN_S@
LN_S=@LN_S@
# These permit overriding just for certain files.
INSTALL_PROGRAM = @INSTALL_PROGRAM@
43 changes: 43 additions & 0 deletions tur/gcc-14/0005-check-both-android-and-bionic-macro.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
Do not know why this happens. We have already set `CFLAGS/CPPFLAGS/CXXFLAGS`
with `__BIONIC__`. Anyway, `__ANDROID__` is always set when compiling, so
check both __ANDROID__ and __BIONIC__ may solve this issue.

```
In file included from /home/builder/.termux-build/gcc-13/src/libgcc/gthr.h:148,
from /home/builder/.termux-build/gcc-13/src/libgcc/unwind-dw2-fde-dip.c:47:
./gthr-default.h:112:9: error: 'pthread_cancel' undeclared here (not in a function); did you mean 'pthread_once'?
112 | __gthrw(pthread_cancel)
| ^~~~~~~~~~~~~~
./gthr-default.h:90:19: note: in definition of macro '__gthrw2'
```
--- a/libgcc/gthr-posix.h
+++ b/libgcc/gthr-posix.h
@@ -108,7 +108,7 @@
__gthrw(pthread_equal)
__gthrw(pthread_self)
__gthrw(pthread_detach)
-#ifndef __BIONIC__
+#if ! (defined (__BIONIC__) || defined (__ANDROID__))
__gthrw(pthread_cancel)
#endif
__gthrw(sched_yield)
@@ -238,7 +238,7 @@
__pthread_key_create,
pthread_key_create)
# define GTHR_ACTIVE_PROXY __gthrw_(__pthread_key_create)
-#elif defined (__BIONIC__)
+#elif defined (__BIONIC__) || defined (__ANDROID__)
# define GTHR_ACTIVE_PROXY __gthrw_(pthread_create)
#else
# define GTHR_ACTIVE_PROXY __gthrw_(pthread_cancel)
--- a/libgcc/unwind-dw2-fde-dip.c
+++ b/libgcc/unwind-dw2-fde-dip.c
@@ -53,7 +53,7 @@
#endif

#if !defined(inhibit_libc) && defined(HAVE_LD_EH_FRAME_HDR) \
- && defined(__BIONIC__)
+ && (defined(__BIONIC__) || defined (__ANDROID__))
# define USE_PT_GNU_EH_FRAME
#endif

16 changes: 16 additions & 0 deletions tur/gcc-14/0006-remove-sys-sysctl.h.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Header <sys/sysctl.h> has been removed since glibc 2.32 [1], neither does it
exist in Android NDK Header. For some reason, HAVE_SYS_SYSCTL_H is not false when
performing a build for `x86_64-linux-gnu`, so just assume this header is missing.

[1]: https://sourceware.org/pipermail/libc-announce/2020/000029.html.
--- a/libiberty/physmem.c
+++ b/libiberty/physmem.c
@@ -48,7 +48,7 @@
# include <sys/param.h>
#endif

-#if HAVE_SYS_SYSCTL_H
+#if false
# include <sys/sysctl.h>
#endif

25 changes: 25 additions & 0 deletions tur/gcc-14/0007-override-CXXFLAGS-in-Makefile.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
The Makefile of `libcpp` passes BASE_FLAGS_TO_PASS to `make` and thus
some build flags, such as CXXFLAGS/CPPFLAGS, are passed as well when
compiling libcpp for the build machine. It should not be passed and
should be overrided because these flags are for the host machine.
This seems a bug from upstream.

```
g++ -I/home/builder/.termux-build/gcc-11/src/libcpp -I. -I/home/builder/.termux-build/gcc-11/src/libcpp/../include -I/home/builder/.termux-build/gcc-11/src/libcpp/include -I/data/data/com.termux/files/usr/include -D__BIONIC__ -D__ANDROID_API__=24 -march=armv7-a -mfpu=neon -mfloat-abi=softfp -mthumb -fstack-protector-strong -O3 -D__BIONIC__ -D__ANDROID_API__=24 -W -Wall -Wno-narrowing -Wwrite-strings -Wmissing-format-attribute -pedantic -Wno-long-long -fno-exceptions -fno-rtti -I/home/builder/.termux-build/gcc-11/src/libcpp -I. -I/home/builder/.termux-build/gcc-11/src/libcpp/../include -I/home/builder/.termux-build/gcc-11/src/libcpp/include -I/data/data/com.termux/files/usr/include -D__BIONIC__ -D__ANDROID_API__=24 -fPIC -c -o charset.o -MT charset.o -MMD -MP -MF .deps/charset.Tpo /home/builder/.termux-build/gcc-11/src/libcpp/charset.c
g++: error: unrecognized command-line option '-mfpu=neon'
g++: error: unrecognized command-line option '-mfloat-abi=softfp'
g++: error: unrecognized command-line option '-mthumb'
```
--- a/Makefile.in
+++ b/Makefile.in
@@ -170,7 +170,9 @@
# built for the build system to override those in BASE_FLAGS_TO_PASS.
EXTRA_BUILD_FLAGS = \
CFLAGS="$(CFLAGS_FOR_BUILD)" \
- LDFLAGS="$(LDFLAGS_FOR_BUILD)"
+ LDFLAGS="$(LDFLAGS_FOR_BUILD)" \
+ CXXFLAGS="$(CXXFLAGS_FOR_BUILD)" \
+ CPPFLAGS="$(CPPFLAGS_FOR_BUILD)"

# This is the list of directories to built for the host system.
SUBDIRS = @configdirs@
Loading

0 comments on commit 383298e

Please sign in to comment.