diff --git a/mingw-w64-clang/0002-Fix-Findzstd-on-MINGW.patch b/mingw-w64-clang/0002-Fix-Findzstd-on-MINGW.patch index 108fb0e6a2ef6..f68fb5a29b01a 100644 --- a/mingw-w64-clang/0002-Fix-Findzstd-on-MINGW.patch +++ b/mingw-w64-clang/0002-Fix-Findzstd-on-MINGW.patch @@ -1,6 +1,6 @@ --- a/cmake/modules/Findzstd.cmake +++ b/cmake/modules/Findzstd.cmake -@@ -29,11 +29,11 @@ +@@ -29,14 +29,14 @@ ) if(zstd_FOUND) @@ -13,4 +13,8 @@ + if(WIN32) # IMPORTED_LOCATION is the path to the DLL and IMPORTED_IMPLIB is the "library". get_filename_component(zstd_DIRNAME "${zstd_LIBRARY}" DIRECTORY) - string(REGEX REPLACE "${CMAKE_INSTALL_LIBDIR}$" "${CMAKE_INSTALL_BINDIR}" zstd_DIRNAME "${zstd_DIRNAME}") +- string(REGEX REPLACE "${CMAKE_INSTALL_LIBDIR}$" "${CMAKE_INSTALL_BINDIR}" zstd_DIRNAME "${zstd_DIRNAME}") ++ string(REGEX REPLACE "\\${CMAKE_INSTALL_LIBDIR}$" "${CMAKE_INSTALL_BINDIR}" zstd_DIRNAME "${zstd_DIRNAME}") + get_filename_component(zstd_BASENAME "${zstd_LIBRARY}" NAME) + string(REGEX REPLACE "\\${CMAKE_LINK_LIBRARY_SUFFIX}$" "${CMAKE_SHARED_LIBRARY_SUFFIX}" zstd_BASENAME "${zstd_BASENAME}") + set_target_properties(zstd::libzstd_shared PROPERTIES diff --git a/mingw-w64-clang/0005-aarch64-unwind-seh.patch b/mingw-w64-clang/0005-aarch64-unwind-seh.patch deleted file mode 100644 index ff4385cd3a52b..0000000000000 --- a/mingw-w64-clang/0005-aarch64-unwind-seh.patch +++ /dev/null @@ -1,75 +0,0 @@ -From cef120a2e5abba06c1d7a699a4fd4a17e488d6af Mon Sep 17 00:00:00 2001 -From: =?UTF-8?q?Martin=20Storsj=C3=B6?= -Date: Sun, 1 Oct 2023 00:08:23 +0300 -Subject: [PATCH] [AArch64] Disable loop alignment for Windows targets - -This should fix #66912. When emitting SEH unwind info, we need to -be able to calculate the exact length of functions before alignments -are fixed. Until that limitation is overcome, just disable all -loop alignment on Windows targets. ---- - llvm/lib/MC/MCWin64EH.cpp | 3 +++ - .../Target/AArch64/AArch64ISelLowering.cpp | 7 ++++++- - llvm/test/CodeGen/AArch64/sched-loop-align.ll | 21 +++++++++++++++++++ - 3 files changed, 30 insertions(+), 1 deletion(-) - create mode 100644 llvm/test/CodeGen/AArch64/sched-loop-align.ll - -diff --git a/lib/MC/MCWin64EH.cpp b/lib/MC/MCWin64EH.cpp -index a2d61da722af870..bb3492bec8aad8a 100644 ---- a/lib/MC/MCWin64EH.cpp -+++ b/lib/MC/MCWin64EH.cpp -@@ -1402,6 +1402,9 @@ static void ARM64EmitUnwindInfo(MCStreamer &streamer, WinEH::FrameInfo *info, - // here, but we'd have to emit the pdata, the xdata header, and the - // epilogue scopes later, since they depend on whether the we need to - // split the unwind data. -+ // -+ // If this is fixed, remove code in AArch64ISelLowering.cpp that -+ // disables loop alignment on Windows. - RawFuncLength = GetAbsDifference(streamer, info->FuncletOrFuncEnd, - info->Begin); - } -diff --git a/lib/Target/AArch64/AArch64ISelLowering.cpp b/lib/Target/AArch64/AArch64ISelLowering.cpp -index 932b36587f0694e..46064bc7e46783f 100644 ---- a/lib/Target/AArch64/AArch64ISelLowering.cpp -+++ b/lib/Target/AArch64/AArch64ISelLowering.cpp -@@ -1051,7 +1051,12 @@ AArch64TargetLowering::AArch64TargetLowering(const TargetMachine &TM, - // Set required alignment. - setMinFunctionAlignment(Align(4)); - // Set preferred alignments. -- setPrefLoopAlignment(STI.getPrefLoopAlignment()); -+ -+ // Don't align loops on Windows. The SEH unwind info generation needs to -+ // know the exact length of functions before the alignments have been -+ // expanded. -+ if (!Subtarget->isTargetWindows()) -+ setPrefLoopAlignment(STI.getPrefLoopAlignment()); - setMaxBytesForAlignment(STI.getMaxBytesForLoopAlignment()); - setPrefFunctionAlignment(STI.getPrefFunctionAlignment()); - -diff --git a/test/CodeGen/AArch64/sched-loop-align.ll b/test/CodeGen/AArch64/sched-loop-align.ll -new file mode 100644 -index 000000000000000..5b8e42c2790a439 ---- /dev/null -+++ b/test/CodeGen/AArch64/sched-loop-align.ll -@@ -0,0 +1,21 @@ -+; RUN: llc < %s -mtriple=aarch64-windows | FileCheck %s --check-prefix=WINDOWS -+; RUN: llc < %s -mtriple=aarch64-linux | FileCheck %s --check-prefix=LINUX -+ -+define dso_local void @b() #0 { -+entry: -+ br label %for.cond -+ -+for.cond: -+ tail call void @a() -+ br label %for.cond -+} -+ -+declare dso_local void @a(...) -+ -+attributes #0 = { noreturn nounwind uwtable "tune-cpu"="cortex-a53" } -+ -+; LINUX-LABEL: b: -+; LINUX: .p2align 4 -+ -+; WINDOWS-LABEL: b: -+; WINDOWS-NOT: .p2align diff --git a/mingw-w64-clang/10b78cc8cea65e7e77d227af4027963f39402724.patch b/mingw-w64-clang/10b78cc8cea65e7e77d227af4027963f39402724.patch new file mode 100644 index 0000000000000..a060aa9e07642 --- /dev/null +++ b/mingw-w64-clang/10b78cc8cea65e7e77d227af4027963f39402724.patch @@ -0,0 +1,59 @@ +From 10b78cc8cea65e7e77d227af4027963f39402724 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Martin=20Storsj=C3=B6?= +Date: Fri, 15 Dec 2023 20:15:07 +0200 +Subject: [PATCH] [llvm-windres] Pass user preprocessor arguments before the + input filename (#75389) + +If passing the windres option --preprocessor, the default arguments "-E +-xc -DRC_INVOKED" aren't passed. If these are passed explicitly by the +user via --preprocessor-arg instead, we need to make sure that "-xc" is +passed before the input filename, as this compiler/preprocessor option +only has an effect on input files that follow it. + +This fixes one of the issues with llvm-windres observed in +https://github.com/msys2/MINGW-packages/pull/19157. +--- + llvm/test/tools/llvm-rc/preproc.test | 2 +- + llvm/test/tools/llvm-rc/windres-preproc.test | 2 +- + llvm/tools/llvm-rc/llvm-rc.cpp | 4 ++-- + 3 files changed, 4 insertions(+), 4 deletions(-) + +diff --git a/llvm/test/tools/llvm-rc/preproc.test b/llvm/test/tools/llvm-rc/preproc.test +index f55e5434dce360b..7a6d8b3db036623 100644 +--- a/llvm/test/tools/llvm-rc/preproc.test ++++ b/llvm/test/tools/llvm-rc/preproc.test +@@ -1,3 +1,3 @@ + ; RUN: llvm-rc -### -i%p "-DFOO1=\"foo bar\"" -UFOO2 -D FOO3 -- %p/Inputs/empty.rc | FileCheck %s + +-; CHECK: {{^}} "clang" "--driver-mode=gcc" "-target" "{{.*}}-pc-windows-msvc-coff" "-E" "-xc" "-DRC_INVOKED" "{{.*}}empty.rc" "-o" "{{.*}}preproc-{{.*}}.rc" "-I" "{{.*}}" "-D" "FOO1=\"foo bar\"" "-U" "FOO2" "-D" "FOO3"{{$}} ++; CHECK: {{^}} "clang" "--driver-mode=gcc" "-target" "{{.*}}-pc-windows-msvc-coff" "-E" "-xc" "-DRC_INVOKED" "-I" "{{.*}}" "-D" "FOO1=\"foo bar\"" "-U" "FOO2" "-D" "FOO3" "{{.*}}empty.rc" "-o" "{{.*}}preproc-{{.*}}.rc"{{$}} +diff --git a/llvm/test/tools/llvm-rc/windres-preproc.test b/llvm/test/tools/llvm-rc/windres-preproc.test +index e55195b3a4d2802..42e83ba13021c27 100644 +--- a/llvm/test/tools/llvm-rc/windres-preproc.test ++++ b/llvm/test/tools/llvm-rc/windres-preproc.test +@@ -5,6 +5,6 @@ + + ; RUN: llvm-windres -### --include-dir %p/incdir1 --include %p/incdir2 "-DFOO1=\\\"foo bar\\\"" -UFOO2 -D FOO3 --preprocessor-arg "-DFOO4=\\\"baz baz\\\"" -DFOO5=\"bar\" %p/Inputs/empty.rc %t.res | FileCheck %s --check-prefix=CHECK1 + ; RUN: llvm-windres -### --include-dir %p/incdir1 --include %p/incdir2 "-DFOO1=\"foo bar\"" -UFOO2 -D FOO3 --preprocessor-arg "-DFOO4=\"baz baz\"" "-DFOO5=bar" %p/Inputs/empty.rc %t.res --use-temp-file | FileCheck %s --check-prefix=CHECK1 +-; CHECK1: {{^}} "clang" "--driver-mode=gcc" "-target" "{{.*}}-{{.*}}{{mingw32|windows-gnu}}" "-E" "-xc" "-DRC_INVOKED" "{{.*}}empty.rc" "-o" "{{.*}}preproc-{{.*}}.rc" "-I" "{{.*}}incdir1" "-I" "{{.*}}incdir2" "-D" "FOO1=\"foo bar\"" "-U" "FOO2" "-D" "FOO3" "-DFOO4=\"baz baz\"" "-D" "FOO5=bar"{{$}} ++; CHECK1: {{^}} "clang" "--driver-mode=gcc" "-target" "{{.*}}-{{.*}}{{mingw32|windows-gnu}}" "-E" "-xc" "-DRC_INVOKED" "-I" "{{.*}}incdir1" "-I" "{{.*}}incdir2" "-D" "FOO1=\"foo bar\"" "-U" "FOO2" "-D" "FOO3" "-DFOO4=\"baz baz\"" "-D" "FOO5=bar" "{{.*}}empty.rc" "-o" "{{.*}}preproc-{{.*}}.rc"{{$}} + ; RUN: llvm-windres -### --preprocessor "i686-w64-mingw32-gcc -E -DFOO=\\\"foo\\ bar\\\"" %p/Inputs/empty.rc %t.res | FileCheck %s --check-prefix=CHECK2 + ; CHECK2: {{^}} "i686-w64-mingw32-gcc" "-E" "-DFOO=\"foo bar\"" "{{.*}}empty.rc" "-o" "{{.*}}preproc-{{.*}}.rc"{{$}} +diff --git a/llvm/tools/llvm-rc/llvm-rc.cpp b/llvm/tools/llvm-rc/llvm-rc.cpp +index b955347f2a8646e..43756971fc9ba08 100644 +--- a/llvm/tools/llvm-rc/llvm-rc.cpp ++++ b/llvm/tools/llvm-rc/llvm-rc.cpp +@@ -253,11 +253,11 @@ void preprocess(StringRef Src, StringRef Dst, const RcOptions &Opts, + for (const auto &S : Opts.PreprocessCmd) + Args.push_back(S); + } ++ for (const auto &S : Opts.PreprocessArgs) ++ Args.push_back(S); + Args.push_back(Src); + Args.push_back("-o"); + Args.push_back(Dst); +- for (const auto &S : Opts.PreprocessArgs) +- Args.push_back(S); + if (Opts.PrintCmdAndExit || Opts.BeVerbose) { + for (const auto &A : Args) { + outs() << " "; diff --git a/mingw-w64-clang/1709e8c656de69f6d823a3ae6773bf815e373909.patch b/mingw-w64-clang/1709e8c656de69f6d823a3ae6773bf815e373909.patch new file mode 100644 index 0000000000000..8d3b224caed26 --- /dev/null +++ b/mingw-w64-clang/1709e8c656de69f6d823a3ae6773bf815e373909.patch @@ -0,0 +1,91 @@ +From 1709e8c656de69f6d823a3ae6773bf815e373909 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Martin=20Storsj=C3=B6?= +Date: Fri, 15 Dec 2023 20:16:19 +0200 +Subject: [PATCH] [llvm-windres] Resolve the --preprocessor executable in $PATH + (#75390) + +The llvm::sys::ExecuteAndWait function doesn't resolve the file to be +executed from $PATH - i.e. it is similar to execv(), not execvp(). + +Due to this, specifying a --preprocessor argument to llvm-windres only +worked if it specified an absolute path to the preprocessor executable. +This was observed as one of the issues in +https://github.com/msys2/MINGW-packages/pull/19157. + +Before d2fa6b694c2052cef1ddd507f6569bc84e3bbe35, this usage of +--preprocessor seemed to work, because the first argument of Args[] was +ignored and llvm-windres just executed the autodetected clang executable +regardless. + +Also improve the error messages printed if preprocessing failed. (If the +preprocessor executable was started but itself returned an error, we +don't get any error string.) +--- + llvm/test/tools/llvm-rc/windres-preproc.test | 16 +++++++++++++++- + llvm/tools/llvm-rc/llvm-rc.cpp | 17 +++++++++++++++-- + 2 files changed, 30 insertions(+), 3 deletions(-) + +diff --git a/llvm/test/tools/llvm-rc/windres-preproc.test b/llvm/test/tools/llvm-rc/windres-preproc.test +index 42e83ba13021c2..74e888614aa2b9 100644 +--- a/llvm/test/tools/llvm-rc/windres-preproc.test ++++ b/llvm/test/tools/llvm-rc/windres-preproc.test +@@ -7,4 +7,18 @@ + ; RUN: llvm-windres -### --include-dir %p/incdir1 --include %p/incdir2 "-DFOO1=\"foo bar\"" -UFOO2 -D FOO3 --preprocessor-arg "-DFOO4=\"baz baz\"" "-DFOO5=bar" %p/Inputs/empty.rc %t.res --use-temp-file | FileCheck %s --check-prefix=CHECK1 + ; CHECK1: {{^}} "clang" "--driver-mode=gcc" "-target" "{{.*}}-{{.*}}{{mingw32|windows-gnu}}" "-E" "-xc" "-DRC_INVOKED" "-I" "{{.*}}incdir1" "-I" "{{.*}}incdir2" "-D" "FOO1=\"foo bar\"" "-U" "FOO2" "-D" "FOO3" "-DFOO4=\"baz baz\"" "-D" "FOO5=bar" "{{.*}}empty.rc" "-o" "{{.*}}preproc-{{.*}}.rc"{{$}} + ; RUN: llvm-windres -### --preprocessor "i686-w64-mingw32-gcc -E -DFOO=\\\"foo\\ bar\\\"" %p/Inputs/empty.rc %t.res | FileCheck %s --check-prefix=CHECK2 +-; CHECK2: {{^}} "i686-w64-mingw32-gcc" "-E" "-DFOO=\"foo bar\"" "{{.*}}empty.rc" "-o" "{{.*}}preproc-{{.*}}.rc"{{$}} ++; CHECK2: {{^}} "{{.*}}i686-w64-mingw32-gcc" "-E" "-DFOO=\"foo bar\"" "{{.*}}empty.rc" "-o" "{{.*}}preproc-{{.*}}.rc"{{$}} ++ ++;; Test resolving the --preprocessor executable from PATH ++ ++; RUN: rm -rf %t-bin/testbin ++; RUN: mkdir -p %t-bin/testbin ++; RUN: ln -s llvm-windres %t-bin/testbin/i686-w64-mingw32-gcc ++; RUN: env PATH=%t-bin/testbin llvm-windres -### --preprocessor i686-w64-mingw32-gcc --preprocessor-arg -E --preprocessor-arg -xc -DRC_INVOKED %p/Inputs/empty.rc %t.res | FileCheck %s --check-prefix=CHECK3 ++; CHECK3: {{^}} "{{.*}}/testbin/i686-w64-mingw32-gcc" "-E" "-xc" "-D" "RC_INVOKED" "{{.*}}empty.rc" "-o" "{{.*}}preproc-{{.*}}.rc"{{$}} ++ ++ ++;; Test error messages when unable to execute the preprocessor. ++ ++; RUN: not llvm-windres --preprocessor intentionally-missing-executable %p/Inputs/empty.rc %t.res 2>&1 | FileCheck %s --check-prefix=CHECK4 ++; CHECK4: llvm-rc: Preprocessing failed: Executable "intentionally-missing-executable" doesn't exist! +diff --git a/llvm/tools/llvm-rc/llvm-rc.cpp b/llvm/tools/llvm-rc/llvm-rc.cpp +index 43756971fc9ba0..27fb0309e0ee54 100644 +--- a/llvm/tools/llvm-rc/llvm-rc.cpp ++++ b/llvm/tools/llvm-rc/llvm-rc.cpp +@@ -248,10 +248,17 @@ void preprocess(StringRef Src, StringRef Dst, const RcOptions &Opts, + SmallVector Args = { + Clang, "--driver-mode=gcc", "-target", Opts.Triple, "-E", + "-xc", "-DRC_INVOKED"}; ++ std::string PreprocessorExecutable; + if (!Opts.PreprocessCmd.empty()) { + Args.clear(); + for (const auto &S : Opts.PreprocessCmd) + Args.push_back(S); ++ if (!sys::fs::can_execute(Args[0])) { ++ if (auto P = sys::findProgramByName(Args[0])) { ++ PreprocessorExecutable = *P; ++ Args[0] = PreprocessorExecutable; ++ } ++ } + } + for (const auto &S : Opts.PreprocessArgs) + Args.push_back(S); +@@ -269,9 +276,15 @@ void preprocess(StringRef Src, StringRef Dst, const RcOptions &Opts, + } + // The llvm Support classes don't handle reading from stdout of a child + // process; otherwise we could avoid using a temp file. +- int Res = sys::ExecuteAndWait(Args[0], Args); ++ std::string ErrMsg; ++ int Res = ++ sys::ExecuteAndWait(Args[0], Args, /*Env=*/std::nullopt, /*Redirects=*/{}, ++ /*SecondsToWait=*/0, /*MemoryLimit=*/0, &ErrMsg); + if (Res) { +- fatalError("llvm-rc: Preprocessing failed."); ++ if (!ErrMsg.empty()) ++ fatalError("llvm-rc: Preprocessing failed: " + ErrMsg); ++ else ++ fatalError("llvm-rc: Preprocessing failed."); + } + } + diff --git a/mingw-w64-clang/1d5106d69cf475215887c42834158d710e586f1b.patch b/mingw-w64-clang/1d5106d69cf475215887c42834158d710e586f1b.patch new file mode 100644 index 0000000000000..2071a1a2d6e32 --- /dev/null +++ b/mingw-w64-clang/1d5106d69cf475215887c42834158d710e586f1b.patch @@ -0,0 +1,254 @@ +From 1d5106d69cf475215887c42834158d710e586f1b Mon Sep 17 00:00:00 2001 +From: Frederik Carlier +Date: Wed, 10 Jan 2024 08:52:13 -0800 +Subject: [PATCH] Objective C: use C++ exceptions on MinGW+GNUstep (#77255) + +The GNUstep Objective C runtime (libobjc2) is adding support for the GNU +ABI on Windows (more specifically, MinGW). The libobjc2 runtime uses C++ +exceptions in that configuration; this PR updates clang to act +accordingly. + +The corresponding change to libobjc2 is here: +https://github.com/gnustep/libobjc2/pull/267 +--- + clang/lib/CodeGen/CGException.cpp | 7 ++- + clang/lib/CodeGen/CGObjCGNU.cpp | 35 +++++++----- + .../test/CodeGenObjC/exceptions-personality.m | 53 +++++++++++++++++++ + clang/test/CodeGenObjC/personality.m | 5 +- + clang/test/CodeGenObjCXX/personality.mm | 5 +- + 5 files changed, 87 insertions(+), 18 deletions(-) + create mode 100644 clang/test/CodeGenObjC/exceptions-personality.m + +diff --git a/clang/lib/CodeGen/CGException.cpp b/clang/lib/CodeGen/CGException.cpp +index 0d507da5c1ba92f..56a246eb65e0a82 100644 +--- a/clang/lib/CodeGen/CGException.cpp ++++ b/clang/lib/CodeGen/CGException.cpp +@@ -156,7 +156,9 @@ static const EHPersonality &getObjCPersonality(const TargetInfo &Target, + case ObjCRuntime::WatchOS: + return EHPersonality::NeXT_ObjC; + case ObjCRuntime::GNUstep: +- if (L.ObjCRuntime.getVersion() >= VersionTuple(1, 7)) ++ if (T.isOSCygMing()) ++ return EHPersonality::GNU_CPlusPlus_SEH; ++ else if (L.ObjCRuntime.getVersion() >= VersionTuple(1, 7)) + return EHPersonality::GNUstep_ObjC; + [[fallthrough]]; + case ObjCRuntime::GCC: +@@ -210,7 +212,8 @@ static const EHPersonality &getObjCXXPersonality(const TargetInfo &Target, + return getObjCPersonality(Target, L); + + case ObjCRuntime::GNUstep: +- return EHPersonality::GNU_ObjCXX; ++ return Target.getTriple().isOSCygMing() ? EHPersonality::GNU_CPlusPlus_SEH ++ : EHPersonality::GNU_ObjCXX; + + // The GCC runtime's personality function inherently doesn't support + // mixed EH. Use the ObjC personality just to avoid returning null. +diff --git a/clang/lib/CodeGen/CGObjCGNU.cpp b/clang/lib/CodeGen/CGObjCGNU.cpp +index 9443fecf9b79469..cd1a0b6a130ff01 100644 +--- a/clang/lib/CodeGen/CGObjCGNU.cpp ++++ b/clang/lib/CodeGen/CGObjCGNU.cpp +@@ -168,6 +168,8 @@ class CGObjCGNU : public CGObjCRuntime { + /// Does the current target use SEH-based exceptions? False implies + /// Itanium-style DWARF unwinding. + bool usesSEHExceptions; ++ /// Does the current target uses C++-based exceptions? ++ bool usesCxxExceptions; + + /// Helper to check if we are targeting a specific runtime version or later. + bool isRuntime(ObjCRuntime::Kind kind, unsigned major, unsigned minor=0) { +@@ -819,12 +821,18 @@ class CGObjCGNUstep : public CGObjCGNU { + SlotLookupSuperFn.init(&CGM, "objc_slot_lookup_super", SlotTy, + PtrToObjCSuperTy, SelectorTy); + // If we're in ObjC++ mode, then we want to make +- if (usesSEHExceptions) { +- llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext); +- // void objc_exception_rethrow(void) +- ExceptionReThrowFn.init(&CGM, "objc_exception_rethrow", VoidTy); ++ llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext); ++ if (usesCxxExceptions) { ++ // void *__cxa_begin_catch(void *e) ++ EnterCatchFn.init(&CGM, "__cxa_begin_catch", PtrTy, PtrTy); ++ // void __cxa_end_catch(void) ++ ExitCatchFn.init(&CGM, "__cxa_end_catch", VoidTy); ++ // void objc_exception_rethrow(void*) ++ ExceptionReThrowFn.init(&CGM, "__cxa_rethrow", PtrTy); ++ } else if (usesSEHExceptions) { ++ // void objc_exception_rethrow(void) ++ ExceptionReThrowFn.init(&CGM, "objc_exception_rethrow", VoidTy); + } else if (CGM.getLangOpts().CPlusPlus) { +- llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext); + // void *__cxa_begin_catch(void *e) + EnterCatchFn.init(&CGM, "__cxa_begin_catch", PtrTy, PtrTy); + // void __cxa_end_catch(void) +@@ -833,7 +841,6 @@ class CGObjCGNUstep : public CGObjCGNU { + ExceptionReThrowFn.init(&CGM, "_Unwind_Resume_or_Rethrow", VoidTy, + PtrTy); + } else if (R.getVersion() >= VersionTuple(1, 7)) { +- llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext); + // id objc_begin_catch(void *e) + EnterCatchFn.init(&CGM, "objc_begin_catch", IdTy, PtrTy); + // void objc_end_catch(void) +@@ -841,7 +848,6 @@ class CGObjCGNUstep : public CGObjCGNU { + // void _Unwind_Resume_or_Rethrow(void*) + ExceptionReThrowFn.init(&CGM, "objc_exception_rethrow", VoidTy, PtrTy); + } +- llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext); + SetPropertyAtomic.init(&CGM, "objc_setProperty_atomic", VoidTy, IdTy, + SelectorTy, IdTy, PtrDiffTy); + SetPropertyAtomicCopy.init(&CGM, "objc_setProperty_atomic_copy", VoidTy, +@@ -2126,6 +2132,9 @@ CGObjCGNU::CGObjCGNU(CodeGenModule &cgm, unsigned runtimeABIVersion, + msgSendMDKind = VMContext.getMDKindID("GNUObjCMessageSend"); + usesSEHExceptions = + cgm.getContext().getTargetInfo().getTriple().isWindowsMSVCEnvironment(); ++ usesCxxExceptions = ++ cgm.getContext().getTargetInfo().getTriple().isOSCygMing() && ++ isRuntime(ObjCRuntime::GNUstep, 2); + + CodeGenTypes &Types = CGM.getTypes(); + IntTy = cast( +@@ -2212,7 +2221,10 @@ CGObjCGNU::CGObjCGNU(CodeGenModule &cgm, unsigned runtimeABIVersion, + + // void objc_exception_throw(id); + ExceptionThrowFn.init(&CGM, "objc_exception_throw", VoidTy, IdTy); +- ExceptionReThrowFn.init(&CGM, "objc_exception_throw", VoidTy, IdTy); ++ ExceptionReThrowFn.init(&CGM, ++ usesCxxExceptions ? "objc_exception_rethrow" ++ : "objc_exception_throw", ++ VoidTy, IdTy); + // int objc_sync_enter(id); + SyncEnterFn.init(&CGM, "objc_sync_enter", IntTy, IdTy); + // int objc_sync_exit(id); +@@ -2389,7 +2401,7 @@ llvm::Constant *CGObjCGNUstep::GetEHType(QualType T) { + if (usesSEHExceptions) + return CGM.getCXXABI().getAddrOfRTTIDescriptor(T); + +- if (!CGM.getLangOpts().CPlusPlus) ++ if (!CGM.getLangOpts().CPlusPlus && !usesCxxExceptions) + return CGObjCGNU::GetEHType(T); + + // For Objective-C++, we want to provide the ability to catch both C++ and +@@ -3995,7 +4007,7 @@ void CGObjCGNU::EmitThrowStmt(CodeGenFunction &CGF, + ExceptionAsObject = CGF.ObjCEHValueStack.back(); + isRethrow = true; + } +- if (isRethrow && usesSEHExceptions) { ++ if (isRethrow && (usesSEHExceptions || usesCxxExceptions)) { + // For SEH, ExceptionAsObject may be undef, because the catch handler is + // not passed it for catchalls and so it is not visible to the catch + // funclet. The real thrown object will still be live on the stack at this +@@ -4005,8 +4017,7 @@ void CGObjCGNU::EmitThrowStmt(CodeGenFunction &CGF, + // argument. + llvm::CallBase *Throw = CGF.EmitRuntimeCallOrInvoke(ExceptionReThrowFn); + Throw->setDoesNotReturn(); +- } +- else { ++ } else { + ExceptionAsObject = CGF.Builder.CreateBitCast(ExceptionAsObject, IdTy); + llvm::CallBase *Throw = + CGF.EmitRuntimeCallOrInvoke(ExceptionThrowFn, ExceptionAsObject); +diff --git a/clang/test/CodeGenObjC/exceptions-personality.m b/clang/test/CodeGenObjC/exceptions-personality.m +new file mode 100644 +index 000000000000000..9c25ee38b6d7cf5 +--- /dev/null ++++ b/clang/test/CodeGenObjC/exceptions-personality.m +@@ -0,0 +1,53 @@ ++// RUN: %clang_cc1 -triple x86_64-w64-windows-gnu -emit-llvm -fobjc-runtime=gnustep-2.0 -fexceptions -fobjc-exceptions -o %t %s ++// RUN: FileCheck --check-prefixes=CHECK-MINGW-OBJC2 < %t %s ++ ++// RUN: %clang_cc1 -triple x86_64-w64-windows-gnu -emit-llvm -fobjc-runtime=gcc -fexceptions -fobjc-exceptions -o %t %s ++// RUN: FileCheck --check-prefixes=CHECK-MINGW-GCC < %t %s ++ ++// RUN: %clang_cc1 -triple x86_64-w64-windows-msvc -emit-llvm -fobjc-runtime=gnustep-2.0 -fexceptions -fobjc-exceptions -o %t %s ++// RUN: FileCheck --check-prefixes=CHECK-MSVC-OBJC2 < %t %s ++ ++// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -emit-llvm -fobjc-runtime=gnustep-2.0 -fexceptions -fobjc-exceptions -o %t %s ++// RUN: FileCheck --check-prefixes=CHECK-LINUX-OBJC2 < %t %s ++ ++// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -emit-llvm -fobjc-runtime=gcc -fexceptions -fobjc-exceptions -o %t %s ++// RUN: FileCheck --check-prefixes=CHECK-LINUX-GCC < %t %s ++@interface Foo @end ++ ++void throwing(void) { ++ @try ++ { ++ // CHECK-MINGW-OBJC2: personality ptr @__gxx_personality_seh0 ++ // CHECK-MINGW-OBJC2: invoke void @objc_exception_throw ++ ++ // CHECK-MINGW-GCC: personality ptr @__gnu_objc_personality_v0 ++ // CHECK-MINGW-GCC: invoke void @objc_exception_throw ++ ++ // CHECK-MSVC-OBJC2: personality ptr @__CxxFrameHandler3 ++ // CHECK-MSVC-OBJC2: invoke void @objc_exception_throw ++ ++ // CHECK-LINUX-OBJC2: personality ptr @__gnustep_objc_personality_v0 ++ // CHECK-LINUX-OBJC2: invoke void @objc_exception_throw ++ ++ // CHECK-LINUX-GCC: personality ptr @__gnu_objc_personality_v0 ++ @throw(@"error!"); ++ } ++ @catch(...) ++ { ++ // CHECK-MINGW-OBJC2: call ptr @__cxa_begin_catch ++ // CHECK-MINGW-OBJC2: invoke ptr @__cxa_rethrow ++ // CHECK-MINGW-OBJC2: invoke void @__cxa_end_catch ++ ++ // CHECK-MINGW-GCC: call void @objc_exception_throw ++ ++ // CHECK-MSVC-OBJC2: call void @objc_exception_rethrow ++ ++ // CHECK-LINUX-OBJC2: call ptr @objc_begin_catch ++ // CHECK-LINUX-OBJC2: invoke void @objc_exception_throw ++ // CHECK-LINUX-OBJC2: invoke void @objc_end_catch() ++ ++ // CHECK-LINUX-GCC: invoke void @objc_exception_throw ++ ++ @throw; ++ } ++} +diff --git a/clang/test/CodeGenObjC/personality.m b/clang/test/CodeGenObjC/personality.m +index 6ec67ace3f1ac31..ede0aa34eaf6256 100644 +--- a/clang/test/CodeGenObjC/personality.m ++++ b/clang/test/CodeGenObjC/personality.m +@@ -27,8 +27,8 @@ + // RUN: %clang_cc1 -triple i686-unknown-windows-gnu -fexceptions -fobjc-exceptions -fobjc-runtime=ios -S -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-NS + // RUN: %clang_cc1 -triple i686-unknown-windows-gnu -fexceptions -fobjc-exceptions -fobjc-runtime=macosx -S -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-NS + // RUN: %clang_cc1 -triple i686-unknown-windows-gnu -fexceptions -fobjc-exceptions -fobjc-runtime=watchos -S -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-NS +-// RUN: %clang_cc1 -triple i686-unknown-windows-gnu -fexceptions -fobjc-exceptions -fobjc-runtime=gnustep-1.7 -S -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-GNUSTEP-1_7 +-// RUN: %clang_cc1 -triple i686-unknown-windows-gnu -fexceptions -fobjc-exceptions -fobjc-runtime=gnustep -S -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-GNUSTEP ++// RUN: %clang_cc1 -triple i686-unknown-windows-gnu -fexceptions -fobjc-exceptions -fobjc-runtime=gnustep-1.7 -S -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-WIN-GNU ++// RUN: %clang_cc1 -triple i686-unknown-windows-gnu -fexceptions -fobjc-exceptions -fobjc-runtime=gnustep -S -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-WIN-GNU + // RUN: %clang_cc1 -triple i686-unknown-windows-gnu -fexceptions -fobjc-exceptions -fobjc-runtime=gcc -S -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-GCC + // RUN: %clang_cc1 -triple i686-unknown-windows-gnu -fexceptions -exception-model=seh -fobjc-exceptions -fobjc-runtime=gcc -S -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-GCC-SEH + // RUN: %clang_cc1 -triple i686-unknown-windows-gnu -fexceptions -exception-model=sjlj -fobjc-exceptions -fobjc-runtime=gcc -S -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-GCC-SJLJ +@@ -50,6 +50,7 @@ + // CHECK-OBJFW-SJLJ: personality ptr @__gnu_objc_personality_sj0 + + // CHECK-WIN-MSVC: personality ptr @__CxxFrameHandler3 ++// CHECK-WIN-GNU: personality ptr @__gxx_personality_seh0 + + // CHECK-MACOSX-FRAGILE-MINGW-DWARF: personality ptr @__gcc_personality_v0 + // CHECK-MACOSX-FRAGILE-MINGW-SEH: personality ptr @__gcc_personality_seh0 +diff --git a/clang/test/CodeGenObjCXX/personality.mm b/clang/test/CodeGenObjCXX/personality.mm +index c6debe6f60c2a25..b8c7af962bd0bd6 100644 +--- a/clang/test/CodeGenObjCXX/personality.mm ++++ b/clang/test/CodeGenObjCXX/personality.mm +@@ -50,8 +50,8 @@ + // RUN: %clang_cc1 -triple i686-unknown-windows-gnu -fexceptions -exception-model=dwarf -fobjc-exceptions -fcxx-exceptions -fobjc-runtime=watchos -S -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-NS + // RUN: %clang_cc1 -triple i686-unknown-windows-gnu -fexceptions -exception-model=seh -fobjc-exceptions -fcxx-exceptions -fobjc-runtime=watchos -S -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-NS + // RUN: %clang_cc1 -triple i686-unknown-windows-gnu -fexceptions -exception-model=sjlj -fobjc-exceptions -fcxx-exceptions -fobjc-runtime=watchos -S -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-NS +-// RUN: %clang_cc1 -triple i686-unknown-windows-gnu -fexceptions -fobjc-exceptions -fcxx-exceptions -fobjc-runtime=gnustep-1.7 -S -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-GNUSTEP-1_7 +-// RUN: %clang_cc1 -triple i686-unknown-windows-gnu -fexceptions -fobjc-exceptions -fcxx-exceptions -fobjc-runtime=gnustep -S -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-GNUSTEP ++// RUN: %clang_cc1 -triple i686-unknown-windows-gnu -fexceptions -fobjc-exceptions -fcxx-exceptions -fobjc-runtime=gnustep-1.7 -S -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-WIN-GNU ++// RUN: %clang_cc1 -triple i686-unknown-windows-gnu -fexceptions -fobjc-exceptions -fcxx-exceptions -fobjc-runtime=gnustep -S -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-WIN-GNU + // RUN: %clang_cc1 -triple i686-unknown-windows-gnu -fexceptions -fobjc-exceptions -fcxx-exceptions -fobjc-runtime=gcc -S -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-GCC + // RUN: %clang_cc1 -triple i686-unknown-windows-gnu -fexceptions -exception-model=dwarf -fobjc-exceptions -fcxx-exceptions -fobjc-runtime=gcc -S -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-GCC + // RUN: %clang_cc1 -triple i686-unknown-windows-gnu -fexceptions -exception-model=seh -fobjc-exceptions -fcxx-exceptions -fobjc-runtime=gcc -S -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-GCC-SEH +@@ -81,6 +81,7 @@ + (void)e:(id)xception; + // CHECK-OBJFW-SJLJ: personality ptr @__gnu_objc_personality_sj0 + + // CHECK-WIN-MSVC: personality ptr @__CxxFrameHandler3 ++// CHECK-WIN-GNU: personality ptr @__gxx_personality_seh0 + + void f(void) { + @try { diff --git a/mingw-w64-clang/9e3d915d8ebf86e24c9ff58766be8e7c6aa7b0c0.patch b/mingw-w64-clang/9e3d915d8ebf86e24c9ff58766be8e7c6aa7b0c0.patch new file mode 100644 index 0000000000000..cbf242e8ba7be --- /dev/null +++ b/mingw-w64-clang/9e3d915d8ebf86e24c9ff58766be8e7c6aa7b0c0.patch @@ -0,0 +1,148 @@ +From 9e3d915d8ebf86e24c9ff58766be8e7c6aa7b0c0 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Martin=20Storsj=C3=B6?= +Date: Mon, 18 Dec 2023 12:31:05 +0200 +Subject: [PATCH] [llvm-windres] Change the interpretation of --preprocessor to + match Binutils 2.36 (#75391) + +Binutils 2.36 had a somewhat controversial change in how the +--preprocessor option was handled in GNU windres; previously, the option +was interpreted as a part of the command string, potentially containing +multiple arguments (which even was hinted at in the documentation). + +In Binutils 2.36, this was changed to interpret the --preprocessor +argument as one argument (possibly containing spaces) pointing at the +preprocessor executable. + +The existing behaviour where implicit arguments like -E -xc -DRC_INVOKED +are dropped if --preprocessor is specified, was kept. + +This was a breaking change for some users of GNU windres, see +https://sourceware.org/git/?p=binutils-gdb.git;a=commitdiff;h=21c33bcbe36377abf01614fb1b9be439a3b6de20, +https://sourceware.org/bugzilla/show_bug.cgi?id=27594, and +https://sourceware.org/git/?p=binutils-gdb.git;a=commitdiff;h=5edb8e3f5ad8d74a83fc0df7f6e4514eed0aa77f. + +As multiple years have passed since, the behaviour change seems to be +here to stay, and any users of the previous form of the option have been +forced to avoid this construct. Thus update llvm-windres to match the +new way Binutils of handling this option. + +One construct for specifying the path to the preprocessor, which works +both before and after binutils 2.36 (and this change in llvm-windres) is +to specify options like this: + +--preprocessor path/to/executable --preprocessor-arg -E +--preprocessor-arg -xc -DRC_INVOKED +--- + llvm/test/tools/llvm-rc/windres-preproc.test | 9 +++- + llvm/tools/llvm-rc/llvm-rc.cpp | 44 +++----------------- + 2 files changed, 12 insertions(+), 41 deletions(-) + +diff --git a/llvm/test/tools/llvm-rc/windres-preproc.test b/llvm/test/tools/llvm-rc/windres-preproc.test +index 74e888614aa2b9..13f82299a074bb 100644 +--- a/llvm/test/tools/llvm-rc/windres-preproc.test ++++ b/llvm/test/tools/llvm-rc/windres-preproc.test +@@ -6,8 +6,8 @@ + ; RUN: llvm-windres -### --include-dir %p/incdir1 --include %p/incdir2 "-DFOO1=\\\"foo bar\\\"" -UFOO2 -D FOO3 --preprocessor-arg "-DFOO4=\\\"baz baz\\\"" -DFOO5=\"bar\" %p/Inputs/empty.rc %t.res | FileCheck %s --check-prefix=CHECK1 + ; RUN: llvm-windres -### --include-dir %p/incdir1 --include %p/incdir2 "-DFOO1=\"foo bar\"" -UFOO2 -D FOO3 --preprocessor-arg "-DFOO4=\"baz baz\"" "-DFOO5=bar" %p/Inputs/empty.rc %t.res --use-temp-file | FileCheck %s --check-prefix=CHECK1 + ; CHECK1: {{^}} "clang" "--driver-mode=gcc" "-target" "{{.*}}-{{.*}}{{mingw32|windows-gnu}}" "-E" "-xc" "-DRC_INVOKED" "-I" "{{.*}}incdir1" "-I" "{{.*}}incdir2" "-D" "FOO1=\"foo bar\"" "-U" "FOO2" "-D" "FOO3" "-DFOO4=\"baz baz\"" "-D" "FOO5=bar" "{{.*}}empty.rc" "-o" "{{.*}}preproc-{{.*}}.rc"{{$}} +-; RUN: llvm-windres -### --preprocessor "i686-w64-mingw32-gcc -E -DFOO=\\\"foo\\ bar\\\"" %p/Inputs/empty.rc %t.res | FileCheck %s --check-prefix=CHECK2 +-; CHECK2: {{^}} "{{.*}}i686-w64-mingw32-gcc" "-E" "-DFOO=\"foo bar\"" "{{.*}}empty.rc" "-o" "{{.*}}preproc-{{.*}}.rc"{{$}} ++; RUN: llvm-windres -### --preprocessor "i686-w64-mingw32-gcc" --preprocessor-arg -E "-DFOO=\\\"foo bar\\\"" %p/Inputs/empty.rc %t.res | FileCheck %s --check-prefix=CHECK2 ++; CHECK2: {{^}} "{{.*}}i686-w64-mingw32-gcc" "-E" "-D" "FOO=\"foo bar\"" "{{.*}}empty.rc" "-o" "{{.*}}preproc-{{.*}}.rc"{{$}} + + ;; Test resolving the --preprocessor executable from PATH + +@@ -22,3 +22,8 @@ + + ; RUN: not llvm-windres --preprocessor intentionally-missing-executable %p/Inputs/empty.rc %t.res 2>&1 | FileCheck %s --check-prefix=CHECK4 + ; CHECK4: llvm-rc: Preprocessing failed: Executable "intentionally-missing-executable" doesn't exist! ++ ++;; Test --preprocessor with an argument with spaces. ++ ++; RUN: llvm-windres -### --preprocessor "path with spaces/gcc" %p/Inputs/empty.rc %t.res | FileCheck %s --check-prefix=CHECK5 ++; CHECK5: {{^}} "path with spaces/gcc" "{{.*}}empty.rc" "-o" "{{.*}}preproc-{{.*}}.rc"{{$}} +diff --git a/llvm/tools/llvm-rc/llvm-rc.cpp b/llvm/tools/llvm-rc/llvm-rc.cpp +index 27fb0309e0ee54..78ab96492acc75 100644 +--- a/llvm/tools/llvm-rc/llvm-rc.cpp ++++ b/llvm/tools/llvm-rc/llvm-rc.cpp +@@ -209,7 +209,7 @@ struct RcOptions { + bool Preprocess = true; + bool PrintCmdAndExit = false; + std::string Triple; +- std::vector PreprocessCmd; ++ std::optional Preprocessor; + std::vector PreprocessArgs; + + std::string InputFile; +@@ -229,7 +229,7 @@ struct RcOptions { + void preprocess(StringRef Src, StringRef Dst, const RcOptions &Opts, + const char *Argv0) { + std::string Clang; +- if (Opts.PrintCmdAndExit || !Opts.PreprocessCmd.empty()) { ++ if (Opts.PrintCmdAndExit || Opts.Preprocessor) { + Clang = "clang"; + } else { + ErrorOr ClangOrErr = findClang(Argv0, Opts.Triple); +@@ -249,10 +249,9 @@ void preprocess(StringRef Src, StringRef Dst, const RcOptions &Opts, + Clang, "--driver-mode=gcc", "-target", Opts.Triple, "-E", + "-xc", "-DRC_INVOKED"}; + std::string PreprocessorExecutable; +- if (!Opts.PreprocessCmd.empty()) { ++ if (Opts.Preprocessor) { + Args.clear(); +- for (const auto &S : Opts.PreprocessCmd) +- Args.push_back(S); ++ Args.push_back(*Opts.Preprocessor); + if (!sys::fs::can_execute(Args[0])) { + if (auto P = sys::findProgramByName(Args[0])) { + PreprocessorExecutable = *P; +@@ -342,36 +341,6 @@ std::string unescape(StringRef S) { + return Out; + } + +-std::vector unescapeSplit(StringRef S) { +- std::vector OutArgs; +- std::string Out; +- bool InQuote = false; +- for (int I = 0, E = S.size(); I < E; I++) { +- if (S[I] == '\\') { +- if (I + 1 < E) +- Out.push_back(S[++I]); +- else +- fatalError("Unterminated escape"); +- continue; +- } +- if (S[I] == '"') { +- InQuote = !InQuote; +- continue; +- } +- if (S[I] == ' ' && !InQuote) { +- OutArgs.push_back(Out); +- Out.clear(); +- continue; +- } +- Out.push_back(S[I]); +- } +- if (InQuote) +- fatalError("Unterminated quote"); +- if (!Out.empty()) +- OutArgs.push_back(Out); +- return OutArgs; +-} +- + RcOptions parseWindresOptions(ArrayRef ArgsArr, + ArrayRef InputArgsArray, + std::string Prefix) { +@@ -506,11 +475,8 @@ RcOptions parseWindresOptions(ArrayRef ArgsArr, + break; + } + } +- // TODO: If --use-temp-file is set, we shouldn't be unescaping +- // the --preprocessor argument either, only splitting it. + if (InputArgs.hasArg(WINDRES_preprocessor)) +- Opts.PreprocessCmd = +- unescapeSplit(InputArgs.getLastArgValue(WINDRES_preprocessor)); ++ Opts.Preprocessor = InputArgs.getLastArgValue(WINDRES_preprocessor); + + Opts.Params.CodePage = CpWin1252; // Different default + if (InputArgs.hasArg(WINDRES_codepage)) { diff --git a/mingw-w64-clang/PKGBUILD b/mingw-w64-clang/PKGBUILD index 49f14133b1ffb..d8c84d20d8d20 100644 --- a/mingw-w64-clang/PKGBUILD +++ b/mingw-w64-clang/PKGBUILD @@ -32,7 +32,7 @@ _version=17.0.6 _rc= _tag=llvmorg-${_version}${_rc} pkgver=${_version}${_rc/-/} -pkgrel=3 +pkgrel=8 pkgdesc="C language family frontend for LLVM (mingw-w64)" arch=('any') mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64') @@ -69,7 +69,16 @@ source=("${_url}/llvm-${pkgver}.src.tar.xz"{,.sig} "0004-enable-emutls-for-mingw.patch" "0101-link-pthread-with-mingw.patch" "0102-Rename-flang-new-flang-experimental-exec-to-flang.patch" - "0303-ignore-new-bfd-options.patch") + "0303-ignore-new-bfd-options.patch" + # Objective C: Use C++ mode unconditionally on MinGW + "1d5106d69cf475215887c42834158d710e586f1b.patch" + # Objective C: Mark instance variable offsets with DllExport/DllImport when targetting COFF + "b81ba52e15d95c3353489d4ce2f61c3771714c28.patch" + # Objective C: Work around type encodings which include '=' causing lld to fail + "c65ae76326040369bcd3a85678ab76e402140036.patch" + "10b78cc8cea65e7e77d227af4027963f39402724.patch" + "1709e8c656de69f6d823a3ae6773bf815e373909.patch" + "9e3d915d8ebf86e24c9ff58766be8e7c6aa7b0c0.patch") # Some patch notes :) #0001-0099 -> llvm #0101-0199 -> clang @@ -91,12 +100,18 @@ sha256sums=('b638167da139126ca11917b6880207cc6e8f9d1cbb1a48d87d017f697ef78188' '3054d0a9c9375dab1a4539cc2cc45ab340341c5d71475f9599ba7752e222947b' 'SKIP' 'eb03df53671df6627768141b3aaa76abe176a14e5e47911c97bec544387c4aff' - 'd7d58ad5d0e77f2803070a8fb7f4138a6f49a2cbf30c55ff059c31f40ca6b65c' + '70930739511f0934bafad518cd02acbccd03915ca4c6bec4b272eb5bcec33e1e' '7f0c64cd87b61e894be632f180ae5291e1aa9f1d9d382608f659067eeeda7146' '5f86e542dd1ec92b2fe06ee59061c3e23512df7bafabe82206f2b7d80b81836b' '715cb8862753854b2d9256e0b70003e2d1f57083d83eaeaf5a095fc72b8a4e26' '2770cadf8ccf6b31aece6aee8f76dceb71e6e9d01fdf3be74c3743480ce34899' - 'de631ab199a6fe83b3f695350bffaad067a2f95fc2ba9c8fe57dc85665d3653c') + 'de631ab199a6fe83b3f695350bffaad067a2f95fc2ba9c8fe57dc85665d3653c' + '65b50e18793686ec6620896155797ad2cc93d00f8a458c735a524a8c73d67980' + 'b23427a58ddf2f8fd16605ab9cc89d1233a409ee0a208f6d8d1a34204f716426' + 'a92baac68b7e7deb81edf197fee4e2ffb03a71488a05e7145bdd12f51d443d5a' + 'b7f484b02c79dfaac81243b085dd4196a7f46226ac64e0ba1690c41391a4a157' + '0f3dcb8b2d5f90f8ff2e77896d3b0ef6c87af8214e679917898e35dd678daef5' + 'e745aa71c903445c86639507256a5ca775e69b569b58f2ff48d6047703cfc81a') validpgpkeys=('B6C8F98282B944E3B0D5C2530FC3042E345AD05D' # Hans Wennborg, Google. '474E22316ABF4785A88C6E8EA2C794A986419D8A' # Tom Stellard 'D574BD5D1D0E98895E3BF90044F2485E45D59042') # Tobias Hieta @@ -128,6 +143,19 @@ prepare() { mv ${pkg}-$pkgver.src ${pkg} done + # Backports for llvm-windres, for improved compat with binutils 3.26+ + # https://github.com/msys2/MINGW-packages/pull/19157#issuecomment-1825285063 + apply_patch_with_msg \ + "10b78cc8cea65e7e77d227af4027963f39402724.patch" \ + "1709e8c656de69f6d823a3ae6773bf815e373909.patch" \ + "9e3d915d8ebf86e24c9ff58766be8e7c6aa7b0c0.patch" + + # Objective C patches + apply_patch_with_msg \ + "1d5106d69cf475215887c42834158d710e586f1b.patch" \ + "b81ba52e15d95c3353489d4ce2f61c3771714c28.patch" \ + "c65ae76326040369bcd3a85678ab76e402140036.patch" + # Patch llvm cd "${srcdir}/llvm" apply_patch_with_msg \ @@ -179,10 +207,13 @@ build() { FFI_INCLUDE_DIR=$(echo $FFI_INCLUDE_DIR | sed 's|-I||g') if check_option "debug" "y"; then - common_cmake_args+=(-DCMAKE_BUILD_TYPE=Debug) + common_cmake_args+=(-DCMAKE_BUILD_TYPE=Debug + -DLLVM_ENABLE_ASSERTIONS=ON) VERBOSE="VERBOSE=1" else - common_cmake_args+=(-DCMAKE_BUILD_TYPE=MinSizeRel) + common_cmake_args+=(-DCMAKE_BUILD_TYPE=MinSizeRel + -DLLVM_ENABLE_ASSERTIONS=OFF + -DLLVM_ENABLE_DUMP=ON) fi common_cmake_args+=(-Wno-dev -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} @@ -192,7 +223,6 @@ build() { -DPython3_FIND_REGISTRY=NEVER -DPython3_ROOT_DIR=${MINGW_PREFIX} -DFFI_INCLUDE_DIR="${FFI_INCLUDE_DIR}" - -DLLVM_ENABLE_ASSERTIONS=OFF -DLLVM_ENABLE_FFI=ON -DLLVM_INCLUDE_EXAMPLES=OFF -DLLVM_INCLUDE_BENCHMARKS=OFF @@ -352,7 +382,7 @@ package_clang-analyzer() { local _analyzer for _analyzer in scan-build scan-build-py scan-view; do - DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/cmake --install "${srcdir}/build-${MSYSTEM}" --component ${_analyzer} + DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/cmake --install "${srcdir}/build-${MSYSTEM}/tools/clang/tools/${_analyzer}" done # Compile Python scripts diff --git a/mingw-w64-clang/b81ba52e15d95c3353489d4ce2f61c3771714c28.patch b/mingw-w64-clang/b81ba52e15d95c3353489d4ce2f61c3771714c28.patch new file mode 100644 index 0000000000000..82b5ce1d8179f --- /dev/null +++ b/mingw-w64-clang/b81ba52e15d95c3353489d4ce2f61c3771714c28.patch @@ -0,0 +1,136 @@ +From b81ba52e15d95c3353489d4ce2f61c3771714c28 Mon Sep 17 00:00:00 2001 +From: Frederik Carlier +Date: Tue, 9 Jan 2024 10:15:01 +0100 +Subject: [PATCH] Set dllstorage on ObjectiveC ivar offsets (#77385) + +Mark instance variable offset symbols with `dllexport`/`dllimport` if +they are not hidden and the interface declaration is marked with +`dllexport`/`dllimport`, when using the GNUstep 2.x ABI. + +/cc @davidchisnall +--- + clang/lib/CodeGen/CGObjCGNU.cpp | 2 ++ + clang/test/CodeGenObjC/dllstorage.m | 29 +++++++++++++++++++++++++++++ + 2 files changed, 31 insertions(+) + +diff --git a/clang/lib/CodeGen/CGObjCGNU.cpp b/clang/lib/CodeGen/CGObjCGNU.cpp +index 4ca1a8cce64d89..9443fecf9b7946 100644 +--- a/clang/lib/CodeGen/CGObjCGNU.cpp ++++ b/clang/lib/CodeGen/CGObjCGNU.cpp +@@ -1851,6 +1851,8 @@ class CGObjCGNUstep2 : public CGObjCGNUstep { + llvm::GlobalValue::HiddenVisibility : + llvm::GlobalValue::DefaultVisibility; + OffsetVar->setVisibility(ivarVisibility); ++ if (ivarVisibility != llvm::GlobalValue::HiddenVisibility) ++ CGM.setGVProperties(OffsetVar, OID->getClassInterface()); + ivarBuilder.add(OffsetVar); + // Ivar size + ivarBuilder.addInt(Int32Ty, +diff --git a/clang/test/CodeGenObjC/dllstorage.m b/clang/test/CodeGenObjC/dllstorage.m +index 64ba21f9769ae2..0dbf1881caa9c0 100644 +--- a/clang/test/CodeGenObjC/dllstorage.m ++++ b/clang/test/CodeGenObjC/dllstorage.m +@@ -1,4 +1,5 @@ + // RUN: %clang_cc1 -triple x86_64-unknown-windows-msvc -fdeclspec -fobjc-runtime=ios -fobjc-exceptions -S -emit-llvm -o - %s | FileCheck -allow-deprecated-dag-overlap -check-prefix CHECK-IR %s ++// RUN: %clang_cc1 -triple x86_64-unknown-windows-msvc -fdeclspec -fobjc-runtime=gnustep-2.0 -fobjc-exceptions -S -emit-llvm -o - %s | FileCheck -allow-deprecated-dag-overlap -check-prefix CHECK-NF %s + // RUN: %clang_cc1 -triple i686-windows-itanium -fms-extensions -fobjc-runtime=macosx -fdeclspec -fobjc-exceptions -S -emit-llvm -o - %s | FileCheck -allow-deprecated-dag-overlap -check-prefix CHECK-IR %s + // RUN: %clang_cc1 -triple i686-windows-itanium -fms-extensions -fobjc-runtime=objfw -fdeclspec -fobjc-exceptions -S -emit-llvm -o - %s | FileCheck -allow-deprecated-dag-overlap -check-prefix CHECK-FW %s + +@@ -12,6 +13,8 @@ + (instancetype) new; + // CHECK-IR-DAG: @"OBJC_METACLASS_$_I" = external dllimport global %struct._class_t + // CHECK-IR-DAG: @"OBJC_CLASS_$_I" = external dllimport global %struct._class_t + ++// CHECK-NF-DAG: @"$_OBJC_CLASS_I" = external dllimport global ptr ++ + __declspec(dllexport) + @interface J : I + @end +@@ -22,6 +25,9 @@ @interface J : I + // CHECK-FW-DAG: @_OBJC_METACLASS_J = dso_local dllexport global + // CHECK-FW-DAG: @_OBJC_CLASS_J = dso_local dllexport global + ++// CHECK-NF-DAG: @"$_OBJC_METACLASS_J" = internal global ++// CHECK-NF-DAG: @"$_OBJC_CLASS_J" = dllexport global ++ + @implementation J { + id _ivar; + } +@@ -29,6 +35,8 @@ @implementation J { + + // CHECK-IR-DAG: @"OBJC_IVAR_$_J._ivar" = global i32 + ++// CHECK-NF-DAG: @"__objc_ivar_offset_J._ivar.\01" = hidden global i32 ++ + @interface K : J + @end + +@@ -38,6 +46,9 @@ @interface K : J + // CHECK-FW-DAG: @_OBJC_METACLASS_K = dso_local global + // CHECK-FW-DAG: @_OBJC_CLASS_K = dso_local global + ++// CHECK-NF-DAG: @"$_OBJC_METACLASS_K" = internal global ++// CHECK-NF-DAG: @"$_OBJC_CLASS_K" = global ++ + @implementation K { + id _ivar; + } +@@ -45,6 +56,8 @@ @implementation K { + + // CHECK-IR-DAG: @"OBJC_IVAR_$_K._ivar" = global i32 + ++// CHECK-NF-DAG: @"__objc_ivar_offset_K._ivar.\01" = hidden global i32 ++ + __declspec(dllexport) + @interface L : K + @end +@@ -55,6 +68,9 @@ @interface L : K + // CHECK-FW-DAG: @_OBJC_METACLASS_L = dso_local dllexport global + // CHECK-FW-DAG: @_OBJC_CLASS_L = dso_local dllexport global + ++// CHECK-NF-DAG: @"$_OBJC_METACLASS_L" = internal global ++// CHECK-NF-DAG: @"$_OBJC_CLASS_L" = dllexport global ++ + @implementation L { + id _none; + +@@ -78,6 +94,12 @@ @implementation L { + // CHECK-IR-DAG: @"OBJC_IVAR_$_L._package" = global i32 + // CHECK-IR-DAG: @"OBJC_IVAR_$_L._private" = global i32 + ++// CHECK-NF-DAG: @"__objc_ivar_offset_L._none.\01" = hidden global i32 ++// CHECK-NF-DAG: @"__objc_ivar_offset_L._public.\01" = dso_local dllexport global i32 ++// CHECK-NF-DAG: @"__objc_ivar_offset_L._protected.\01" = dso_local dllexport global i32 ++// CHECK-NF-DAG: @"__objc_ivar_offset_L._package.\01" = hidden global i32 ++// CHECK-NF-DAG: @"__objc_ivar_offset_L._private.\01" = hidden global i32 ++ + __declspec(dllimport) + @interface M : I { + @public +@@ -89,6 +111,9 @@ @interface M : I { + + // CHECK-IR-DAG: @"OBJC_IVAR_$_M._ivar" = external dllimport global i32 + ++// CHECK-NF-DAG: @"$_OBJC_REF_CLASS_M" = external dllimport global ptr ++// CHECK-NF-DAG: @"__objc_ivar_offset_M._ivar.\01" = external global i32 ++ + __declspec(dllexport) + __attribute__((__objc_exception__)) + @interface N : I +@@ -97,6 +122,8 @@ @interface N : I + // CHECK-FW-DAG: @_OBJC_METACLASS_N = dso_local dllexport global + // CHECK-FW-DAG: @_OBJC_CLASS_N = dso_local dllexport global + ++// CHECK-NF-DAG: @"$_OBJC_CLASS_N" = dllexport global ++ + @implementation N : I + @end + +@@ -124,6 +151,8 @@ id f(Q *q) { + + // CHECK-IR-DAG: @"OBJC_IVAR_$_M._ivar" = external dllimport global i32 + ++// CHECK-NF-DAG: @"__objc_ivar_offset_M._ivar.\01" = external global i32 ++ + int g(void) { + @autoreleasepool { + M *mi = [M new]; diff --git a/mingw-w64-clang/c65ae76326040369bcd3a85678ab76e402140036.patch b/mingw-w64-clang/c65ae76326040369bcd3a85678ab76e402140036.patch new file mode 100644 index 0000000000000..88b8e76bb300d --- /dev/null +++ b/mingw-w64-clang/c65ae76326040369bcd3a85678ab76e402140036.patch @@ -0,0 +1,41 @@ +From c65ae76326040369bcd3a85678ab76e402140036 Mon Sep 17 00:00:00 2001 +From: Frederik Carlier +Date: Wed, 10 Jan 2024 16:51:18 +0000 +Subject: [PATCH] Objective C: Avoid including '=' characters in type encodings + in instance variable names + +--- + clang/lib/CodeGen/CGObjCGNU.cpp | 6 ++++++ + 1 file changed, 6 insertions(+) + +diff --git a/clang/lib/CodeGen/CGObjCGNU.cpp b/clang/lib/CodeGen/CGObjCGNU.cpp +index cd1a0b6a130ff01..62da81e59f34de5 100644 +--- a/clang/lib/CodeGen/CGObjCGNU.cpp ++++ b/clang/lib/CodeGen/CGObjCGNU.cpp +@@ -1437,6 +1437,8 @@ class CGObjCGNUstep2 : public CGObjCGNUstep { + std::string MangledTypes = std::string(TypeEncoding); + std::replace(MangledTypes.begin(), MangledTypes.end(), + '@', '\1'); ++ std::replace(MangledTypes.begin(), MangledTypes.end(), ++ '=', '\2'); + std::string TypesVarName = ".objc_sel_types_" + MangledTypes; + auto *TypesGlobal = TheModule.getGlobalVariable(TypesVarName); + if (!TypesGlobal) { +@@ -1460,6 +1462,8 @@ class CGObjCGNUstep2 : public CGObjCGNUstep { + std::string MangledTypes = TypeEncoding; + std::replace(MangledTypes.begin(), MangledTypes.end(), + '@', '\1'); ++ std::replace(MangledTypes.begin(), MangledTypes.end(), ++ '=', '\2'); + auto SelVarName = (StringRef(".objc_selector_") + Sel.getAsString() + "_" + + MangledTypes).str(); + if (auto *GV = TheModule.getNamedGlobal(SelVarName)) +@@ -1674,6 +1678,8 @@ class CGObjCGNUstep2 : public CGObjCGNUstep { + // Prevent the @ from being interpreted as a symbol version. + std::replace(TypeEncoding.begin(), TypeEncoding.end(), + '@', '\1'); ++ std::replace(TypeEncoding.begin(), TypeEncoding.end(), ++ '=', '\2'); + const std::string Name = "__objc_ivar_offset_" + ID->getNameAsString() + + '.' + Ivar->getNameAsString() + '.' + TypeEncoding; + return Name; diff --git a/mingw-w64-clang/update-clang-from-msys2.sh b/mingw-w64-clang/update-clang-from-msys2.sh old mode 100644 new mode 100755 index 2e83377935fe3..0e5cc775aa866 --- a/mingw-w64-clang/update-clang-from-msys2.sh +++ b/mingw-w64-clang/update-clang-from-msys2.sh @@ -49,7 +49,8 @@ mv upstream/$pkgname/README-patches.md ./ || die "$0: failed to replace existing sed -e "s/pkgrel=[.0-9]\+\(.*\)/pkgrel=$new_pkgrel\1/" \ -e 's/-DCMAKE_BUILD_TYPE=Release/-DCMAKE_BUILD_TYPE=MinSizeRel/' \ - -e 's/-DLLVM_TARGETS_TO_BUILD=.*/-DLLVM_TARGETS_TO_BUILD=Native/' \ + -e 's/-DLLVM_TARGETS_TO_BUILD=".*"/-DLLVM_TARGETS_TO_BUILD=Native/' \ + -e 's/-DLLVM_TARGETS_TO_BUILD=[A-Za-z0-9;]*/-DLLVM_TARGETS_TO_BUILD=Native/' \ -e 's/-DLLVM_ENABLE_SPHINX=ON/-DLLVM_ENABLE_SPHINX=OFF/'\ -e '/^check()/,/^}/d' \ -i PKGBUILD