Skip to content

Commit 5f082ad

Browse files
committed
guix: patch LIEF to fix PPC64 NX default
This patches our LIEF build using the change merged upstream: lief-project/LIEF#718. This can be dropped the next time we update LIEF.
1 parent 0b5adfd commit 5f082ad

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

contrib/guix/manifest.scm

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,10 @@ chain for " target " development."))
200200
(package-with-extra-patches base-nsis
201201
(search-our-patches "nsis-gcc-10-memmove.patch")))
202202

203+
(define (fix-ppc64-nx-default lief)
204+
(package-with-extra-patches lief
205+
(search-our-patches "lief-fix-ppc64-nx-default.patch")))
206+
203207
(define-public lief
204208
(package
205209
(name "python-lief")
@@ -602,7 +606,7 @@ inspecting signatures in Mach-O binaries.")
602606
;; Git
603607
git
604608
;; Tests
605-
lief)
609+
(fix-ppc64-nx-default lief))
606610
(let ((target (getenv "HOST")))
607611
(cond ((string-suffix? "-mingw32" target)
608612
;; Windows
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
Correct default for Binary::has_nx on ppc64
2+
3+
From the Linux kernel source:
4+
5+
* This is the default if a program doesn't have a PT_GNU_STACK
6+
* program header entry. The PPC64 ELF ABI has a non executable stack
7+
* stack by default, so in the absence of a PT_GNU_STACK program header
8+
* we turn execute permission off.
9+
10+
This patch can be dropped the next time we update LIEF.
11+
12+
diff --git a/src/ELF/Binary.cpp b/src/ELF/Binary.cpp
13+
index a90be1ab..fd2d9764 100644
14+
--- a/src/ELF/Binary.cpp
15+
+++ b/src/ELF/Binary.cpp
16+
@@ -1084,7 +1084,12 @@ bool Binary::has_nx() const {
17+
return segment->type() == SEGMENT_TYPES::PT_GNU_STACK;
18+
});
19+
if (it_stack == std::end(segments_)) {
20+
- return false;
21+
+ if (header().machine_type() == ARCH::EM_PPC64) {
22+
+ // The PPC64 ELF ABI has a non-executable stack by default.
23+
+ return true;
24+
+ } else {
25+
+ return false;
26+
+ }
27+
}
28+
29+
return !(*it_stack)->has(ELF_SEGMENT_FLAGS::PF_X);

0 commit comments

Comments
 (0)