diff -pruN 3.0-4/debian/changelog 3.0-6/debian/changelog
--- 3.0-4/debian/changelog	2022-06-21 18:47:34.000000000 +0000
+++ 3.0-6/debian/changelog	2022-08-03 23:54:01.000000000 +0000
@@ -1,3 +1,18 @@
+pocl (3.0-6) unstable; urgency=medium
+
+  * Update symbols file.
+
+ -- Andreas Beckmann <anbe@debian.org>  Thu, 04 Aug 2022 01:54:01 +0200
+
+pocl (3.0-5) unstable; urgency=medium
+
+  * Rebuild with GCC 12.  (Closes: #1016294)
+  * Add some patches to use -latomic if needed.
+  * Drop redundant pie flags to make blhc happy.
+  * Update symbols file for amd64 and i386.
+
+ -- Andreas Beckmann <anbe@debian.org>  Wed, 03 Aug 2022 07:26:39 +0200
+
 pocl (3.0-4) unstable; urgency=medium
 
   * Switch to llvm 13.  (Closes: #1001317)
@@ -325,7 +340,7 @@ pocl (1.3-4) unstable; urgency=medium
 
 pocl (1.3-3) unstable; urgency=medium
 
-  * Rebuild with gcc 9.
+  * Rebuild with GCC 9.
   * Update symbols files for amd64 and i386.
 
  -- Andreas Beckmann <anbe@debian.org>  Sat, 24 Aug 2019 07:37:21 +0200
diff -pruN 3.0-4/debian/control 3.0-6/debian/control
--- 3.0-4/debian/control	2022-06-21 18:47:34.000000000 +0000
+++ 3.0-6/debian/control	2022-08-03 23:54:01.000000000 +0000
@@ -6,6 +6,7 @@ Uploaders: Vincent Danjean <vdanjean@deb
  Andreas Beckmann <anbe@debian.org>,
 Build-Depends:
  debhelper-compat (= 13),
+ gcc (>= 4:12),
  clang-13,
  libclang-13-dev,
  libclang-cpp13-dev,
diff -pruN 3.0-4/debian/libpocl2.symbols 3.0-6/debian/libpocl2.symbols
--- 3.0-4/debian/libpocl2.symbols	2022-06-21 18:47:34.000000000 +0000
+++ 3.0-6/debian/libpocl2.symbols	2022-08-03 23:54:01.000000000 +0000
@@ -1,4 +1,4 @@
-# SymbolsHelper-Confirmed: 3.0 amd64 arm64 armel armhf hurd-i386 i386 mips64el mipsel powerpc ppc64 ppc64el riscv64 s390x sparc64
+# SymbolsHelper-Confirmed: 3.0-5~gcc12 amd64 arm64 armel armhf hurd-i386 i386 mips64el mipsel ppc64 ppc64el s390x
 libpocl-devices-basic.so #PACKAGE# #MINVER#
 * Build-Depends-Package: libpocl-dev
  pocl_basic_init_device_ops@Base 1.6
@@ -90,8 +90,10 @@ libpocl.so.2 #PACKAGE# #MINVER#
  (arch=armel riscv64)_ZTSSt16_Sp_counted_baseILN9__gnu_cxx12_Lock_policyE1EE@Base 0.10
  (arch=!armel !riscv64)_ZTSSt16_Sp_counted_baseILN9__gnu_cxx12_Lock_policyE2EE@Base 0.10
  _ZTSSt19_Sp_make_shared_tag@Base 0.10
- (arch=armel riscv64)_ZTSSt23_Sp_counted_ptr_inplaceINSt8__detail4_NFAINSt7__cxx1112regex_traitsIcEEEESaIS5_ELN9__gnu_cxx12_Lock_policyE1EE@Base 3.0
- (arch=!armel !riscv64)_ZTSSt23_Sp_counted_ptr_inplaceINSt8__detail4_NFAINSt7__cxx1112regex_traitsIcEEEESaIS5_ELN9__gnu_cxx12_Lock_policyE2EE@Base 3.0
+#MISSING: 3.0-5~gcc12# (arch=armel riscv64)_ZTSSt23_Sp_counted_ptr_inplaceINSt8__detail4_NFAINSt7__cxx1112regex_traitsIcEEEESaIS5_ELN9__gnu_cxx12_Lock_policyE1EE@Base 3.0
+#MISSING: 3.0-5~gcc12# (arch=!armel !riscv64)_ZTSSt23_Sp_counted_ptr_inplaceINSt8__detail4_NFAINSt7__cxx1112regex_traitsIcEEEESaIS5_ELN9__gnu_cxx12_Lock_policyE2EE@Base 3.0
+ (arch=armel)_ZTSSt23_Sp_counted_ptr_inplaceINSt8__detail4_NFAINSt7__cxx1112regex_traitsIcEEEESaIvELN9__gnu_cxx12_Lock_policyE1EE@Base 3.0-5~gcc12
+ (arch=!armel !riscv64)_ZTSSt23_Sp_counted_ptr_inplaceINSt8__detail4_NFAINSt7__cxx1112regex_traitsIcEEEESaIvELN9__gnu_cxx12_Lock_policyE2EE@Base 3.0-5~gcc12
  (optional=templinst)_ZZNKSt7__cxx1112regex_traitsIcE16lookup_classnameIPKcEENS1_10_RegexMaskET_S6_bE12__classnames@Base 3.0
  (optional=templinst)_ZZNKSt7__cxx1112regex_traitsIcE18lookup_collatenameIPKcEENS_12basic_stringIcSt11char_traitsIcESaIcEEET_SA_E14__collatenames@Base 3.0
  (optional=templinst)_ZZNKSt8__detail11_AnyMatcherINSt7__cxx1112regex_traitsIcEELb0ELb0ELb0EEclEcE5__nul@Base 3.0
diff -pruN 3.0-4/debian/patches/1018-drop-unused-POCL_ATOMIC_CAS.patch 3.0-6/debian/patches/1018-drop-unused-POCL_ATOMIC_CAS.patch
--- 3.0-4/debian/patches/1018-drop-unused-POCL_ATOMIC_CAS.patch	1970-01-01 00:00:00.000000000 +0000
+++ 3.0-6/debian/patches/1018-drop-unused-POCL_ATOMIC_CAS.patch	2022-08-03 23:54:01.000000000 +0000
@@ -0,0 +1,31 @@
+From 98d848b03d082401d37ece778652b9f78a511e33 Mon Sep 17 00:00:00 2001
+From: Andreas Beckmann <anbe@debian.org>
+Date: Mon, 27 Jun 2022 13:49:53 +0200
+Subject: [PATCH 1/3] drop unused POCL_ATOMIC_CAS
+
+---
+ lib/CL/pocl_cl.h | 4 ----
+ 1 file changed, 4 deletions(-)
+
+diff --git a/lib/CL/pocl_cl.h b/lib/CL/pocl_cl.h
+index 461009b0..0d8ce769 100644
+--- a/lib/CL/pocl_cl.h
++++ b/lib/CL/pocl_cl.h
+@@ -80,14 +80,10 @@ typedef pthread_t pocl_thread_t;
+ /* See: https://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/Atomic-Builtins.html */
+ #define POCL_ATOMIC_INC(x) __sync_add_and_fetch (&x, 1)
+ #define POCL_ATOMIC_DEC(x) __sync_sub_and_fetch (&x, 1)
+-#define POCL_ATOMIC_CAS(ptr, oldval, newval)                                  \
+-  __sync_val_compare_and_swap (ptr, oldval, newval)
+ 
+ #elif defined(_WIN32)
+ #define POCL_ATOMIC_INC(x) InterlockedIncrement64 (&x)
+ #define POCL_ATOMIC_DEC(x) InterlockedDecrement64 (&x)
+-#define POCL_ATOMIC_CAS(ptr, oldval, newval)                                  \
+-  InterlockedCompareExchange64 (ptr, newval, oldval)
+ #else
+ #error Need atomic_inc() builtin for this compiler
+ #endif
+-- 
+2.20.1
+
diff -pruN 3.0-4/debian/patches/1019-switch-from-__sync_add_and_fetch-to-__atomic_add_fet.patch 3.0-6/debian/patches/1019-switch-from-__sync_add_and_fetch-to-__atomic_add_fet.patch
--- 3.0-4/debian/patches/1019-switch-from-__sync_add_and_fetch-to-__atomic_add_fet.patch	1970-01-01 00:00:00.000000000 +0000
+++ 3.0-6/debian/patches/1019-switch-from-__sync_add_and_fetch-to-__atomic_add_fet.patch	2022-08-03 23:54:01.000000000 +0000
@@ -0,0 +1,29 @@
+From 84bb6978ff4bdb298b109004d927e80a5dabf04a Mon Sep 17 00:00:00 2001
+From: Andreas Beckmann <anbe@debian.org>
+Date: Mon, 27 Jun 2022 13:55:15 +0200
+Subject: [PATCH 2/3] switch from __sync_add_and_fetch to __atomic_add_fetch
+
+---
+ lib/CL/pocl_cl.h | 6 +++---
+ 1 file changed, 3 insertions(+), 3 deletions(-)
+
+diff --git a/lib/CL/pocl_cl.h b/lib/CL/pocl_cl.h
+index 0d8ce769..20119b51 100644
+--- a/lib/CL/pocl_cl.h
++++ b/lib/CL/pocl_cl.h
+@@ -77,9 +77,9 @@ typedef pthread_t pocl_thread_t;
+ #if defined(__GNUC__) || defined(__clang__)
+ 
+ /* These return the new value. */
+-/* See: https://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/Atomic-Builtins.html */
+-#define POCL_ATOMIC_INC(x) __sync_add_and_fetch (&x, 1)
+-#define POCL_ATOMIC_DEC(x) __sync_sub_and_fetch (&x, 1)
++/* See: https://gcc.gnu.org/onlinedocs/gcc-4.7.4/gcc/_005f_005fatomic-Builtins.html */
++#define POCL_ATOMIC_INC(x) __atomic_add_fetch (&x, 1, __ATOMIC_SEQ_CST)
++#define POCL_ATOMIC_DEC(x) __atomic_sub_fetch (&x, 1, __ATOMIC_SEQ_CST)
+ 
+ #elif defined(_WIN32)
+ #define POCL_ATOMIC_INC(x) InterlockedIncrement64 (&x)
+-- 
+2.20.1
+
diff -pruN 3.0-4/debian/patches/1020-check-whether-64bit-atomics-require-latomic.patch 3.0-6/debian/patches/1020-check-whether-64bit-atomics-require-latomic.patch
--- 3.0-4/debian/patches/1020-check-whether-64bit-atomics-require-latomic.patch	1970-01-01 00:00:00.000000000 +0000
+++ 3.0-6/debian/patches/1020-check-whether-64bit-atomics-require-latomic.patch	2022-08-03 23:54:01.000000000 +0000
@@ -0,0 +1,70 @@
+From a22d8c2321f42c3ad7235b60800895bae26d9566 Mon Sep 17 00:00:00 2001
+From: Andreas Beckmann <anbe@debian.org>
+Date: Mon, 27 Jun 2022 14:04:28 +0200
+Subject: [PATCH 3/3] check whether 64bit atomics require -latomic
+
+---
+ CMakeLists.txt        | 31 +++++++++++++++++++++++++++++++
+ lib/CL/CMakeLists.txt |  4 ++++
+ 2 files changed, 35 insertions(+)
+
+diff --git a/CMakeLists.txt b/CMakeLists.txt
+index 96ace837..0d71ea02 100644
+--- a/CMakeLists.txt
++++ b/CMakeLists.txt
+@@ -646,6 +646,37 @@ endif()
+ 
+ ######################################################################################
+ 
++function(check_64bit_atomics varname)
++    check_c_source_compiles("
++#include <stdint.h>
++uint64_t x = 0;
++int main()
++{
++  __atomic_add_fetch(&x, 1, __ATOMIC_SEQ_CST);
++  __atomic_sub_fetch(&x, 1, __ATOMIC_SEQ_CST);
++  return x;
++}
++" ${varname})
++endfunction(check_64bit_atomics)
++
++# platforms w/o lockfree 64bit atomics need to link with -latomic
++if(UNIX)
++    check_64bit_atomics(HAVE_64BIT_ATOMICS_WITHOUT_LIB)
++    if(HAVE_64BIT_ATOMICS_WITHOUT_LIB)
++        set(HAVE_64BIT_ATOMICS_WITH_LIB FALSE)
++    else()
++        set(OLD_CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
++        list(APPEND CMAKE_REQUIRED_LIBRARIES "atomic")
++        check_64bit_atomics(HAVE_64BIT_ATOMICS_WITH_LIB)
++        set(CMAKE_REQUIRED_LIBRARIES ${OLD_CMAKE_REQUIRED_LIBRARIES})
++        if(NOT HAVE_64BIT_ATOMICS_WITH_LIB)
++            message(SEND_ERROR "Missing 64-bit atomic increment")
++        endif()
++    endif()
++endif()
++
++######################################################################################
++
+ if(UNIX AND ENABLE_LLVM AND HAVE_DLADDR)
+     option(ENABLE_RELOCATION "make libpocl relocatable" ON)
+ else()
+diff --git a/lib/CL/CMakeLists.txt b/lib/CL/CMakeLists.txt
+index 342cdac4..ed573409 100644
+--- a/lib/CL/CMakeLists.txt
++++ b/lib/CL/CMakeLists.txt
+@@ -242,6 +242,10 @@ if(HAVE_CLOCK_GETTIME AND CMAKE_SYSTEM_NAME MATCHES "Linux")
+   list(APPEND POCL_PRIVATE_LINK_LIST "rt")
+ endif()
+ 
++if(HAVE_64BIT_ATOMICS_WITH_LIB)
++  list(APPEND POCL_PRIVATE_LINK_LIST "atomic")
++endif()
++
+ list(APPEND POCL_PRIVATE_LINK_LIST ${LIBMATH} ${CMAKE_DL_LIBS} ${PTHREAD_LIBRARY})
+ 
+ # see lib/CMakeLists.txt
+-- 
+2.20.1
+
diff -pruN 3.0-4/debian/patches/blhc.patch 3.0-6/debian/patches/blhc.patch
--- 3.0-4/debian/patches/blhc.patch	1970-01-01 00:00:00.000000000 +0000
+++ 3.0-6/debian/patches/blhc.patch	2022-08-03 23:54:01.000000000 +0000
@@ -0,0 +1,52 @@
+Author: Andreas Beckmann <anbe@debian.org>
+Description: drop redundant pie flags to make blhc happy
+ pie is enabled by default on Debian
+Forwarded: not-needed
+
+--- a/cmake/Hardening.cmake
++++ b/cmake/Hardening.cmake
+@@ -53,13 +53,13 @@ function(processFlagsList target propert
+ endfunction(processFlagsList)
+ 
+ function(setupPIC target)
+-	set_property(TARGET ${target} PROPERTY POSITION_INDEPENDENT_CODE ON) # bad, doesn't work
++	#set_property(TARGET ${target} PROPERTY POSITION_INDEPENDENT_CODE ON) # bad, doesn't work
+ 	if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
+ 		get_target_property(type ${target} TYPE)
+ 		if(type STREQUAL "EXECUTABLE")
+-			list(APPEND HARDENING_PIC_COMPILE_FLAGS
+-				"-fPIE"
+-			)
++			#list(APPEND HARDENING_PIC_COMPILE_FLAGS
++			#	"-fPIE"
++			#)
+ 		else()
+ 			list(APPEND HARDENING_PIC_COMPILE_FLAGS
+ 				"-fPIC"
+@@ -67,9 +67,9 @@ function(setupPIC target)
+ 		endif()
+ 		if(type STREQUAL "EXECUTABLE")
+ 			# https://mropert.github.io/2018/02/02/pic_pie_sanitizers/
+-			list(APPEND HARDENING_PIC_LINKER_FLAGS
+-				"-Wl,-pie"
+-			)
++			#list(APPEND HARDENING_PIC_LINKER_FLAGS
++			#	"-Wl,-pie"
++			#)
+ 			if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
+ 				message(STATUS "Working around Clang bug https://bugs.llvm.org/show_bug.cgi?id=44594 ...")
+ 				list(APPEND HARDENING_PIC_LINKER_FLAGS
+--- a/CMakeLists.txt
++++ b/CMakeLists.txt
+@@ -83,9 +83,9 @@ set(VERSION_STRING ${MAJOR_VERSION}.${MI
+ set(POCL_VERSION_BASE ${VERSION_STRING})
+ 
+ # required b/c SHARED libs defaults to ON while OBJECT defaults to OFF
+-set(CMAKE_POSITION_INDEPENDENT_CODE ON)
++#set(CMAKE_POSITION_INDEPENDENT_CODE ON)
+ # CMake doesn't add "-pie" by default for executables (CMake issue #14983)
+-set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pie")
++#set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pie")
+ 
+ enable_testing()
+ 
diff -pruN 3.0-4/debian/patches/distro.patch 3.0-6/debian/patches/distro.patch
--- 3.0-4/debian/patches/distro.patch	2022-06-21 18:47:34.000000000 +0000
+++ 3.0-6/debian/patches/distro.patch	2022-08-03 23:54:01.000000000 +0000
@@ -1,6 +1,6 @@
 Author: Andreas Beckmann <anbe@debian.org>
 Description: tune distro mode
-Forwarded: no-needed
+Forwarded: not-needed
 
 --- a/lib/kernel/host/CMakeLists.txt
 +++ b/lib/kernel/host/CMakeLists.txt
diff -pruN 3.0-4/debian/patches/no-rc.patch 3.0-6/debian/patches/no-rc.patch
--- 3.0-4/debian/patches/no-rc.patch	2022-06-21 18:47:34.000000000 +0000
+++ 3.0-6/debian/patches/no-rc.patch	2022-08-03 23:54:01.000000000 +0000
@@ -1,6 +1,6 @@
 Author: Andreas Beckmann <anbe@debian.org>
 Description: this is not a release candidate
-Forwarded: no-needed
+Forwarded: not-needed
 
 --- a/CMakeLists.txt
 +++ b/CMakeLists.txt
diff -pruN 3.0-4/debian/patches/series 3.0-6/debian/patches/series
--- 3.0-4/debian/patches/series	2022-06-21 18:47:34.000000000 +0000
+++ 3.0-6/debian/patches/series	2022-08-03 23:54:01.000000000 +0000
@@ -15,6 +15,9 @@
 1015-use-_LLC_HOST_CPU-as-internal-variable.patch
 1016-let-LLC_HOST_CPU-be-forced-HOST_CPU_FORCED-to-any-cp.patch
 1017-support-overriding-the-runtime-cpu-detection-with-PO.patch
+1018-drop-unused-POCL_ATOMIC_CAS.patch
+1019-switch-from-__sync_add_and_fetch-to-__atomic_add_fet.patch
+1020-check-whether-64bit-atomics-require-latomic.patch
 
 2002-link-against-single-shared-libclang-cpp-when-buildin.patch
 test_structs_as_args.patch
@@ -23,3 +26,4 @@ distro.patch
 timeout.patch
 no-rc.patch
 fix-opencl.hpp-detection.patch
+blhc.patch
