Skip to content

Commit

Permalink
Support lld + update toolchains
Browse files Browse the repository at this point in the history
  • Loading branch information
def- committed Dec 11, 2024
1 parent 64628dc commit eaa208c
Show file tree
Hide file tree
Showing 7 changed files with 247 additions and 113 deletions.
10 changes: 1 addition & 9 deletions Formula/aarch64-unknown-linux-gnu.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 1 addition & 9 deletions Formula/x86_64-unknown-linux-gnu.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ brew install MaterializeInc/crosstools/<toolchain>

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
Expand Down
120 changes: 52 additions & 68 deletions lib/toolchain.rb
Original file line number Diff line number Diff line change
@@ -1,55 +1,52 @@
# 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"
homepage "https://see.above"

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
Expand Down Expand Up @@ -77,35 +74,26 @@ 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
url "https://ftp.gnu.org/pub/gnu/gettext/gettext-0.21.tar.xz"
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
Expand All @@ -114,48 +102,43 @@ 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
url "https://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.16.tar.gz"
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
Expand Down Expand Up @@ -205,6 +188,7 @@ 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"
ln_s prefix/"bin/lld", "mnt/install/bin/ld.lld"

cp_r "mnt/install/.", prefix
end
Expand Down
140 changes: 140 additions & 0 deletions patches/gcc/13.2.0/001-safe-ctype.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
From: Francois-Xavier Coudert <[email protected]>
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 <list>, <map>, 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 <locale>).

There was already a special case for including <string> 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 <[email protected]>
(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 <string> before "safe-ctype.h" to avoid GCC poisoning
- the ctype macros through safe-ctype.h */
-
-#ifdef __cplusplus
-#ifdef INCLUDE_STRING
-# include <string>
-#endif
-#endif
-
-/* There are an extraordinary number of issues with <ctype.h>.
- The last straw is that it varies with the locale. Use libiberty's
- replacement instead. */
-#include "safe-ctype.h"
-
-#include <sys/types.h>
-
-#include <errno.h>
-
-#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 <set>
#endif
+#ifdef INCLUDE_STRING
+# include <string>
+#endif
#ifdef INCLUDE_VECTOR
# include <vector>
#endif
@@ -245,6 +229,19 @@ extern int errno;
# include <type_traits>
#endif

+/* There are an extraordinary number of issues with <ctype.h>.
+ The last straw is that it varies with the locale. Use libiberty's
+ replacement instead. */
+#include "safe-ctype.h"
+
+#include <sys/types.h>
+
+#include <errno.h>
+
+#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

Loading

0 comments on commit eaa208c

Please sign in to comment.