From 758fc8c063b185a0d296e2f38c53e5d059df16fb Mon Sep 17 00:00:00 2001 From: Itamar Date: Fri, 11 Dec 2020 15:44:08 +0200 Subject: [PATCH] Toolchain: Fix usage of libgcc_s & build PIE executables by default We can now build the porst with the shared libraries toolchain. --- CMakeLists.txt | 4 ++-- Ports/gcc/patches/gcc.patch | 2 +- Toolchain/BuildIt.sh | 1 + Toolchain/Patches/gcc.patch | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6ea5d54de3e..925382276b9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -233,8 +233,8 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Os -g1 -fno-exceptions -fno-rtti -Wno-a set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ffile-prefix-map=${CMAKE_SOURCE_DIR}=.") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DDEBUG -DSANITIZE_PTRS") -set(CMAKE_CXX_FLAGS_STATIC ${CMAKE_CXX_FLAGS}) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -nostartfiles -lgcc_s -pie -fpic") +set(CMAKE_CXX_FLAGS_STATIC "${CMAKE_CXX_FLAGS} -static") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -nostartfiles -pie -fpic") add_link_options(--sysroot ${CMAKE_BINARY_DIR}/Root) diff --git a/Ports/gcc/patches/gcc.patch b/Ports/gcc/patches/gcc.patch index 8ef1458f104..f06a160904f 100644 --- a/Ports/gcc/patches/gcc.patch +++ b/Ports/gcc/patches/gcc.patch @@ -128,7 +128,7 @@ index 000000000..2692b8e57 +#define ENDFILE_SPEC "%{shared|pie:crtendS.o%s; :crtend.o%s} crtn.o%s" + +#undef LINK_SPEC -+#define LINK_SPEC "%{shared:-shared} %{static:-static} %{!shared: %{!static: %{rdynamic:-export-dynamic} -dynamic-linker /usr/lib/Loader.so}}" ++#define LINK_SPEC "%{shared:-shared} %{static:-static} %{!static: %{rdynamic:-export-dynamic} %{!fbuilding-libgcc:-lgcc_s -dynamic-linker /usr/lib/Loader.so}}" + +/* Additional predefined macros. */ +#undef TARGET_OS_CPP_BUILTINS diff --git a/Toolchain/BuildIt.sh b/Toolchain/BuildIt.sh index 7b2a6b0aef1..568aac2b28d 100755 --- a/Toolchain/BuildIt.sh +++ b/Toolchain/BuildIt.sh @@ -224,6 +224,7 @@ pushd "$DIR/Build/" --with-newlib \ --enable-shared \ --enable-languages=c,c++ \ + --enable-default-pie \ ${TRY_USE_LOCAL_TOOLCHAIN:+"--quiet"} || exit 1 echo "XXX build gcc and libgcc" diff --git a/Toolchain/Patches/gcc.patch b/Toolchain/Patches/gcc.patch index 8ef1458f104..f06a160904f 100644 --- a/Toolchain/Patches/gcc.patch +++ b/Toolchain/Patches/gcc.patch @@ -128,7 +128,7 @@ index 000000000..2692b8e57 +#define ENDFILE_SPEC "%{shared|pie:crtendS.o%s; :crtend.o%s} crtn.o%s" + +#undef LINK_SPEC -+#define LINK_SPEC "%{shared:-shared} %{static:-static} %{!shared: %{!static: %{rdynamic:-export-dynamic} -dynamic-linker /usr/lib/Loader.so}}" ++#define LINK_SPEC "%{shared:-shared} %{static:-static} %{!static: %{rdynamic:-export-dynamic} %{!fbuilding-libgcc:-lgcc_s -dynamic-linker /usr/lib/Loader.so}}" + +/* Additional predefined macros. */ +#undef TARGET_OS_CPP_BUILTINS