pkgsrc-WIP-changes archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
zig-git: build with relro + pie fix from upstream
Module Name: pkgsrc-wip
Committed By: nikita <nikita%NetBSD.org@localhost>
Pushed By: nikita
Date: Tue May 2 10:43:49 2023 +0200
Changeset: 2ce1f0752538ff491dcb5850701e6e6d02810235
Modified Files:
zig-git/Makefile
Added Files:
zig-git/patches/patch-CMakeLists.txt
zig-git/patches/patch-src_link_Elf.zig
Log Message:
zig-git: build with relro + pie fix from upstream
To see a diff of this commit:
https://wip.pkgsrc.org/cgi-bin/gitweb.cgi?p=pkgsrc-wip.git;a=commitdiff;h=2ce1f0752538ff491dcb5850701e6e6d02810235
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
diffstat:
zig-git/Makefile | 8 +-----
zig-git/patches/patch-CMakeLists.txt | 47 ++++++++++++++++++++++++++++++++++
zig-git/patches/patch-src_link_Elf.zig | 23 +++++++++++++++++
3 files changed, 71 insertions(+), 7 deletions(-)
diffs:
diff --git a/zig-git/Makefile b/zig-git/Makefile
index 3b464fe99d..d5c4683aa5 100644
--- a/zig-git/Makefile
+++ b/zig-git/Makefile
@@ -20,6 +20,7 @@ CMAKE_ARGS+= -DDESTDIR=${DESTDIR}
# avoid full-cu-features available to build host,
# in other words ensure that we run everywhere
CMAKE_ARGS+= -DZIG_TARGET_MCPU=baseline
+CMAKE_ARGS+= -DZIG_PIE=ON
REPLACE_BASH+= lib/libcxxabi/src/demangle/cp-to-llvm.sh
@@ -32,13 +33,6 @@ DEPENDS+= llvm>=16.0.0:../../wip/llvm
DEPENDS+= lld>=16.0.0:../../wip/lld
DEPENDS+= clang>=16.0.0:../../wip/clang
-# \todo: There is currently an issue building this as a PIE
-MKPIE_SUPPORTED= no
-CHECK_PIE_SKIP= bin/zig
-# RELRO checks fail for this package at the moment
-RELRO_SUPPORTED= no
-CHECK_RELRO_SKIP= bin/zig
-
CONFLICTS+= zig-[0-9]*
INSTALLATION_DIRS+= share/doc/zig
diff --git a/zig-git/patches/patch-CMakeLists.txt b/zig-git/patches/patch-CMakeLists.txt
new file mode 100644
index 0000000000..e224076799
--- /dev/null
+++ b/zig-git/patches/patch-CMakeLists.txt
@@ -0,0 +1,47 @@
+From dacd959704b8ffae32fa19c5ec428b06cbbbba4f Mon Sep 17 00:00:00 2001
+From: Michael Dusan <michael.dusan%gmail.com@localhost>
+Date: Sat, 29 Apr 2023 13:14:51 -0400
+Subject: [PATCH] cmake: add ZIG_PIE toggle for -Dpie
+
+- add pkg-maintainer-friendly option to enable PIE when building zig
+- fix `ZIG_PIE_ARG` syntax
+
+--- CMakeLists.txt
++++ CMakeLists.txt
+@@ -130,6 +130,8 @@ if(ZIG_AR_WORKAROUND)
+ string(REPLACE "<CMAKE_AR>" "<CMAKE_AR> ar" CMAKE_CXX_ARCHIVE_CREATE ${CMAKE_CXX_ARCHIVE_CREATE})
+ endif()
+
++set(ZIG_PIE off CACHE BOOL "produce a position independent zig executable")
++
+ find_package(llvm 16)
+ find_package(clang 16)
+ find_package(lld 16)
+@@ -686,7 +688,12 @@ if(ZIG_STATIC)
+ endif()
+
+ add_library(zigcpp STATIC ${ZIG_CPP_SOURCES})
+-set_target_properties(zigcpp PROPERTIES COMPILE_FLAGS ${EXE_CXX_FLAGS})
++if(ZIG_PIE)
++ set(ZIGCPP_CXX_FLAGS "${EXE_CXX_FLAGS} -fPIC")
++else()
++ set(ZIGCPP_CXX_FLAGS "${EXE_CXX_FLAGS}")
++endif()
++set_target_properties(zigcpp PROPERTIES COMPILE_FLAGS ${ZIGCPP_CXX_FLAGS})
+
+ target_link_libraries(zigcpp LINK_PUBLIC
+ ${CLANG_LIBRARIES}
+@@ -838,10 +845,10 @@ else()
+ set(ZIG_STATIC_ARG "")
+ endif()
+
+-if(CMAKE_POSITION_INDEPENDENT_CODE)
+- set(ZIG_PIE_ARG="-Dpie")
++if(CMAKE_POSITION_INDEPENDENT_CODE OR ZIG_PIE)
++ set(ZIG_PIE_ARG "-Dpie")
+ else()
+- set(ZIG_PIE_ARG="")
++ set(ZIG_PIE_ARG "")
+ endif()
+
+ set(ZIG_BUILD_ARGS
diff --git a/zig-git/patches/patch-src_link_Elf.zig b/zig-git/patches/patch-src_link_Elf.zig
new file mode 100644
index 0000000000..d58da480e3
--- /dev/null
+++ b/zig-git/patches/patch-src_link_Elf.zig
@@ -0,0 +1,23 @@
+From 23fdbe052d06d186c5b63d930055344c848e0259 Mon Sep 17 00:00:00 2001
+From: Michael Dusan <michael.dusan%gmail.com@localhost>
+Date: Sat, 29 Apr 2023 13:14:49 -0400
+Subject: [PATCH] netbsd: restrict PT_LOAD workaround to dlibs only
+
+NetBSD supports executables with > 2 PT_LOAD segments but dynamic
+libraries continue to expect exactly 2 PT_LOAD segments.
+
+--- src/link/Elf.zig
++++ src/link/Elf.zig
+@@ -1636,10 +1636,10 @@ fn linkWithLLD(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node) !v
+ try argv.append("-pie");
+ }
+
+- if (self.base.options.link_mode == .Dynamic and target.os.tag == .netbsd) {
++ if (is_dyn_lib and target.os.tag == .netbsd) {
+ // Add options to produce shared objects with only 2 PT_LOAD segments.
+ // NetBSD expects 2 PT_LOAD segments in a shared object, otherwise
+- // ld.elf_so fails to load, emitting a general "not found" error.
++ // ld.elf_so fails loading dynamic libraries with "not found" error.
+ // See https://github.com/ziglang/zig/issues/9109 .
+ try argv.append("--no-rosegment");
+ try argv.append("-znorelro");
Home |
Main Index |
Thread Index |
Old Index