add secure complie option and code improve

Signed-off-by: zhongtao <zhongtao17@huawei.com>
(cherry picked from commit 3fb64f0af0727a03b3c67c2edd00bc69c58fca7c)
This commit is contained in:
zhongtao 2024-04-09 09:31:37 +08:00 committed by openeuler-sync-bot
parent 60c0b4b248
commit 536c47cfc7
3 changed files with 26 additions and 14 deletions

View File

@ -1,26 +1,27 @@
From bc32151458494ce41b4ccc0e0e87999ce27a15fc Mon Sep 17 00:00:00 2001 From 4cf6dc9f628fc2c5b3478d70e15d4fab8a32ae86 Mon Sep 17 00:00:00 2001
From: zhongtao <zhongtao17@huawei.com> From: zhongtao <zhongtao17@huawei.com>
Date: Wed, 10 Jan 2024 16:21:07 +0800 Date: Wed, 10 Apr 2024 11:43:51 +0800
Subject: [PATCH] add secure compile option Subject: [PATCH] add secure compile option
Signed-off-by: zhongtao <zhongtao17@huawei.com> Signed-off-by: zhongtao <zhongtao17@huawei.com>
--- ---
CMakeLists.txt | 2 ++ CMakeLists.txt | 3 +++
1 file changed, 2 insertions(+) 1 file changed, 3 insertions(+)
diff --git a/CMakeLists.txt b/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt
index 4137ce2..05ee303 100644 index 4137ce2..d17f09d 100644
--- a/CMakeLists.txt --- a/CMakeLists.txt
+++ b/CMakeLists.txt +++ b/CMakeLists.txt
@@ -2,6 +2,8 @@ @@ -2,6 +2,9 @@
# to 3.26. # to 3.26.
cmake_minimum_required(VERSION 3.10...3.26) cmake_minimum_required(VERSION 3.10...3.26)
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wl,-z,now -fstack-check") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wl,-z,now -fstack-check -fPIE")
+set(CMAKE_EXE_LINKER_FLAGS "-pie")
+ +
# Revert to old behavior for MSVC debug symbols. # Revert to old behavior for MSVC debug symbols.
if(POLICY CMP0141) if(POLICY CMP0141)
cmake_policy(SET CMP0141 OLD) cmake_policy(SET CMP0141 OLD)
-- --
2.43.0 2.25.1

View File

@ -7,7 +7,7 @@
Summary: Protocol Buffers - Google's data interchange format Summary: Protocol Buffers - Google's data interchange format
Name: protobuf Name: protobuf
Version: 25.1 Version: 25.1
Release: 2 Release: 3
License: BSD License: BSD
URL: https://github.com/protocolbuffers/protobuf URL: https://github.com/protocolbuffers/protobuf
Source: https://github.com/protocolbuffers/protobuf/releases/download/v%{version}%{?rcver}/%{name}-all-%{version}%{?rcver}.tar.gz Source: https://github.com/protocolbuffers/protobuf/releases/download/v%{version}%{?rcver}/%{name}-all-%{version}%{?rcver}.tar.gz
@ -15,7 +15,7 @@ Source1: protobuf-init.el
%global so_version 25.1 %global so_version 25.1
Patch9000: 0001-add-secure-compile-option.patch Patch9000: 0001-add-secure-compile-option.patch
Patch9001: 0001-Fix-CC-compiler-support.patch Patch9001: 0002-Fix-CC-compiler-support.patch
BuildRequires: cmake gcc-c++ emacs zlib-devel gmock-devel gtest-devel jsoncpp-devel BuildRequires: cmake gcc-c++ emacs zlib-devel gmock-devel gtest-devel jsoncpp-devel
BuildRequires: fdupes pkgconfig python-rpm-macros pkgconfig(zlib) ninja-build BuildRequires: fdupes pkgconfig python-rpm-macros pkgconfig(zlib) ninja-build
@ -233,8 +233,9 @@ pushd build
-DCMAKE_MODULE_LINKER_FLAGS=-Wl,--as-needed \ -DCMAKE_MODULE_LINKER_FLAGS=-Wl,--as-needed \
-DCMAKE_SHARED_LINKER_FLAGS=-Wl,--as-needed \ -DCMAKE_SHARED_LINKER_FLAGS=-Wl,--as-needed \
-DCMAKE_CXX_FLAGS="-g -O2" \ -DCMAKE_CXX_FLAGS="-g -O2" \
-DCMAKE_C_COMPILER=%{__cc} \ -DCMAKE_C_COMPILER=%{__cc} \
-DCMAKE_CXX_COMPILER=%{__cxx} \ -DCMAKE_CXX_COMPILER=%{__cxx} \
-DCMAKE_SKIP_RPATH=TRUE \
-G Ninja \ -G Ninja \
../ ../
popd popd
@ -250,8 +251,9 @@ export CMAKE_BUILD_DIR=build-static
-Dprotobuf_ABSL_PROVIDER=package \ -Dprotobuf_ABSL_PROVIDER=package \
-Dprotobuf_BUILD_TESTS:BOOL=OFF \ -Dprotobuf_BUILD_TESTS:BOOL=OFF \
-DCMAKE_CXX_FLAGS="-fPIC" \ -DCMAKE_CXX_FLAGS="-fPIC" \
-DCMAKE_C_COMPILER=%{__cc} \ -DCMAKE_C_COMPILER=%{__cc} \
-DCMAKE_CXX_COMPILER=%{__cxx} \ -DCMAKE_CXX_COMPILER=%{__cxx} \
-DCMAKE_SKIP_RPATH=TRUE \
-G Ninja \ -G Ninja \
../ ../
popd popd
@ -260,6 +262,9 @@ popd
%ninja_build -C build %ninja_build -C build
%ninja_build -C build-static %ninja_build -C build-static
# we have to override LD_LIBRARY_PATH because we eliminated rpath
export LD_LIBRARY_PATH="${PWD}/build":$LD_LIBRARY_PATH
%if %{with python} %if %{with python}
# Use the just built protoc instead of any # Use the just built protoc instead of any
# system version for python and/or java bindings # system version for python and/or java bindings
@ -392,6 +397,12 @@ install -p -m 0644 %{SOURCE1} %{buildroot}%{_emacs_sitestartdir}
%endif %endif
%changelog %changelog
* Tue Apr 09 2024 zhongtao <zhongtao17@huawei.com> - 25.1-3
- Type:bugfix
- ID:NA
- SUG:NA
- DESC: add secure complie option and code improve
* Wed Mar 20 2024 wangqiang <wangqiang1@kylinos.cn> - 25.1-2 * Wed Mar 20 2024 wangqiang <wangqiang1@kylinos.cn> - 25.1-2
- Support package build with clang - Support package build with clang