From 4b6b4fc53791e7873e56f01cff1baf692906f340 Mon Sep 17 00:00:00 2001 From: fanquake Date: Mon, 13 Jun 2022 11:10:06 +0100 Subject: [PATCH 1/3] guix: remove usage of -Wl,-z,noexecstack for PPC64 HOST The PPC64 ABI has a non-executable stack by default, and does not need a GNU_STACK program header. See also: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/powerpc/include/asm/page_64.h#n92 --- contrib/guix/libexec/build.sh | 4 ---- 1 file changed, 4 deletions(-) diff --git a/contrib/guix/libexec/build.sh b/contrib/guix/libexec/build.sh index 44c769f4632..ad3129184c9 100755 --- a/contrib/guix/libexec/build.sh +++ b/contrib/guix/libexec/build.sh @@ -249,10 +249,6 @@ case "$HOST" in *powerpc64*) HOST_LDFLAGS="${HOST_LDFLAGS} -Wl,--no-tls-get-addr-optimize" ;; esac -case "$HOST" in - powerpc64-linux-*) HOST_LDFLAGS="${HOST_LDFLAGS} -Wl,-z,noexecstack" ;; -esac - # Make $HOST-specific native binaries from depends available in $PATH export PATH="${BASEPREFIX}/${HOST}/native/bin:${PATH}" mkdir -p "$DISTSRC" From 0b5adfda87ff9f3cf669c277b2c3e2b96676b259 Mon Sep 17 00:00:00 2001 From: fanquake Date: Thu, 16 Jun 2022 15:45:08 +0100 Subject: [PATCH 2/3] guix: use LIEF 0.12.1 --- contrib/guix/manifest.scm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contrib/guix/manifest.scm b/contrib/guix/manifest.scm index acb7ff99128..09d9525f820 100644 --- a/contrib/guix/manifest.scm +++ b/contrib/guix/manifest.scm @@ -203,7 +203,7 @@ chain for " target " development.")) (define-public lief (package (name "python-lief") - (version "0.12.0") + (version "0.12.1") (source (origin (method git-fetch) @@ -213,7 +213,7 @@ chain for " target " development.")) (file-name (git-file-name name version)) (sha256 (base32 - "026jchj56q25v6gc0754dj9cj5hz5zaza8ij93y5ga94w20kzm9q")))) + "1xzbh3bxy4rw1yamnx68da1v5s56ay4g081cyamv67256g0qy2i1")))) (build-system python-build-system) (arguments `(#:phases From 5f082ad4e4cc59ccc0ea32626a69522abba71e0d Mon Sep 17 00:00:00 2001 From: fanquake Date: Sat, 25 Jun 2022 09:41:09 +0100 Subject: [PATCH 3/3] guix: patch LIEF to fix PPC64 NX default This patches our LIEF build using the change merged upstream: https://github.com/lief-project/LIEF/pull/718. This can be dropped the next time we update LIEF. --- contrib/guix/manifest.scm | 6 +++- .../patches/lief-fix-ppc64-nx-default.patch | 29 +++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 contrib/guix/patches/lief-fix-ppc64-nx-default.patch diff --git a/contrib/guix/manifest.scm b/contrib/guix/manifest.scm index 09d9525f820..36d8dddab61 100644 --- a/contrib/guix/manifest.scm +++ b/contrib/guix/manifest.scm @@ -200,6 +200,10 @@ chain for " target " development.")) (package-with-extra-patches base-nsis (search-our-patches "nsis-gcc-10-memmove.patch"))) +(define (fix-ppc64-nx-default lief) + (package-with-extra-patches lief + (search-our-patches "lief-fix-ppc64-nx-default.patch"))) + (define-public lief (package (name "python-lief") @@ -602,7 +606,7 @@ inspecting signatures in Mach-O binaries.") ;; Git git ;; Tests - lief) + (fix-ppc64-nx-default lief)) (let ((target (getenv "HOST"))) (cond ((string-suffix? "-mingw32" target) ;; Windows diff --git a/contrib/guix/patches/lief-fix-ppc64-nx-default.patch b/contrib/guix/patches/lief-fix-ppc64-nx-default.patch new file mode 100644 index 00000000000..101bc1ddc0c --- /dev/null +++ b/contrib/guix/patches/lief-fix-ppc64-nx-default.patch @@ -0,0 +1,29 @@ +Correct default for Binary::has_nx on ppc64 + +From the Linux kernel source: + + * This is the default if a program doesn't have a PT_GNU_STACK + * program header entry. The PPC64 ELF ABI has a non executable stack + * stack by default, so in the absence of a PT_GNU_STACK program header + * we turn execute permission off. + +This patch can be dropped the next time we update LIEF. + +diff --git a/src/ELF/Binary.cpp b/src/ELF/Binary.cpp +index a90be1ab..fd2d9764 100644 +--- a/src/ELF/Binary.cpp ++++ b/src/ELF/Binary.cpp +@@ -1084,7 +1084,12 @@ bool Binary::has_nx() const { + return segment->type() == SEGMENT_TYPES::PT_GNU_STACK; + }); + if (it_stack == std::end(segments_)) { +- return false; ++ if (header().machine_type() == ARCH::EM_PPC64) { ++ // The PPC64 ELF ABI has a non-executable stack by default. ++ return true; ++ } else { ++ return false; ++ } + } + + return !(*it_stack)->has(ELF_SEGMENT_FLAGS::PF_X);