From 2cb0b2bae6ce3e19aeba32d416e89c86cfadd60d Mon Sep 17 00:00:00 2001
From: Thierry Escande <thierry.escande@huawei.com>
Date: Mon, 4 Jul 2022 10:36:10 +0200
Subject: [PATCH] prebuilts: Disable _FORTIFY_SOURCE for native libselinux
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This patch disables the macro _FORTIFY_SOURCE for libselinux native
compilation with gcc. This fixes the following error:
 "inlining failed in call to always_inline ‘syslog’: function body can be overwritten at link time".

Signed-off-by: Thierry Escande <thierry.escande@huawei.com>
---
 ...-openharmony-toolchain-integration-3.1.inc |  1 +
 .../patches/third_party_selinux.patch         | 29 +++++++++++++++++++
 2 files changed, 30 insertions(+)
 create mode 100644 recipes-openharmony/prebuilts/openharmony-3.1/patches/third_party_selinux.patch

diff --git a/recipes-openharmony/prebuilts/oniro-openharmony-toolchain-integration-3.1.inc b/recipes-openharmony/prebuilts/oniro-openharmony-toolchain-integration-3.1.inc
index e9883c24..de5b33a1 100644
--- a/recipes-openharmony/prebuilts/oniro-openharmony-toolchain-integration-3.1.inc
+++ b/recipes-openharmony/prebuilts/oniro-openharmony-toolchain-integration-3.1.inc
@@ -16,3 +16,4 @@ SRC_URI += "file://patches/productdefine_common.patch;apply=no;subdir=src"
 SRC_URI += "file://patches/third_party_libevdev.patch;apply=no;subdir=src"
 SRC_URI += "file://patches/third_party_libusb.patch;apply=no;subdir=src"
 SRC_URI += "file://patches/third_party_e2fsprogs-backports-to-3.1.patch;apply=no;subdir=src"
+SRC_URI += "file://patches/third_party_selinux.patch;apply=no;subdir=src"
diff --git a/recipes-openharmony/prebuilts/openharmony-3.1/patches/third_party_selinux.patch b/recipes-openharmony/prebuilts/openharmony-3.1/patches/third_party_selinux.patch
new file mode 100644
index 00000000..73085d39
--- /dev/null
+++ b/recipes-openharmony/prebuilts/openharmony-3.1/patches/third_party_selinux.patch
@@ -0,0 +1,29 @@
+# SPDX-FileCopyrightText: Huawei Inc.
+#
+# SPDX-License-Identifier: Apache-2.0
+
+Patch for //third_party/selinux git repository of OpenHarmony 3.1 codebase.
+
+This disables the _FORTIFY_SOURCE macro for native build with gcc.
+This fixes the following compiler error for libselinux:
+ "error: inlining failed in call to always_inline ‘syslog’: function body can be overwritten at link time"
+
+Signed-off-by: Thierry Escande <thierry.escande@huawei.com>
+Upstream-Status: Inappropriate
+
+diff --git a/third_party/selinux/BUILD.gn b/third_party/selinux/BUILD.gn
+index 34616600..a9ca7cf5 100644
+--- a/third_party/selinux/BUILD.gn
++++ b/third_party/selinux/BUILD.gn
+@@ -199,6 +199,11 @@ ohos_shared_library("libselinux") {
+     "-DAUDITD_LOG_TAG=1003",
+     "-DPCRE2_CODE_UNIT_WIDTH=8",
+   ]
++
++  if (!is_clang) {
++    cflags += [ "-U_FORTIFY_SOURCE" ]
++  }
++
+   deps = [
+     ":libsepol",
+     "$LIBPCRE2_ROOT_DIR:libpcre2",
-- 
GitLab