From f1376c1bad842a3c1670ee5258b4c78372ae5b6b Mon Sep 17 00:00:00 2001 From: Dennis Felsing Date: Tue, 10 Dec 2024 15:20:12 -0500 Subject: [PATCH] Support lld + update toolchains --- Formula/aarch64-unknown-linux-gnu.rb | 10 +- Formula/x86_64-unknown-linux-gnu.rb | 10 +- README.md | 4 +- lib/toolchain.rb | 123 +++++++-------- patches/gcc/13.2.0/001-safe-ctype.patch | 140 ++++++++++++++++++ patches/gcc/13.2.0/002-include-order.patch | 51 +++++++ .../linux/2.6.32.71/0001-remove-strlcpy.patch | 25 ---- 7 files changed, 250 insertions(+), 113 deletions(-) create mode 100644 patches/gcc/13.2.0/001-safe-ctype.patch create mode 100644 patches/gcc/13.2.0/002-include-order.patch delete mode 100644 patches/linux/2.6.32.71/0001-remove-strlcpy.patch diff --git a/Formula/aarch64-unknown-linux-gnu.rb b/Formula/aarch64-unknown-linux-gnu.rb index a302d7f..4a0fe5b 100644 --- a/Formula/aarch64-unknown-linux-gnu.rb +++ b/Formula/aarch64-unknown-linux-gnu.rb @@ -4,20 +4,12 @@ class Aarch64UnknownLinuxGnu < Toolchain desc "aarch64 Linux GNU toolchain" - version "0.1.0" - - bottle do - root_url "https://github.com/MaterializeInc/homebrew-crosstools/releases/download/aarch64-unknown-linux-gnu-0.1.0" - sha256 cellar: :any, arm64_big_sur: "e9a7883db4e4bca222dacfe6576b46318ebe949f4352aa061c8b5e80d6479bea" - sha256 cellar: :any, catalina: "b9128e88b58f1afb20092c9478c7fc3d9daf935baeda344a8eae18f01231db4f" - end + version "0.2.0" defconfig <<~EOS CT_ARCH_64=y CT_ARCH_ARM=y EOS - glibc_version "2.26" - linux_version "3.10" def test_signature(sig) assert_match "ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV)", sig diff --git a/Formula/x86_64-unknown-linux-gnu.rb b/Formula/x86_64-unknown-linux-gnu.rb index 6bf4e8c..1df1c74 100644 --- a/Formula/x86_64-unknown-linux-gnu.rb +++ b/Formula/x86_64-unknown-linux-gnu.rb @@ -4,20 +4,12 @@ class X8664UnknownLinuxGnu < Toolchain desc "x86_64 Linux GNU toolchain" - version "0.1.0" - - bottle do - root_url "https://github.com/MaterializeInc/homebrew-crosstools/releases/download/x86_64-unknown-linux-gnu-0.1.0" - sha256 cellar: :any, arm64_big_sur: "bb23a1e08218c0acdfe8701c0a0aea5a76adb010610c941976a0368939debbd4" - sha256 cellar: :any, catalina: "8290d01510eb2a1bb8c6f4c97e88ad73e1536ffb9b3e0eb2417b25cb294d114d" - end + version "0.2.0" defconfig <<~EOS CT_ARCH_64=y CT_ARCH_X86=y EOS - glibc_version "2.12.1" - linux_version "2.6.32" def test_signature(sig) assert_match "ELF 64-bit LSB executable, x86-64, version 1 (SYSV)", sig diff --git a/README.md b/README.md index 1a53064..740f75b 100644 --- a/README.md +++ b/README.md @@ -17,8 +17,8 @@ brew install MaterializeInc/crosstools/ Target | Binutils | GCC | Kernel | Glibc ------------------------------|----------|---------|----------|------- -[`aarch64-unknown-linux-gnu`] | 2.37 | 11.2.0 | 3.10.108 | 2.26.0 -[`x86_64-unknown-linux-gnu`] | 2.37 | 11.2.0 | 2.6.32 | 2.12.1 +[`aarch64-unknown-linux-gnu`] | 2.40 | 13.2.0 | 5.10.185 | 2.35 +[`x86_64-unknown-linux-gnu`] | 2.40 | 13.2.0 | 5.10.185 | 2.35 ## Contributing diff --git a/lib/toolchain.rb b/lib/toolchain.rb index 0644490..00ad637 100644 --- a/lib/toolchain.rb +++ b/lib/toolchain.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -TAP_PATH = (HOMEBREW_TAP_DIRECTORY/"MaterializeInc"/"homebrew-crosstools").freeze +TAP_PATH = (HOMEBREW_TAP_DIRECTORY/"def-"/"homebrew-crosstools").freeze class Toolchain < Formula desc "Appease RuboCop; not used" @@ -8,48 +8,45 @@ class Toolchain < Formula DEFCONFIG = <<~EOF <%= defconfig %> - CT_BINUTILS_GOLD_THREADS=y - CT_BINUTILS_LD_WRAPPER=y - CT_BINUTILS_LINKER_LD_GOLD=y - CT_BINUTILS_PLUGINS=y - CT_BINUTILS_V_2_37=y - CT_CC_GCC_BUILD_ID=y - CT_CC_LANG_CXX=y - CT_CONFIG_VERSION="3" - CT_EXPERIMENTAL=y - CT_FORBID_DOWNLOAD=y - CT_GCC_V_11=y - CT_GETTEXT_V_0_21=y - CT_GLIBC_V_<%= glibc_version.gsub(".", "_") %>=y - # CT_GLIBC_ENABLE_OBSOLETE_RPC is not set - CT_GMP_V_6_2=y - CT_ISL_V_0_24=y - CT_KERNEL_LINUX=y - CT_LIBC_GLIBC=yCT_DEBUG_CT=y - CT_LIBICONV_V_1_16=y - CT_LINUX_V_<%= linux_version.gsub(".", "_") %>=y CT_LOCAL_TARBALLS_DIR="<%= buildpath %>/tarballs" CT_LOCAL_PATCH_DIR="<%= buildpath %>/patches" # CT_LOG_PROGRESS_BAR is not set - CT_MPC_V_1_2=y - CT_MPFR_V_4_1=y - CT_NCURSES_V_6_2=y + CT_PATCH_ORDER="bundled,local" CT_PATCH_BUNDLED_LOCAL=y + CT_PATCH_USE_LOCAL=y CT_PREFIX_DIR="<%= buildpath %>/mnt/install" <% if Context.current.debug? %> CT_DEBUG_CT=y CT_DEBUG_CT_SAVE_STEPS=y + CT_CONFIG_VERSION="3" + CT_EXPERIMENTAL=y + CT_ALLOW_BUILD_AS_ROOT=y + CT_ALLOW_BUILD_AS_ROOT_SURE=y + # CT_SAVE_TARBALLS is not set + CT_PREFIX_DIR="${CT_PREFIX:-/opt/x-tools}/${CT_HOST:+HOST-${CT_HOST}/}${CT_TARGET}" + # CT_LOG_TO_FILE is not set + CT_ARCH_ARM=y + CT_ARCH_64=y + CT_KERNEL_LINUX=y + CT_LINUX_V_5_10=y + CT_BINUTILS_LINKER_LD_GOLD=y + CT_BINUTILS_GOLD_THREADS=y + CT_BINUTILS_LD_WRAPPER=y + CT_BINUTILS_PLUGINS=y + CT_CC_LANG_CXX=y + CT_LIBC_GLIBC=y + # CT_LOG_PROGRESS_BAR is not set + CT_GLIBC_V_2_35=y + # CT_COMP_TOOLS_AUTOCONF is not set + # CT_COMP_TOOLS_AUTOMAKE is not set + CT_CC_GCC_BUILD_ID=y <% end %> EOF delegate defconfig: :"self.class" - delegate glibc_version: :"self.class" - delegate linux_version: :"self.class" class << self attr_rw :defconfig - attr_rw :glibc_version - attr_rw :linux_version def inherited(formula) super @@ -77,15 +74,16 @@ def inject depends_on "gawk" => :build depends_on "xz" => :build depends_on "zstd" + depends_on "lld" resource "binutils" do - url "https://ftp.gnu.org/pub/gnu/binutils/binutils-2.37.tar.xz" - sha256 "820d9724f020a3e69cb337893a0b63c2db161dadcb0e06fc11dc29eb1e84a32c" + url "https://ftp.gnu.org/pub/gnu/binutils/binutils-2.40.tar.xz" + sha256 "0f8a4c272d7f17f369ded10a4aca28b8e304828e95526da482b0ccc4dfc9d8e1" end resource "gcc" do - url "https://ftp.gnu.org/gnu/gcc/gcc-11.2.0/gcc-11.2.0.tar.xz" - sha256 "d08edc536b54c372a1010ff6619dd274c0f1603aa49212ba20f7aa2cda36fa8b" + url "https://ftp.gnu.org/gnu/gcc/gcc-13.2.0/gcc-13.2.0.tar.xz" + sha256 "e275e76442a6067341a27f04c5c6b83d8613144004c0413528863dc6b5c743da" end resource "gettext" do @@ -93,19 +91,9 @@ def inject sha256 "d20fcbb537e02dcf1383197ba05bd0734ef7bf5db06bdb241eb69b7d16b73192" end - case glibc_version - when "2.12.1" - resource "glibc" do - url "https://ftp.gnu.org/pub/gnu/glibc/glibc-2.12.1.tar.xz" - sha256 "9e633fb278b411a90636cc1c4bf1ffddcc8b0d214f5bacd74bfcdaac81d6035e" - end - when "2.26" - resource "glibc" do - url "https://ftp.gnu.org/pub/gnu/glibc/glibc-2.26.tar.xz" - sha256 "e54e0a934cd2bc94429be79da5e9385898d2306b9eaf3c92d5a77af96190f6bd" - end - else - raise "unsupported glibc version #{glibc_version}" + resource "glibc" do + url "https://ftp.gnu.org/pub/gnu/glibc/glibc-2.35.tar.xz" + sha256 "5123732f6b67ccd319305efd399971d58592122bcc2a6518a1bd2510dd0cf52e" end resource "gmp" do @@ -114,8 +102,8 @@ def inject end resource "isl" do - url "https://libisl.sourceforge.io/isl-0.24.tar.xz" - sha256 "043105cc544f416b48736fff8caf077fb0663a717d06b1113f16e391ac99ebad" + url "https://libisl.sourceforge.io/isl-0.26.tar.xz" + sha256 "a0b5cb06d24f9fa9e77b55fabbe9a3c94a336190345c2555f9915bb38e976504" end resource "libiconv" do @@ -123,39 +111,34 @@ def inject sha256 "e6a1b1b589654277ee790cce3734f07876ac4ccfaecbee8afa0b649cf529cc04" end - case linux_version - when "2.6.32" - resource "linux" do - url "https://cdn.kernel.org/pub/linux/kernel/v2.6/longterm/v2.6.32/linux-2.6.32.71.tar.xz" - sha256 "60a5ffe0206a0ea8997c29ccc595aa7dae55f6cb20c7d92aab88029ca4fef598" - end - when "3.10" - resource "linux" do - url "https://cdn.kernel.org/pub/linux/kernel/v3.x/linux-3.10.108.tar.xz" - sha256 "3849ea8119517f605f9d53c57dd6c539af8d584c2f1d9031f4f56283af3409a5" - end - else - raise "unsupported linux version #{linux_version}" + resource "linux" do + url "https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.10.185.tar.xz" + sha256 "280662ec8dc8738cf947ad66e748141abd58cbe3b5ed66b7f2b153222b7c7090" end resource "mpc" do - url "https://www.multiprecision.org/downloads/mpc-1.2.0.tar.gz" - sha256 "e90f2d99553a9c19911abdb4305bf8217106a957e3994436428572c8dfe8fda6" + url "https://www.multiprecision.org/downloads/mpc-1.2.1.tar.gz" + sha256 "17503d2c395dfcf106b622dc142683c1199431d095367c6aacba6eec30340459" end resource "mpfr" do - url "https://www.mpfr.org/mpfr-4.1.0/mpfr-4.1.0.tar.xz" - sha256 "0c98a3f1732ff6ca4ea690552079da9c597872d30e96ec28414ee23c95558a7f" + url "https://www.mpfr.org/mpfr-4.2.1/mpfr-4.2.1.tar.xz" + sha256 "277807353a6726978996945af13e52829e3abd7a9a5b7fb2793894e18f1fcbb2" end resource "ncurses" do - url "https://invisible-mirror.net/archives/ncurses/ncurses-6.2.tar.gz" - sha256 "30306e0c76e0f9f1f0de987cf1c82a5c21e1ce6568b9227f7da5b71cbea86c9d" + url "https://invisible-mirror.net/archives/ncurses/ncurses-6.4.tar.gz" + sha256 "6931283d9ac87c5073f30b6290c4c75f21632bb4fc3603ac8100812bed248159" end resource "zlib" do - url "https://downloads.sourceforge.net/project/libpng/zlib/1.2.11/zlib-1.2.11.tar.xz" - sha256 "4ff941449631ace0d4d203e3483be9dbc9da454084111f97ea0a2114e19bf066" + url "https://github.com/madler/zlib/releases/download/v1.2.13/zlib-1.2.13.tar.xz" + sha256 "d14c38e313afc35a9a8760dadf26042f51ea0f5d154b0630a31da0540107fb98" + end + + resource "zstd" do + url "https://github.com/facebook/zstd/releases/download/v1.5.5/zstd-1.5.5.tar.gz" + sha256 "9c4396cc829cfae319a6e2615202e82aad41372073482fce286fac78646d3ee4" end end end @@ -205,6 +188,10 @@ def install rm_r "mnt/install/lib/bfd-plugins" rm ["mnt/install/lib/libcc1.so", "mnt/install/lib/libcc1.0.so"] chmod "-w", "mnt/install/lib" + mkdir "mnt/install/bin" + + brew_prefix = ENV["HOMEBREW_PREFIX"] || "/usr/local" + ln_s brew_prefix/"homebrew/bin/lld", "mnt/install/bin/ld.lld" cp_r "mnt/install/.", prefix end diff --git a/patches/gcc/13.2.0/001-safe-ctype.patch b/patches/gcc/13.2.0/001-safe-ctype.patch new file mode 100644 index 0000000..070bf68 --- /dev/null +++ b/patches/gcc/13.2.0/001-safe-ctype.patch @@ -0,0 +1,140 @@ +From: Francois-Xavier Coudert +Date: Thu, 7 Mar 2024 13:36:03 +0000 (+0100) +Subject: Include safe-ctype.h after C++ standard headers, to avoid over-poisoning +X-Git-Tag: releases/gcc-13.3.0~210 +X-Git-Url: https://gcc.gnu.org/git/?p=gcc.git;a=commitdiff_plain;h=68057560ff1fc0fb2df38c2f9627a20c9a8da5c5 + +Include safe-ctype.h after C++ standard headers, to avoid over-poisoning + +When building gcc's C++ sources against recent libc++, the poisoning of +the ctype macros due to including safe-ctype.h before including C++ +standard headers such as , , etc, causes many compilation +errors, similar to: + + In file included from /home/dim/src/gcc/master/gcc/gensupport.cc:23: + In file included from /home/dim/src/gcc/master/gcc/system.h:233: + In file included from /usr/include/c++/v1/vector:321: + In file included from + /usr/include/c++/v1/__format/formatter_bool.h:20: + In file included from + /usr/include/c++/v1/__format/formatter_integral.h:32: + In file included from /usr/include/c++/v1/locale:202: + /usr/include/c++/v1/__locale:546:5: error: '__abi_tag__' attribute + only applies to structs, variables, functions, and namespaces + 546 | _LIBCPP_INLINE_VISIBILITY + | ^ + /usr/include/c++/v1/__config:813:37: note: expanded from macro + '_LIBCPP_INLINE_VISIBILITY' + 813 | # define _LIBCPP_INLINE_VISIBILITY _LIBCPP_HIDE_FROM_ABI + | ^ + /usr/include/c++/v1/__config:792:26: note: expanded from macro + '_LIBCPP_HIDE_FROM_ABI' + 792 | + __attribute__((__abi_tag__(_LIBCPP_TOSTRING( + _LIBCPP_VERSIONED_IDENTIFIER)))) + | ^ + In file included from /home/dim/src/gcc/master/gcc/gensupport.cc:23: + In file included from /home/dim/src/gcc/master/gcc/system.h:233: + In file included from /usr/include/c++/v1/vector:321: + In file included from + /usr/include/c++/v1/__format/formatter_bool.h:20: + In file included from + /usr/include/c++/v1/__format/formatter_integral.h:32: + In file included from /usr/include/c++/v1/locale:202: + /usr/include/c++/v1/__locale:547:37: error: expected ';' at end of + declaration list + 547 | char_type toupper(char_type __c) const + | ^ + /usr/include/c++/v1/__locale:553:48: error: too many arguments + provided to function-like macro invocation + 553 | const char_type* toupper(char_type* __low, const + char_type* __high) const + | ^ + /home/dim/src/gcc/master/gcc/../include/safe-ctype.h:146:9: note: + macro 'toupper' defined here + 146 | #define toupper(c) do_not_use_toupper_with_safe_ctype + | ^ + +This is because libc++ uses different transitive includes than +libstdc++, and some of those transitive includes pull in various ctype +declarations (typically via ). + +There was already a special case for including before +safe-ctype.h, so move the rest of the C++ standard header includes to +the same location, to fix the problem. + + PR middle-end/111632 + +gcc/ChangeLog: + + * system.h: Include safe-ctype.h after C++ standard headers. + +Signed-off-by: Dimitry Andric +(cherry picked from commit 9970b576b7e4ae337af1268395ff221348c4b34a) +--- + +diff --git a/gcc/system.h b/gcc/system.h +index 33e9d4211150..03ab33ac960f 100644 +--- a/gcc/system.h ++++ b/gcc/system.h +@@ -194,27 +194,8 @@ extern int fprintf_unlocked (FILE *, const char *, ...); + #undef fread_unlocked + #undef fwrite_unlocked + +-/* Include before "safe-ctype.h" to avoid GCC poisoning +- the ctype macros through safe-ctype.h */ +- +-#ifdef __cplusplus +-#ifdef INCLUDE_STRING +-# include +-#endif +-#endif +- +-/* There are an extraordinary number of issues with . +- The last straw is that it varies with the locale. Use libiberty's +- replacement instead. */ +-#include "safe-ctype.h" +- +-#include +- +-#include +- +-#if !defined (errno) && defined (HAVE_DECL_ERRNO) && !HAVE_DECL_ERRNO +-extern int errno; +-#endif ++/* Include C++ standard headers before "safe-ctype.h" to avoid GCC ++ poisoning the ctype macros through safe-ctype.h */ + + #ifdef __cplusplus + #if defined (INCLUDE_ALGORITHM) || !defined (HAVE_SWAP_IN_UTILITY) +@@ -229,6 +210,9 @@ extern int errno; + #ifdef INCLUDE_SET + # include + #endif ++#ifdef INCLUDE_STRING ++# include ++#endif + #ifdef INCLUDE_VECTOR + # include + #endif +@@ -245,6 +229,19 @@ extern int errno; + # include + #endif + ++/* There are an extraordinary number of issues with . ++ The last straw is that it varies with the locale. Use libiberty's ++ replacement instead. */ ++#include "safe-ctype.h" ++ ++#include ++ ++#include ++ ++#if !defined (errno) && defined (HAVE_DECL_ERRNO) && !HAVE_DECL_ERRNO ++extern int errno; ++#endif ++ + /* Some of glibc's string inlines cause warnings. Plus we'd rather + rely on (and therefore test) GCC's string builtins. */ + #define __NO_STRING_INLINES + diff --git a/patches/gcc/13.2.0/002-include-order.patch b/patches/gcc/13.2.0/002-include-order.patch new file mode 100644 index 0000000..15e5304 --- /dev/null +++ b/patches/gcc/13.2.0/002-include-order.patch @@ -0,0 +1,51 @@ +commit 49222b98ac8e30a4a042ada0ece3d7df93f049d2 +Author: Dimitry Andric +Date: 2024-03-06T23:46:27+01:00 + + Fix libcc1plugin and libc1plugin to use INCLUDE_VECTOR before including + system.h, instead of directly including , to avoid running into + poisoned identifiers. + +diff --git a/libcc1/libcc1plugin.cc b/libcc1/libcc1plugin.cc +index 72d17c3b81c..e64847466f4 100644 +--- a/libcc1/libcc1plugin.cc ++++ b/libcc1/libcc1plugin.cc +@@ -32,6 +32,7 @@ + #undef PACKAGE_VERSION + + #define INCLUDE_MEMORY ++#define INCLUDE_VECTOR + #include "gcc-plugin.h" + #include "system.h" + #include "coretypes.h" +@@ -69,8 +70,6 @@ + #include "gcc-c-interface.h" + #include "context.hh" + +-#include +- + using namespace cc1_plugin; + + +diff --git a/libcc1/libcp1plugin.cc b/libcc1/libcp1plugin.cc +index 0eff7c68d29..da68c5d0ac1 100644 +--- a/libcc1/libcp1plugin.cc ++++ b/libcc1/libcp1plugin.cc +@@ -33,6 +33,7 @@ + #undef PACKAGE_VERSION + + #define INCLUDE_MEMORY ++#define INCLUDE_VECTOR + #include "gcc-plugin.h" + #include "system.h" + #include "coretypes.h" +@@ -71,8 +72,6 @@ + #include "rpc.hh" + #include "context.hh" + +-#include +- + using namespace cc1_plugin; + + + diff --git a/patches/linux/2.6.32.71/0001-remove-strlcpy.patch b/patches/linux/2.6.32.71/0001-remove-strlcpy.patch deleted file mode 100644 index a5b275b..0000000 --- a/patches/linux/2.6.32.71/0001-remove-strlcpy.patch +++ /dev/null @@ -1,25 +0,0 @@ -From 24040613a77cc47408b0831fae55ef1f5e64aeb9 Mon Sep 17 00:00:00 2001 -From: Nikhil Benesch -Date: Mon, 20 Dec 2021 23:06:27 -0500 -Subject: [PATCH] unifdef: remove conflicting strlcpy declaration for macOS - ---- - scripts/unifdef.c | 2 -- - 1 file changed, 2 deletions(-) - -diff --git a/scripts/unifdef.c b/scripts/unifdef.c -index 30d459fb0709..4d8aa3a3be23 100644 ---- a/scripts/unifdef.c -+++ b/scripts/unifdef.c -@@ -72,8 +72,6 @@ __FBSDID("$FreeBSD: /repoman/r/ncvs/src/usr.bin/unifdef/unifdef.c,v 1.20 2005/05 - #include - #include - --size_t strlcpy(char *dst, const char *src, size_t siz); -- - /* types of input lines: */ - typedef enum { - LT_TRUEI, /* a true #if with ignore flag */ --- -2.25.1 -