From b0c3a624c9c861df9ad3fc7e0961a18ac4059ae4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20A=C3=9Fhauer?= Date: Sun, 23 Apr 2023 09:32:42 +0200 Subject: [PATCH] WIP: shrink LLVM MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Matthias Aßhauer --- ...-GetHostTriple-for-mingw-w64-in-msys.patch | 24 +++++++ ...ry-creating-symlink-first-on-windows.patch | 30 +++++++++ ...-add-pthread-as-system-lib-for-mingw.patch | 26 ++++++++ .../0004-enable-emutls-for-mingw.patch | 11 ++++ ...linker-error-with-multiple-compilers.patch | 11 ++++ .../0101-link-pthread-with-mingw.patch | 25 +++++++ ...new-flang-experimental-exec-to-flang.patch | 65 +++++++++++++++++++ .../0303-ignore-new-bfd-options.patch | 11 ++++ mingw-w64-clang/README-patches.md | 20 ++++++ mingw-w64-clang/update-clang-from-msys2.sh | 55 ++++++++++++++++ 10 files changed, 278 insertions(+) create mode 100644 mingw-w64-clang/0001-Fix-GetHostTriple-for-mingw-w64-in-msys.patch create mode 100644 mingw-w64-clang/0002-Revert-CMake-try-creating-symlink-first-on-windows.patch create mode 100644 mingw-w64-clang/0003-add-pthread-as-system-lib-for-mingw.patch create mode 100644 mingw-w64-clang/0004-enable-emutls-for-mingw.patch create mode 100644 mingw-w64-clang/0005-Fix-Any-linker-error-with-multiple-compilers.patch create mode 100644 mingw-w64-clang/0101-link-pthread-with-mingw.patch create mode 100644 mingw-w64-clang/0102-Rename-flang-new-flang-experimental-exec-to-flang.patch create mode 100644 mingw-w64-clang/0303-ignore-new-bfd-options.patch create mode 100644 mingw-w64-clang/README-patches.md create mode 100755 mingw-w64-clang/update-clang-from-msys2.sh diff --git a/mingw-w64-clang/0001-Fix-GetHostTriple-for-mingw-w64-in-msys.patch b/mingw-w64-clang/0001-Fix-GetHostTriple-for-mingw-w64-in-msys.patch new file mode 100644 index 0000000000000..be63c8f6a959d --- /dev/null +++ b/mingw-w64-clang/0001-Fix-GetHostTriple-for-mingw-w64-in-msys.patch @@ -0,0 +1,24 @@ +From b47a00af69f3c662e54dc54e482fc9b0d4ba6480 Mon Sep 17 00:00:00 2001 +From: Martell Malone +Date: Sun, 28 Jun 2015 20:14:51 +0100 +Subject: [PATCH 2/5] Fix GetHostTriple for mingw-w64 in msys + +--- + cmake/modules/GetHostTriple.cmake | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/cmake/modules/GetHostTriple.cmake b/cmake/modules/GetHostTriple.cmake +index 0cad1db4eff..47e9f986e15 100644 +--- a/cmake/modules/GetHostTriple.cmake ++++ b/cmake/modules/GetHostTriple.cmake +@@ -16,7 +16,7 @@ + else() + set( value "i686-pc-windows-msvc" ) + endif() +- elseif( MINGW AND NOT MSYS ) ++ elseif( MINGW ) + # CMake doesn't provide COMPILER_ARCHITECTURE_ID for Clang/GCC, + # but it does for MSVC. + if( CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "ARM.*" ) +2.13.3 + diff --git a/mingw-w64-clang/0002-Revert-CMake-try-creating-symlink-first-on-windows.patch b/mingw-w64-clang/0002-Revert-CMake-try-creating-symlink-first-on-windows.patch new file mode 100644 index 0000000000000..aaf7cf60f8866 --- /dev/null +++ b/mingw-w64-clang/0002-Revert-CMake-try-creating-symlink-first-on-windows.patch @@ -0,0 +1,30 @@ +--- a/cmake/modules/LLVMInstallSymlink.cmake ++++ b/cmake/modules/LLVMInstallSymlink.cmake +@@ -6,6 +6,12 @@ + + function(install_symlink name target outdir) + set(DESTDIR $ENV{DESTDIR}) ++ if(CMAKE_HOST_UNIX) ++ set(LINK_OR_COPY create_symlink) ++ else() ++ set(LINK_OR_COPY copy) ++ endif() ++ + if(NOT IS_ABSOLUTE "${outdir}") + set(outdir "${CMAKE_INSTALL_PREFIX}/${outdir}") + endif() +@@ -14,12 +20,7 @@ + message(STATUS "Creating ${name}") + + execute_process( +- COMMAND "${CMAKE_COMMAND}" -E create_symlink "${target}" "${name}" +- WORKING_DIRECTORY "${outdir}" ERROR_VARIABLE has_err) +- if(CMAKE_HOST_WIN32 AND has_err) +- execute_process( +- COMMAND "${CMAKE_COMMAND}" -E copy "${target}" "${name}" +- WORKING_DIRECTORY "${outdir}") +- endif() ++ COMMAND "${CMAKE_COMMAND}" -E ${LINK_OR_COPY} "${target}" "${name}" ++ WORKING_DIRECTORY "${outdir}") + + endfunction() diff --git a/mingw-w64-clang/0003-add-pthread-as-system-lib-for-mingw.patch b/mingw-w64-clang/0003-add-pthread-as-system-lib-for-mingw.patch new file mode 100644 index 0000000000000..1d8792100b967 --- /dev/null +++ b/mingw-w64-clang/0003-add-pthread-as-system-lib-for-mingw.patch @@ -0,0 +1,26 @@ +From 9102055df75457e1194008ce6152221112a785ad Mon Sep 17 00:00:00 2001 +From: Mateusz Mikula +Date: Tue, 14 Mar 2017 17:50:29 +0100 +Subject: [PATCH 5/5] add pthread as system lib for mingw + +--- + lib/Support/CMakeLists.txt | 3 +++ + 1 file changed, 3 insertions(+) + +diff --git a/lib/Support/CMakeLists.txt b/lib/Support/CMakeLists.txt +index 0a8e3897cce..de9cda5dda3 100644 +--- a/lib/Support/CMakeLists.txt ++++ b/lib/Support/CMakeLists.txt +@@ -6,6 +6,9 @@ set(system_libs) + # libuuid required for FOLDERID_Profile usage in lib/Support/Windows/Path.inc. + # advapi32 required for CryptAcquireContextW in lib/Support/Windows/Path.inc. + set(system_libs ${system_libs} psapi shell32 ole32 uuid advapi32) ++ if( MINGW ) ++ set(system_libs ${system_libs} pthread) ++ endif() + elseif( CMAKE_HOST_UNIX ) + if( HAVE_LIBRT ) + set(system_libs ${system_libs} rt) +-- +2.13.3 + diff --git a/mingw-w64-clang/0004-enable-emutls-for-mingw.patch b/mingw-w64-clang/0004-enable-emutls-for-mingw.patch new file mode 100644 index 0000000000000..0dbca655370d6 --- /dev/null +++ b/mingw-w64-clang/0004-enable-emutls-for-mingw.patch @@ -0,0 +1,11 @@ +--- a/include/llvm/TargetParser/Triple.h ++++ b/include/llvm/TargetParser/Triple.h +@@ -952,7 +952,7 @@ + + /// Tests whether the target uses emulated TLS as default. + bool hasDefaultEmulatedTLS() const { +- return isAndroid() || isOSOpenBSD() || isWindowsCygwinEnvironment(); ++ return isAndroid() || isOSOpenBSD() || isOSCygMing(); + } + + /// Tests whether the target uses -data-sections as default. diff --git a/mingw-w64-clang/0005-Fix-Any-linker-error-with-multiple-compilers.patch b/mingw-w64-clang/0005-Fix-Any-linker-error-with-multiple-compilers.patch new file mode 100644 index 0000000000000..6d6aa2a9852c6 --- /dev/null +++ b/mingw-w64-clang/0005-Fix-Any-linker-error-with-multiple-compilers.patch @@ -0,0 +1,11 @@ +--- a/include/llvm/ADT/Any.h ++++ b/include/llvm/ADT/Any.h +@@ -124,7 +124,7 @@ + std::unique_ptr Storage; + }; + +-template char Any::TypeId::Id = 0; ++template char Any::TypeId::Id = 1; + + template + LLVM_DEPRECATED("Use any_cast(Any*) != nullptr instead", "any_cast") diff --git a/mingw-w64-clang/0101-link-pthread-with-mingw.patch b/mingw-w64-clang/0101-link-pthread-with-mingw.patch new file mode 100644 index 0000000000000..3fdfc0fc0d4dd --- /dev/null +++ b/mingw-w64-clang/0101-link-pthread-with-mingw.patch @@ -0,0 +1,25 @@ +From 9498118b65fa150f074efb52b4507b53434a90ad Mon Sep 17 00:00:00 2001 +From: Mateusz Mikula +Date: Thu, 2 Feb 2017 12:33:51 +0100 +Subject: [PATCH 4/6] link pthread with mingw + +--- + lib/Driver/ToolChains/MinGW.cpp | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/lib/Driver/ToolChains/MinGW.cpp b/lib/Driver/ToolChains/MinGW.cpp +index 632b76d92b..23da2d6376 100644 +--- a/lib/Driver/ToolChains/MinGW.cpp ++++ b/lib/Driver/ToolChains/MinGW.cpp +@@ -265,7 +265,7 @@ + if (Args.hasArg(options::OPT_pg)) + CmdArgs.push_back("-lgmon"); + +- if (Args.hasArg(options::OPT_pthread)) ++ if (!Args.hasArg(options::OPT_no_pthread)) + CmdArgs.push_back("-lpthread"); + + if (Sanitize.needsAsanRt()) { +-- +2.14.1 + diff --git a/mingw-w64-clang/0102-Rename-flang-new-flang-experimental-exec-to-flang.patch b/mingw-w64-clang/0102-Rename-flang-new-flang-experimental-exec-to-flang.patch new file mode 100644 index 0000000000000..b94440a9010b3 --- /dev/null +++ b/mingw-w64-clang/0102-Rename-flang-new-flang-experimental-exec-to-flang.patch @@ -0,0 +1,65 @@ +Index: clang/include/clang/Driver/Options.td +=================================================================== +--- clang/include/clang/Driver/Options.td ++++ clang/include/clang/Driver/Options.td +@@ -5076,9 +5076,6 @@ + // FLangOption + NoXarchOption + //===----------------------------------------------------------------------===// + +-def flang_experimental_exec : Flag<["-"], "flang-experimental-exec">, +- Flags<[FlangOption, FlangOnlyOption, NoXarchOption, HelpHidden]>, +- HelpText<"Enable support for generating executables (experimental)">; + + def flang_experimental_hlfir : Flag<["-"], "flang-experimental-hlfir">, + Flags<[FlangOption, FC1Option, FlangOnlyOption, NoXarchOption, HelpHidden]>, +Index: clang/lib/Driver/Driver.cpp +=================================================================== +--- clang/lib/Driver/Driver.cpp ++++ clang/lib/Driver/Driver.cpp +@@ -1936,7 +1936,7 @@ + + void Driver::PrintVersion(const Compilation &C, raw_ostream &OS) const { + if (IsFlangMode()) { +- OS << getClangToolFullVersion("flang-new") << '\n'; ++ OS << getClangToolFullVersion("flang") << '\n'; + } else { + // FIXME: The following handlers should use a callback mechanism, we don't + // know what the client would like to do. +Index: clang/lib/Driver/ToolChains/CommonArgs.cpp +=================================================================== +--- clang/lib/Driver/ToolChains/CommonArgs.cpp ++++ clang/lib/Driver/ToolChains/CommonArgs.cpp +@@ -886,12 +886,6 @@ + void tools::addFortranRuntimeLibraryPath(const ToolChain &TC, + const llvm::opt::ArgList &Args, + ArgStringList &CmdArgs) { +- // NOTE: Generating executables by Flang is considered an "experimental" +- // feature and hence this is guarded with a command line option. +- // TODO: Make this work unconditionally once Flang is mature enough. +- if (!Args.hasArg(options::OPT_flang_experimental_exec)) +- return; +- + // Default to the /../lib directory. This works fine on the + // platforms that we have tested so far. We will probably have to re-fine + // this in the future. In particular, on some platforms, we may need to use +Index: clang/lib/Driver/ToolChains/Flang.cpp +=================================================================== +--- clang/lib/Driver/ToolChains/Flang.cpp ++++ clang/lib/Driver/ToolChains/Flang.cpp +@@ -409,14 +409,12 @@ + + CmdArgs.push_back(Input.getFilename()); + +- // TODO: Replace flang-new with flang once the new driver replaces the +- // throwaway driver +- const char *Exec = Args.MakeArgString(D.GetProgramPath("flang-new", TC)); ++ const char *Exec = Args.MakeArgString(D.GetProgramPath("flang", TC)); + C.addCommand(std::make_unique(JA, *this, + ResponseFileSupport::AtFileUTF8(), + Exec, CmdArgs, Inputs, Output)); + } + +-Flang::Flang(const ToolChain &TC) : Tool("flang-new", "flang frontend", TC) {} ++Flang::Flang(const ToolChain &TC) : Tool("flang", "flang frontend", TC) {} + + Flang::~Flang() {} diff --git a/mingw-w64-clang/0303-ignore-new-bfd-options.patch b/mingw-w64-clang/0303-ignore-new-bfd-options.patch new file mode 100644 index 0000000000000..39ec520b3becd --- /dev/null +++ b/mingw-w64-clang/0303-ignore-new-bfd-options.patch @@ -0,0 +1,11 @@ +--- a/MinGW/Options.td ++++ b/MinGW/Options.td +@@ -165,6 +165,8 @@ def alias_undefined_u: JoinedOrSeparate<["-"], "u">, Alias; + def: Joined<["-"], "O">; + def: F<"as-needed">; + def: F<"build-id">; ++def: F<"default-image-base-high">; ++def: F<"default-image-base-low">; + def: F<"disable-auto-image-base">; + def: F<"enable-auto-image-base">; + def: F<"end-group">; diff --git a/mingw-w64-clang/README-patches.md b/mingw-w64-clang/README-patches.md new file mode 100644 index 0000000000000..352b8efb4c538 --- /dev/null +++ b/mingw-w64-clang/README-patches.md @@ -0,0 +1,20 @@ +# Patches statuses + +Legend: + +- :grey_exclamation: - not meant to upstream, for compatibility with GCC only +- :x: - not upstreamed +- :grey_question: - sent but not merged yet +- :arrow_up_small: - upstreamed +- :arrow_down_small: - backported + +----- + +- `"0001-Fix-GetHostTriple-for-mingw-w64-in-msys.patch"` :x: +- `"0002-Revert-CMake-try-creating-symlink-first-on-windows.patch"` :x: (win symlinks don't play well with pacman packages) +- `"0003-add-pthread-as-system-lib-for-mingw.patch"` :grey_exclamation: +- `"0004-enable-emutls-for-mingw.patch"` :grey_exclamation: +- `"0005-Fix-Any-linker-error-with-multiple-compilers.patch"` :grey_question: +- `"0101-link-pthread-with-mingw.patch"` :grey_exclamation: +- `"0301-Add-exceptions-for-Flang-runtime-libraries-on-MinGW.patch"` :upstreamed: +- `"0303-ignore-new-bfd-options.patch"` :x: diff --git a/mingw-w64-clang/update-clang-from-msys2.sh b/mingw-w64-clang/update-clang-from-msys2.sh new file mode 100755 index 0000000000000..2a82c5e35bb20 --- /dev/null +++ b/mingw-w64-clang/update-clang-from-msys2.sh @@ -0,0 +1,55 @@ + +die () { + printf "$@" >&2 + cleanup + exit 1 +} +cleanup(){ + rm -rf upstream +} + +pkgname=mingw-w64-clang + +old_pkgver="$(sed -ne 's/pkgver=\([.0-9]*\).*/\1/p' -e 's/_version=\([.0-9]*\).*/\1/p' < PKGBUILD)" +old_pkgrel="$(sed -ne 's/pkgrel=\([0-9]*\).*/\1/p' < PKGBUILD)" + +test -n "$old_pkgver" || + die "$0: could not determine current pkgver\n" + +test -n "$old_pkgrel" || + die "$0: could not determine current pkgrel\n" + +git clone --sparse --depth 1 https://github.com/msys2/MINGW-packages upstream +cd upstream +git sparse-checkout add $pkgname +cd .. + +new_pkgver="$(sed -ne 's/pkgver=\([.0-9]*\).*/\1/p' -e 's/_version=\([.0-9]*\).*/\1/p' < upstream/$pkgname/PKGBUILD)" +new_pkgrel="$(sed -ne 's/pkgrel=\([0-9]*\).*/\1/p' < upstream/$pkgname/PKGBUILD)" +rc="$(sed -ne 's/_rc="\(*\)".*/\1/p' < upstream/$pkgname/PKGBUILD)" + +test -n "$new_pkgver" || + die "$0: could not determine new pkgver\n" + +test -n "$new_pkgrel" || + die "$0: could not determine new pkgrel\n" + +test -z "$rc" || + die "$0: MSYS2 is currently on an RC version. This script is not able to handle RC versions." + +test "$new_pkgver" = "$old_pkgver" && + new_pkgrel="$old_pkgrel" + +new_pkgrel=$(("$new_pkgrel"+1)) + +rm -f *.patch +mv upstream/$pkgname/*.patch ./ +rm -f PKGBUILD +mv upstream/$pkgname/PKGBUILD ./ +rm -f README-patches.md +mv upstream/$pkgname/README-patches.md ./ + +sed -i "s/pkgrel=[.0-9]\+\(.*\)/pkgrel=$new_pkgrel\1/" PKGBUILD +sed -i 's/-DLLVM_TARGETS_TO_BUILD=".*"/-DLLVM_TARGETS_TO_BUILD="host"/' PKGBUILD + +cleanup