Date: Thursday, May 27, 2021 @ 04:32:42 Author: foutrelis Revision: 948006
upgpkg: lib32-clang 12.0.0-1: new upstream release Build with -fno-semantic-interposition and -Bsymbolic-function for improved performance (FS#70697). Added: lib32-clang/trunk/clang-link-with-Bsymbolic-functions.patch lib32-clang/trunk/opencl-respect-calling-convention-for-builtin.patch Modified: lib32-clang/trunk/PKGBUILD lib32-clang/trunk/enable-SSP-and-PIE-by-default.patch -----------------------------------------------------+ PKGBUILD | 19 ++ clang-link-with-Bsymbolic-functions.patch | 63 +++++++++ enable-SSP-and-PIE-by-default.patch | 126 +++++++++++------- opencl-respect-calling-convention-for-builtin.patch | 107 +++++++++++++++ 4 files changed, 261 insertions(+), 54 deletions(-) Modified: PKGBUILD =================================================================== --- PKGBUILD 2021-05-27 04:29:14 UTC (rev 948005) +++ PKGBUILD 2021-05-27 04:32:42 UTC (rev 948006) @@ -2,7 +2,7 @@ # Contributor: Jan "heftig" Steffens <[email protected]> pkgname=lib32-clang -pkgver=11.1.0 +pkgver=12.0.0 pkgrel=1 pkgdesc="C language family frontend for LLVM (32-bit)" arch=('x86_64') @@ -13,12 +13,16 @@ _source_base=https://github.com/llvm/llvm-project/releases/download/llvmorg-$pkgver source=($_source_base/clang-$pkgver.src.tar.xz{,.sig} $_source_base/llvm-$pkgver.src.tar.xz{,.sig} + opencl-respect-calling-convention-for-builtin.patch + clang-link-with-Bsymbolic-functions.patch enable-SSP-and-PIE-by-default.patch) -sha256sums=('0a8288f065d1f57cb6d96da4d2965cbea32edc572aa972e466e954d17148558b' +sha256sums=('e26e452e91d4542da3ebbf404f024d3e1cbf103f4cd110c26bf0a19621cca9ed' 'SKIP' - 'ce8508e318a01a63d4e8b3090ab2ded3c598a50258cc49e2625b9120d4c03ea5' + '49dc47c8697a1a0abd4ee51629a696d7bfe803662f2a7252a3b16fc75f3a8b50' 'SKIP' - '248a0e8609b00689e82ce5e05e1de58b7c8ae09a35bbb9625e9069e1f13d2fec') + '859d34dac43999edfc4c33e1cbb6e7458921fa9f16a93514701c1a9706665d24' + '5bc0b47c70990bb8dd0cf4138a8ab9e15cf6b008b7c0cf2c7aac3736b559e0e6' + 'a877fa5cf1c1cca3bd55f9a36cf8c1bdd061ff398aeace90fe3cbd9e82550da3') validpgpkeys+=('B6C8F98282B944E3B0D5C2530FC3042E345AD05D') # Hans Wennborg <[email protected]> validpgpkeys+=('474E22316ABF4785A88C6E8EA2C794A986419D8A') # Tom Stellard <[email protected]> @@ -48,6 +52,12 @@ cd "$srcdir/clang-$pkgver.src" mkdir build patch -Np2 -i ../enable-SSP-and-PIE-by-default.patch + + # Some fixes from the release/12.x branch + patch -Np2 -i ../opencl-respect-calling-convention-for-builtin.patch + + # https://bugs.archlinux.org/task/70697 + patch -Np2 -i ../clang-link-with-Bsymbolic-functions.patch } build() { @@ -59,7 +69,6 @@ -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr - -DPYTHON_EXECUTABLE=/usr/bin/python -DLLVM_LIBDIR_SUFFIX=32 -DCMAKE_C_FLAGS:STRING=-m32 -DCMAKE_CXX_FLAGS:STRING=-m32 Added: clang-link-with-Bsymbolic-functions.patch =================================================================== --- clang-link-with-Bsymbolic-functions.patch (rev 0) +++ clang-link-with-Bsymbolic-functions.patch 2021-05-27 04:32:42 UTC (rev 948006) @@ -0,0 +1,63 @@ +From 4f05f4c8e66bc76b1d94f5283494404382e3bacd Mon Sep 17 00:00:00 2001 +From: Fangrui Song <[email protected]> +Date: Thu, 13 May 2021 13:44:57 -0700 +Subject: [PATCH] [CMake][ELF] Link libLLVM.so and libclang-cpp.so with + -Bsymbolic-functions + +llvm-dev message: https://lists.llvm.org/pipermail/llvm-dev/2021-May/150465.html + +In an ELF shared object, a default visibility defined symbol is preemptible by +default. This creates some missed optimization opportunities. +-Bsymbolic-functions is more aggressive than our current -fvisibility-inlines-hidden +(present since 2012) as it applies to all function definitions. It can + +* avoid PLT for cross-TU function calls && reduce dynamic symbol lookup +* reduce dynamic symbol lookup for taking function addresses and optimize out GOT/TOC on x86-64/ppc64 + +In a -DLLVM_TARGETS_TO_BUILD=X86 build, the number of JUMP_SLOT decreases from 12716 to 1628, and the number of GLOB_DAT decreases from 1918 to 1313 +The built clang with `-DLLVM_LINK_LLVM_DYLIB=on -DCLANG_LINK_CLANG_DYLIB=on` is significantly faster. +See the Linux kernel build result https://bugs.archlinux.org/task/70697 + +Note: the performance of -fno-semantic-interposition -Bsymbolic-functions +libLLVM.so and libclang-cpp.so is close to a PIE binary linking against +`libLLVM*.a` and `libclang*.a`. When the host compiler is Clang, +-Bsymbolic-functions is the major contributor. On x86-64 (with GOTPCRELX) and +ppc64 ELFv2, the GOT/TOC relocations can be optimized. + +Some implication: + +Interposing a subset of functions is no longer supported. +(This is fragile on ELF and unsupported on Mach-O at all. For Mach-O we don't +use `ld -interpose` or `-flat_namespace`) + +Compiling a program which takes the address of any LLVM function with +`{gcc,clang} -fno-pic` and expects the address to equal to the address taken +from libLLVM.so or libclang-cpp.so is unsupported. I am fairly confident that +llvm-project shouldn't have different behaviors depending on such pointer +equality (as we've been using -fvisibility-inlines-hidden which applies to +inline functions for a long time), but if we accidentally do, users should be +aware that they should not make assumption on pointer equality in `-fno-pic` +mode. + +See more on https://maskray.me/blog/2021-05-09-fno-semantic-interposition + +Reviewed By: phosek + +Differential Revision: https://reviews.llvm.org/D102090 +--- + clang/tools/clang-shlib/CMakeLists.txt | 5 +++++ + 1 file changed, 5 insertions(+) + +diff --git a/clang/tools/clang-shlib/CMakeLists.txt b/clang/tools/clang-shlib/CMakeLists.txt +index 5949223fc8e3..d08cf8938328 100644 +--- a/clang/tools/clang-shlib/CMakeLists.txt ++++ b/clang/tools/clang-shlib/CMakeLists.txt +@@ -48,3 +48,8 @@ add_clang_library(clang-cpp + ${_OBJECTS} + LINK_LIBS + ${_DEPS}) ++# Optimize function calls for default visibility definitions to avoid PLT and ++# reduce dynamic relocations. ++if (NOT APPLE) ++ target_link_options(clang-cpp PRIVATE LINKER:-Bsymbolic-functions) ++endif() Modified: enable-SSP-and-PIE-by-default.patch =================================================================== --- enable-SSP-and-PIE-by-default.patch 2021-05-27 04:29:14 UTC (rev 948005) +++ enable-SSP-and-PIE-by-default.patch 2021-05-27 04:32:42 UTC (rev 948006) @@ -1,6 +1,6 @@ -From bb7bdc61f8a80db9aa16370d9c9fd0ae7be825cc Mon Sep 17 00:00:00 2001 +From 6878f5376dec0a3d75674d5a2076d4af911f7c7c Mon Sep 17 00:00:00 2001 From: Evangelos Foutras <[email protected]> -Date: Mon, 12 Oct 2020 16:40:41 +0300 +Date: Wed, 12 May 2021 08:55:14 +0300 Subject: [PATCH] Enable SSP and PIE by default This is a minimal set of changes needed to make clang use SSP and PIE by @@ -17,26 +17,27 @@ Hopefully these changes will be obsoleted by the introduction upstream of a compile-time option (https://bugs.llvm.org/show_bug.cgi?id=13410) --- - clang/lib/Driver/ToolChains/Linux.cpp | 14 ++++++++++++-- - clang/lib/Driver/ToolChains/Linux.h | 1 + + clang/lib/Driver/ToolChains/Linux.cpp | 10 ++++++++-- + clang/lib/Driver/ToolChains/Linux.h | 5 +++++ clang/test/Driver/cross-linux.c | 16 ++++++++-------- clang/test/Driver/env.c | 2 +- clang/test/Driver/fsanitize.c | 14 +++++++------- clang/test/Driver/gcc-toolchain.cpp | 2 +- clang/test/Driver/hexagon-toolchain-elf.c | 2 +- + clang/test/Driver/hip-fpie-option.hip | 4 ++-- clang/test/Driver/linux-as.c | 4 ++-- clang/test/Driver/linux-ld.c | 2 ++ - clang/test/Driver/ppc-abi.c | 16 +++++++++------- + clang/test/Driver/ppc-abi.c | 18 +++++++++++------- clang/test/Driver/riscv32-toolchain.c | 4 ++-- clang/test/Driver/riscv64-toolchain.c | 4 ++-- clang/test/Driver/stack-protector.c | 4 ++-- - 13 files changed, 50 insertions(+), 35 deletions(-) + 14 files changed, 54 insertions(+), 37 deletions(-) diff --git a/clang/lib/Driver/ToolChains/Linux.cpp b/clang/lib/Driver/ToolChains/Linux.cpp -index 180350476c3..119f32ceec6 100644 +index 9663a7390ada..2f8d01092557 100644 --- a/clang/lib/Driver/ToolChains/Linux.cpp +++ b/clang/lib/Driver/ToolChains/Linux.cpp -@@ -819,8 +819,18 @@ void Linux::AddIAMCUIncludeArgs(const ArgList &DriverArgs, +@@ -832,8 +832,14 @@ void Linux::AddIAMCUIncludeArgs(const ArgList &DriverArgs, } bool Linux::isPIEDefault() const { @@ -50,27 +51,34 @@ + getTriple().isMusl() || getSanitizerArgs().requiresPIE(); + + return true; -+} -+ -+unsigned Linux::GetDefaultStackProtectorLevel(bool KernelOrKext) const { -+ return 2; } bool Linux::isNoExecStackDefault() const { diff --git a/clang/lib/Driver/ToolChains/Linux.h b/clang/lib/Driver/ToolChains/Linux.h -index 6b16b0e6499..d0024110aef 100644 +index 6b16b0e64990..04c4d176ca71 100644 --- a/clang/lib/Driver/ToolChains/Linux.h +++ b/clang/lib/Driver/ToolChains/Linux.h -@@ -39,6 +39,7 @@ public: +@@ -10,6 +10,7 @@ + #define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_LINUX_H + + #include "Gnu.h" ++#include "clang/Basic/LangOptions.h" + #include "clang/Driver/ToolChain.h" + + namespace clang { +@@ -39,6 +40,10 @@ public: bool isPIEDefault() const override; bool isNoExecStackDefault() const override; bool IsMathErrnoDefault() const override; -+ unsigned GetDefaultStackProtectorLevel(bool KernelOrKext) const override; ++ LangOptions::StackProtectorMode ++ GetDefaultStackProtectorLevel(bool KernelOrKext) const override { ++ return LangOptions::SSPStrong; ++ } SanitizerMask getSupportedSanitizers() const override; void addProfileRTLibs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const override; diff --git a/clang/test/Driver/cross-linux.c b/clang/test/Driver/cross-linux.c -index 6c2dab26069..c28c5653e34 100644 +index 6c2dab260695..c28c5653e348 100644 --- a/clang/test/Driver/cross-linux.c +++ b/clang/test/Driver/cross-linux.c @@ -42,8 +42,8 @@ @@ -118,7 +126,7 @@ // CHECK-MULTI64-X86-64: "-L[[gcc_install]]/../../../../x86_64-unknown-linux/lib" // CHECK-MULTI64-X86-64: "-L[[sysroot]]/lib" diff --git a/clang/test/Driver/env.c b/clang/test/Driver/env.c -index 0371bc91c4a..ea89f525121 100644 +index 0371bc91c4a3..ea89f5251217 100644 --- a/clang/test/Driver/env.c +++ b/clang/test/Driver/env.c @@ -20,7 +20,7 @@ @@ -131,10 +139,10 @@ // CHECK-LD-32: "-L[[SYSROOT]]/usr/lib/gcc/i386-unknown-linux/4.6.0/../../../../i386-unknown-linux/lib" // CHECK-LD-32: "-L[[SYSROOT]]/usr/lib/gcc/i386-unknown-linux/4.6.0/../../.." diff --git a/clang/test/Driver/fsanitize.c b/clang/test/Driver/fsanitize.c -index 7340bfb35e4..681bb90b50e 100644 +index 8926d55a0cf4..40f628ccae45 100644 --- a/clang/test/Driver/fsanitize.c +++ b/clang/test/Driver/fsanitize.c -@@ -329,15 +329,15 @@ +@@ -330,15 +330,15 @@ // RUN: %clang -target x86_64-linux-gnu -fsanitize=vptr -fno-sanitize=vptr -fsanitize=undefined,address %s -### 2>&1 // OK @@ -154,7 +162,7 @@ // CHECK-NO-PIE-NOT: "-pie" // CHECK-NO-PIE: "-mrelocation-model" "static" -@@ -662,12 +662,12 @@ +@@ -667,12 +667,12 @@ // RUN: %clang -fno-sanitize=safe-stack -### %s 2>&1 | FileCheck %s -check-prefix=NOSP // NOSP-NOT: "-fsanitize=safe-stack" @@ -171,7 +179,7 @@ // NO-SP-NOT: stack-protector // NO-SP: "-fsanitize=safe-stack" diff --git a/clang/test/Driver/gcc-toolchain.cpp b/clang/test/Driver/gcc-toolchain.cpp -index 6c872f4255c..f5006d1dd9a 100644 +index 6c872f4255c3..f5006d1dd9ab 100644 --- a/clang/test/Driver/gcc-toolchain.cpp +++ b/clang/test/Driver/gcc-toolchain.cpp @@ -26,6 +26,6 @@ @@ -183,7 +191,7 @@ // CHECK: "-L[[TOOLCHAIN]]/usr/lib/i386-linux-gnu/gcc/i686-linux-gnu/4.5" // CHECK: "-L[[TOOLCHAIN]]/usr/lib/i386-linux-gnu/gcc/i686-linux-gnu/4.5/../../../.." diff --git a/clang/test/Driver/hexagon-toolchain-elf.c b/clang/test/Driver/hexagon-toolchain-elf.c -index cc11f9fcba9..1fe8b5db587 100644 +index cc11f9fcba9e..1fe8b5db587b 100644 --- a/clang/test/Driver/hexagon-toolchain-elf.c +++ b/clang/test/Driver/hexagon-toolchain-elf.c @@ -487,7 +487,7 @@ @@ -195,8 +203,26 @@ // CHECK042: "-mllvm" "-hexagon-small-data-threshold=8" // CHECK042-NEXT: llvm-mc // CHECK042: "-gpsize=8" +diff --git a/clang/test/Driver/hip-fpie-option.hip b/clang/test/Driver/hip-fpie-option.hip +index 2e296a099dea..86915f1c8c25 100644 +--- a/clang/test/Driver/hip-fpie-option.hip ++++ b/clang/test/Driver/hip-fpie-option.hip +@@ -5,11 +5,11 @@ + + // RUN: %clang -### -target x86_64-unknown-linux-gnu \ + // RUN: --offload-arch=gfx906 %s -nogpulib -nogpuinc \ +-// RUN: 2>&1 | FileCheck -check-prefixes=DEV,HOST-STATIC %s ++// RUN: 2>&1 | FileCheck -check-prefixes=DEV,HOST-PIE %s + + // RUN: %clang -### -target x86_64-unknown-linux-gnu \ + // RUN: -fgpu-rdc --offload-arch=gfx906 %s -nogpulib -nogpuinc \ +-// RUN: 2>&1 | FileCheck -check-prefixes=DEV,HOST-STATIC %s ++// RUN: 2>&1 | FileCheck -check-prefixes=DEV,HOST-PIE %s + + // RUN: %clang -### -target x86_64-unknown-linux-gnu \ + // RUN: --offload-arch=gfx906 %s -nogpulib -nogpuinc \ diff --git a/clang/test/Driver/linux-as.c b/clang/test/Driver/linux-as.c -index 0959bd7ba0a..4056a672b6f 100644 +index 0959bd7ba0a1..4056a672b6f9 100644 --- a/clang/test/Driver/linux-as.c +++ b/clang/test/Driver/linux-as.c @@ -164,7 +164,7 @@ @@ -218,7 +244,7 @@ // CHECK-SPARCV9PIC: as // CHECK-SPARCV9PIC: -64 diff --git a/clang/test/Driver/linux-ld.c b/clang/test/Driver/linux-ld.c -index ec539522c25..caf96020a15 100644 +index 24d3c78643f8..9ea22e6e0f64 100644 --- a/clang/test/Driver/linux-ld.c +++ b/clang/test/Driver/linux-ld.c @@ -1,3 +1,5 @@ @@ -228,10 +254,10 @@ // sysroot to make these tests independent of the host system. // diff --git a/clang/test/Driver/ppc-abi.c b/clang/test/Driver/ppc-abi.c -index aef8d8576ad..ec595f4cd96 100644 +index a74a19953ca2..0452661ba5a7 100644 --- a/clang/test/Driver/ppc-abi.c +++ b/clang/test/Driver/ppc-abi.c -@@ -1,9 +1,9 @@ +@@ -1,20 +1,20 @@ // Check passing PowerPC ABI options to the backend. // RUN: %clang -target powerpc64-unknown-linux-gnu %s -### -o %t.o 2>&1 \ @@ -241,22 +267,25 @@ -// RUN: -mabi=elfv1 | FileCheck -check-prefix=CHECK-ELFv1 %s +// RUN: -mabi=elfv1 | FileCheck -check-prefix=CHECK-ELFv1-PIE %s // RUN: %clang -target powerpc64-unknown-linux-gnu %s -### -o %t.o 2>&1 \ - // RUN: -mabi=elfv1-qpx | FileCheck -check-prefix=CHECK-ELFv1-QPX %s - // RUN: %clang -target powerpc64-unknown-linux-gnu %s -### -o %t.o 2>&1 \ -@@ -11,9 +11,9 @@ - // RUN: %clang -target powerpc64-unknown-linux-gnu %s -### -o %t.o 2>&1 \ - // RUN: -mcpu=a2 -mqpx | FileCheck -check-prefix=CHECK-ELFv1-QPX %s - // RUN: %clang -target powerpc64-unknown-linux-gnu %s -### -o %t.o 2>&1 \ --// RUN: -mcpu=a2q -mno-qpx | FileCheck -check-prefix=CHECK-ELFv1 %s -+// RUN: -mcpu=a2q -mno-qpx | FileCheck -check-prefix=CHECK-ELFv1-PIE %s - // RUN: %clang -target powerpc64-unknown-linux-gnu %s -### -o %t.o 2>&1 \ -// RUN: -mabi=elfv2 | FileCheck -check-prefix=CHECK-ELFv2-BE %s +// RUN: -mabi=elfv2 | FileCheck -check-prefix=CHECK-ELFv2-BE-PIE %s // RUN: %clang -target powerpc64le-unknown-linux-gnu %s -### -o %t.o 2>&1 \ - // RUN: | FileCheck -check-prefix=CHECK-ELFv2 %s -@@ -33,11 +33,13 @@ +-// RUN: | FileCheck -check-prefix=CHECK-ELFv2 %s ++// RUN: | FileCheck -check-prefix=CHECK-ELFv2-PIE %s + // RUN: %clang -target powerpc64le-unknown-linux-gnu %s -### -o %t.o 2>&1 \ + // RUN: -mabi=elfv1 | FileCheck -check-prefix=CHECK-ELFv1-LE %s + // RUN: %clang -target powerpc64le-unknown-linux-gnu %s -### -o %t.o 2>&1 \ +-// RUN: -mabi=elfv2 | FileCheck -check-prefix=CHECK-ELFv2 %s ++// RUN: -mabi=elfv2 | FileCheck -check-prefix=CHECK-ELFv2-PIE %s + // RUN: %clang -target powerpc64le-unknown-linux-gnu %s -### -o %t.o 2>&1 \ +-// RUN: -mabi=altivec | FileCheck -check-prefix=CHECK-ELFv2 %s ++// RUN: -mabi=altivec | FileCheck -check-prefix=CHECK-ELFv2-PIE %s + // RUN: %clang -target powerpc64-unknown-freebsd11 %s -### 2>&1 | FileCheck --check-prefix=CHECK-ELFv1 %s + // RUN: %clang -target powerpc64-unknown-freebsd12 %s -### 2>&1 | FileCheck --check-prefix=CHECK-ELFv1 %s +@@ -26,10 +26,14 @@ + // CHECK-ELFv1: "-mrelocation-model" "static" // CHECK-ELFv1: "-target-abi" "elfv1" -// CHECK-ELFv1-LE: "-mrelocation-model" "static" @@ -264,19 +293,18 @@ +// CHECK-ELFv1-PIE: "-target-abi" "elfv1" +// CHECK-ELFv1-LE: "-mrelocation-model" "pic" "-pic-level" "2" // CHECK-ELFv1-LE: "-target-abi" "elfv1" --// CHECK-ELFv1-QPX: "-mrelocation-model" "static" -+// CHECK-ELFv1-QPX: "-mrelocation-model" "pic" "-pic-level" "2" - // CHECK-ELFv1-QPX: "-target-abi" "elfv1-qpx" --// CHECK-ELFv2: "-mrelocation-model" "static" -+// CHECK-ELFv2: "-mrelocation-model" "pic" "-pic-level" "2" + // CHECK-ELFv2: "-mrelocation-model" "static" // CHECK-ELFv2: "-target-abi" "elfv2" ++// CHECK-ELFv2-PIE: "-mrelocation-model" "pic" "-pic-level" "2" ++// CHECK-ELFv2-PIE: "-target-abi" "elfv2" // CHECK-ELFv2-BE: "-mrelocation-model" "static" // CHECK-ELFv2-BE: "-target-abi" "elfv2" + // CHECK-ELFv2-BE-PIE: "-mrelocation-model" "pic" "-pic-level" "2" "-pic-is-pie" diff --git a/clang/test/Driver/riscv32-toolchain.c b/clang/test/Driver/riscv32-toolchain.c -index b83c9aafcbf..15b6f6496b2 100644 +index a5852f5f3997..233d9ef003cf 100644 --- a/clang/test/Driver/riscv32-toolchain.c +++ b/clang/test/Driver/riscv32-toolchain.c -@@ -81,7 +81,7 @@ +@@ -84,7 +84,7 @@ // C-RV32-LINUX-MULTI-ILP32: "--sysroot={{.*}}/Inputs/multilib_riscv_linux_sdk/sysroot" // C-RV32-LINUX-MULTI-ILP32: "-m" "elf32lriscv" // C-RV32-LINUX-MULTI-ILP32: "-dynamic-linker" "/lib/ld-linux-riscv32-ilp32.so.1" @@ -285,7 +313,7 @@ // C-RV32-LINUX-MULTI-ILP32: "-L{{.*}}/Inputs/multilib_riscv_linux_sdk/lib/gcc/riscv64-unknown-linux-gnu/7.2.0/lib32/ilp32" // C-RV32-LINUX-MULTI-ILP32: "-L{{.*}}/Inputs/multilib_riscv_linux_sdk/sysroot/lib32/ilp32" // C-RV32-LINUX-MULTI-ILP32: "-L{{.*}}/Inputs/multilib_riscv_linux_sdk/sysroot/usr/lib32/ilp32" -@@ -96,7 +96,7 @@ +@@ -99,7 +99,7 @@ // C-RV32-LINUX-MULTI-ILP32D: "--sysroot={{.*}}/Inputs/multilib_riscv_linux_sdk/sysroot" // C-RV32-LINUX-MULTI-ILP32D: "-m" "elf32lriscv" // C-RV32-LINUX-MULTI-ILP32D: "-dynamic-linker" "/lib/ld-linux-riscv32-ilp32d.so.1" @@ -295,10 +323,10 @@ // C-RV32-LINUX-MULTI-ILP32D: "-L{{.*}}/Inputs/multilib_riscv_linux_sdk/sysroot/lib32/ilp32d" // C-RV32-LINUX-MULTI-ILP32D: "-L{{.*}}/Inputs/multilib_riscv_linux_sdk/sysroot/usr/lib32/ilp32d" diff --git a/clang/test/Driver/riscv64-toolchain.c b/clang/test/Driver/riscv64-toolchain.c -index 5df069eb9fd..2617551ec35 100644 +index e727f20bb601..a801e5eee462 100644 --- a/clang/test/Driver/riscv64-toolchain.c +++ b/clang/test/Driver/riscv64-toolchain.c -@@ -81,7 +81,7 @@ +@@ -84,7 +84,7 @@ // C-RV64-LINUX-MULTI-LP64: "--sysroot={{.*}}/Inputs/multilib_riscv_linux_sdk/sysroot" // C-RV64-LINUX-MULTI-LP64: "-m" "elf64lriscv" // C-RV64-LINUX-MULTI-LP64: "-dynamic-linker" "/lib/ld-linux-riscv64-lp64.so.1" @@ -307,7 +335,7 @@ // C-RV64-LINUX-MULTI-LP64: "-L{{.*}}/Inputs/multilib_riscv_linux_sdk/lib/gcc/riscv64-unknown-linux-gnu/7.2.0/lib64/lp64" // C-RV64-LINUX-MULTI-LP64: "-L{{.*}}/Inputs/multilib_riscv_linux_sdk/sysroot/lib64/lp64" // C-RV64-LINUX-MULTI-LP64: "-L{{.*}}/Inputs/multilib_riscv_linux_sdk/sysroot/usr/lib64/lp64" -@@ -96,7 +96,7 @@ +@@ -99,7 +99,7 @@ // C-RV64-LINUX-MULTI-LP64D: "--sysroot={{.*}}/Inputs/multilib_riscv_linux_sdk/sysroot" // C-RV64-LINUX-MULTI-LP64D: "-m" "elf64lriscv" // C-RV64-LINUX-MULTI-LP64D: "-dynamic-linker" "/lib/ld-linux-riscv64-lp64d.so.1" @@ -317,7 +345,7 @@ // C-RV64-LINUX-MULTI-LP64D: "-L{{.*}}/Inputs/multilib_riscv_linux_sdk/sysroot/lib64/lp64d" // C-RV64-LINUX-MULTI-LP64D: "-L{{.*}}/Inputs/multilib_riscv_linux_sdk/sysroot/usr/lib64/lp64d" diff --git a/clang/test/Driver/stack-protector.c b/clang/test/Driver/stack-protector.c -index a3e40b50eed..dfffe0d6cf8 100644 +index a3e40b50eed8..dfffe0d6cf85 100644 --- a/clang/test/Driver/stack-protector.c +++ b/clang/test/Driver/stack-protector.c @@ -3,11 +3,11 @@ Added: opencl-respect-calling-convention-for-builtin.patch =================================================================== --- opencl-respect-calling-convention-for-builtin.patch (rev 0) +++ opencl-respect-calling-convention-for-builtin.patch 2021-05-27 04:32:42 UTC (rev 948006) @@ -0,0 +1,107 @@ +From e0fe1c58acfa0bde36afde8354cb31fc1e0b75e2 Mon Sep 17 00:00:00 2001 +From: Luke Drummond <[email protected]> +Date: Wed, 10 Mar 2021 18:14:42 +0000 +Subject: [PATCH] [OpenCL] Respect calling convention for builtin + +`__translate_sampler_initializer` has a calling convention of +`spir_func`, but clang generated calls to it using the default CC. + +Instruction Combining was lowering these mismatching calling conventions +to `store i1* undef` which itself was subsequently lowered to a trap +instruction by simplifyCFG resulting in runtime `SIGILL` + +There are arguably two bugs here: but whether there's any wisdom in +converting an obviously invalid call into a runtime crash over aborting +with a sensible error message will require further discussion. So for +now it's enough to set the right calling convention on the runtime +helper. + +Reviewed By: svenh, bader + +Differential Revision: https://reviews.llvm.org/D98411 + +(cherry picked from commit fcfd3fda71905d7c48f75a531c2265ad3b9876ea) +--- + clang/lib/CodeGen/CodeGenModule.cpp | 12 +++++++----- + clang/test/CodeGenOpenCL/sampler.cl | 12 ++++++------ + 2 files changed, 13 insertions(+), 11 deletions(-) + +diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp +index 31afbc6b4262..9c9bd4e374af 100644 +--- a/clang/lib/CodeGen/CodeGenModule.cpp ++++ b/clang/lib/CodeGen/CodeGenModule.cpp +@@ -6215,15 +6215,17 @@ llvm::SanitizerStatReport &CodeGenModule::getSanStats() { + + return *SanStats; + } ++ + llvm::Value * + CodeGenModule::createOpenCLIntToSamplerConversion(const Expr *E, + CodeGenFunction &CGF) { + llvm::Constant *C = ConstantEmitter(CGF).emitAbstract(E, E->getType()); +- auto SamplerT = getOpenCLRuntime().getSamplerType(E->getType().getTypePtr()); +- auto FTy = llvm::FunctionType::get(SamplerT, {C->getType()}, false); +- return CGF.Builder.CreateCall(CreateRuntimeFunction(FTy, +- "__translate_sampler_initializer"), +- {C}); ++ auto *SamplerT = getOpenCLRuntime().getSamplerType(E->getType().getTypePtr()); ++ auto *FTy = llvm::FunctionType::get(SamplerT, {C->getType()}, false); ++ auto *Call = CGF.Builder.CreateCall( ++ CreateRuntimeFunction(FTy, "__translate_sampler_initializer"), {C}); ++ Call->setCallingConv(Call->getCalledFunction()->getCallingConv()); ++ return Call; + } + + CharUnits CodeGenModule::getNaturalPointeeTypeAlignment( +diff --git a/clang/test/CodeGenOpenCL/sampler.cl b/clang/test/CodeGenOpenCL/sampler.cl +index e6bda49f51c8..5ad8d0dbbf37 100644 +--- a/clang/test/CodeGenOpenCL/sampler.cl ++++ b/clang/test/CodeGenOpenCL/sampler.cl +@@ -39,7 +39,7 @@ kernel void foo(sampler_t smp_par) { + // Case 2b + sampler_t smp = CLK_ADDRESS_CLAMP_TO_EDGE | CLK_NORMALIZED_COORDS_TRUE | CLK_FILTER_NEAREST; + // CHECK: [[smp_ptr:%[A-Za-z0-9_\.]+]] = alloca %opencl.sampler_t addrspace(2)* +- // CHECK: [[SAMP:%[0-9]+]] = call %opencl.sampler_t addrspace(2)* @__translate_sampler_initializer(i32 19) ++ // CHECK: [[SAMP:%[0-9]+]] = call spir_func %opencl.sampler_t addrspace(2)* @__translate_sampler_initializer(i32 19) + // CHECK: store %opencl.sampler_t addrspace(2)* [[SAMP]], %opencl.sampler_t addrspace(2)** [[smp_ptr]] + + // Case 1b +@@ -56,12 +56,12 @@ kernel void foo(sampler_t smp_par) { + + // Case 1a/2a + fnc4smp(glb_smp); +- // CHECK: [[SAMP:%[0-9]+]] = call %opencl.sampler_t addrspace(2)* @__translate_sampler_initializer(i32 35) ++ // CHECK: [[SAMP:%[0-9]+]] = call spir_func %opencl.sampler_t addrspace(2)* @__translate_sampler_initializer(i32 35) + // CHECK: call spir_func void [[FUNCNAME]](%opencl.sampler_t addrspace(2)* [[SAMP]]) + + // Case 1a/2c + fnc4smp(glb_smp_const); +- // CHECK: [[SAMP:%[0-9]+]] = call %opencl.sampler_t addrspace(2)* @__translate_sampler_initializer(i32 35) ++ // CHECK: [[SAMP:%[0-9]+]] = call spir_func %opencl.sampler_t addrspace(2)* @__translate_sampler_initializer(i32 35) + // CHECK: call spir_func void [[FUNCNAME]](%opencl.sampler_t addrspace(2)* [[SAMP]]) + + // Case 1c +@@ -70,12 +70,12 @@ kernel void foo(sampler_t smp_par) { + // CHECK: call spir_func void [[FUNCNAME]](%opencl.sampler_t addrspace(2)* [[SAMP]]) + + fnc4smp(5); +- // CHECK: [[SAMP:%[0-9]+]] = call %opencl.sampler_t addrspace(2)* @__translate_sampler_initializer(i32 5) ++ // CHECK: [[SAMP:%[0-9]+]] = call spir_func %opencl.sampler_t addrspace(2)* @__translate_sampler_initializer(i32 5) + // CHECK: call spir_func void [[FUNCNAME]](%opencl.sampler_t addrspace(2)* [[SAMP]]) + + const sampler_t const_smp = CLK_ADDRESS_CLAMP_TO_EDGE | CLK_NORMALIZED_COORDS_TRUE | CLK_FILTER_LINEAR; + fnc4smp(const_smp); +- // CHECK: [[CONST_SAMP:%[0-9]+]] = call %opencl.sampler_t addrspace(2)* @__translate_sampler_initializer(i32 35) ++ // CHECK: [[CONST_SAMP:%[0-9]+]] = call spir_func %opencl.sampler_t addrspace(2)* @__translate_sampler_initializer(i32 35) + // CHECK: store %opencl.sampler_t addrspace(2)* [[CONST_SAMP]], %opencl.sampler_t addrspace(2)** [[CONST_SMP_PTR:%[a-zA-Z0-9]+]] + fnc4smp(const_smp); + // CHECK: [[SAMP:%[0-9]+]] = load %opencl.sampler_t addrspace(2)*, %opencl.sampler_t addrspace(2)** [[CONST_SMP_PTR]] +@@ -83,7 +83,7 @@ kernel void foo(sampler_t smp_par) { + + constant sampler_t constant_smp = CLK_ADDRESS_CLAMP_TO_EDGE | CLK_NORMALIZED_COORDS_TRUE | CLK_FILTER_LINEAR; + fnc4smp(constant_smp); +- // CHECK: [[SAMP:%[0-9]+]] = call %opencl.sampler_t addrspace(2)* @__translate_sampler_initializer(i32 35) ++ // CHECK: [[SAMP:%[0-9]+]] = call spir_func %opencl.sampler_t addrspace(2)* @__translate_sampler_initializer(i32 35) + // CHECK: call spir_func void [[FUNCNAME]](%opencl.sampler_t addrspace(2)* [[SAMP]]) + + // TODO: enable sampler initialization with non-constant integer.
