guix-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] gnu: patchelf: Fix platform page size determination


From: Mark H Weaver
Subject: [PATCH] gnu: patchelf: Fix platform page size determination
Date: Mon, 17 Feb 2014 07:37:06 -0500

This patch is needed to fix a problem in 'patchelf', which sometimes
produces ELF libraries that fail to work on MIPS systems configured to
use a 64K page size.  Linux on MIPS can be configured to use 16K or 64K
as the page size, and there are significant performance advantages to
using 64K.  (I'm now running with 64K pages on my YeeLoong).

Patchelf incorrectly assumes that the page size on MIPS systems is 16K,
and aligns segments accordingly.  From patchelf.cc:

--8<---------------cut here---------------start------------->8---
#ifdef MIPSEL
/* The lemote fuloong 2f kernel defconfig sets a page size of 16KB */
const unsigned int pageSize = 4096*4;
#else
const unsigned int pageSize = 4096;
#endif
--8<---------------cut here---------------end--------------->8---

This is a serious mistake.  All proper linkers use the maximum
architectural page size for the platform.  For Linux MIPS, that's 64K.

FYI, the following packages include 'patchelf' as an input: python, hop,
ffmpeg, icu4c, cdparanoia, libssh, and samba.

     Mark


>From b95b5d7289c094189c106c5faf3aea45ecabcac9 Mon Sep 17 00:00:00 2001
From: Mark H Weaver <address@hidden>
Date: Sun, 16 Feb 2014 20:20:10 -0500
Subject: [PATCH] gnu: patchelf: Fix platform page size determination.

* gnu/packages/patches/patchelf-page-size.patch: New file.
* gnu/packages/elf.scm (patchelf): Add the patch.
* gnu-system.am (dist_patch_DATA): Add the patch.
---
 gnu-system.am                                 |  1 +
 gnu/packages/elf.scm                          |  4 +-
 gnu/packages/patches/patchelf-page-size.patch | 69 +++++++++++++++++++++++++++
 3 files changed, 73 insertions(+), 1 deletion(-)
 create mode 100644 gnu/packages/patches/patchelf-page-size.patch

diff --git a/gnu-system.am b/gnu-system.am
index 9b0a691..5ff3067 100644
--- a/gnu-system.am
+++ b/gnu-system.am
@@ -290,6 +290,7 @@ dist_patch_DATA =                                           
\
   gnu/packages/patches/make-impure-dirs.patch                  \
   gnu/packages/patches/mcron-install.patch                     \
   gnu/packages/patches/mit-krb5-init-fix.patch                 \
+  gnu/packages/patches/patchelf-page-size.patch                        \
   gnu/packages/patches/perl-no-sys-dirs.patch                  \
   gnu/packages/patches/plotutils-libpng-jmpbuf.patch           \
   gnu/packages/patches/procps-make-3.82.patch                  \
diff --git a/gnu/packages/elf.scm b/gnu/packages/elf.scm
index 1df9956..45714be 100644
--- a/gnu/packages/elf.scm
+++ b/gnu/packages/elf.scm
@@ -21,6 +21,7 @@
   #:use-module (guix download)
   #:use-module (guix build-system gnu)
   #:use-module ((guix licenses) #:select (gpl3+ lgpl3+ lgpl2.0+))
+  #:use-module (gnu packages)
   #:use-module (gnu packages m4)
   #:use-module (gnu packages compression))
 
@@ -92,7 +93,8 @@
                    "/patchelf-" version ".tar.bz2"))
              (sha256
               (base32
-               "00bw29vdsscsili65wcb5ay0gvg1w0ljd00sb5xc6br8bylpyzpw"))))
+               "00bw29vdsscsili65wcb5ay0gvg1w0ljd00sb5xc6br8bylpyzpw"))
+             (patches (list (search-patch "patchelf-page-size.patch")))))
     (build-system gnu-build-system)
     (home-page "http://nixos.org/patchelf.html";)
     (synopsis "Modify the dynamic linker and RPATH of ELF executables")
diff --git a/gnu/packages/patches/patchelf-page-size.patch 
b/gnu/packages/patches/patchelf-page-size.patch
new file mode 100644
index 0000000..2528b60
--- /dev/null
+++ b/gnu/packages/patches/patchelf-page-size.patch
@@ -0,0 +1,69 @@
+Improve the determination of pageSize in patchelf.cc.
+
+Patch by Mark H Weaver <address@hidden>.
+
+--- patchelf/src/patchelf.cc.orig      1969-12-31 19:00:01.000000000 -0500
++++ patchelf/src/patchelf.cc   2014-02-16 20:15:06.283203125 -0500
+@@ -21,11 +21,19 @@
+ using namespace std;
+ 
+ 
+-#ifdef MIPSEL
+-/* The lemote fuloong 2f kernel defconfig sets a page size of 16KB */
+-const unsigned int pageSize = 4096*4;
+-#else
++/* Note that some platforms support multiple page sizes.  Therefore,
++   it is not enough to query the current page size.  'pageSize' must
++   be the maximum architectural page size for the platform, which is
++   typically defined in the corresponding ABI document.
++
++   XXX FIXME: This won't work when we're cross-compiling.  */
++
++#if defined __MIPSEL__ || defined __MIPSEB__ || defined __aarch64__
++const unsigned int pageSize = 65536;
++#elif defined __x86_64__ || defined __i386__ || defined __arm__
+ const unsigned int pageSize = 4096;
++#else
++# error maximum architectural page size unknown for this platform
+ #endif
+ 
+ 
+--- patchelf/tests/no-rpath.sh.orig    1969-12-31 19:00:01.000000000 -0500
++++ patchelf/tests/no-rpath.sh 2014-02-16 20:44:12.036376953 -0500
+@@ -1,22 +1,22 @@
+ #! /bin/sh -e
+ 
+-rm -rf scratch
+-mkdir -p scratch
++if [ "$(uname -m)" = i686 -a "$(uname -s)" = Linux ]; then
++    rm -rf scratch
++    mkdir -p scratch
+ 
+-cp no-rpath scratch/
++    cp no-rpath scratch/
+ 
+-oldRPath=$(../src/patchelf --print-rpath scratch/no-rpath)
+-if test -n "$oldRPath"; then exit 1; fi
+-../src/patchelf \
+-  --set-interpreter "$(../src/patchelf --print-interpreter ../src/patchelf)" \
+-  --set-rpath /foo:/bar:/xxxxxxxxxxxxxxx scratch/no-rpath
++    oldRPath=$(../src/patchelf --print-rpath scratch/no-rpath)
++    if test -n "$oldRPath"; then exit 1; fi
++    ../src/patchelf \
++      --set-interpreter "$(../src/patchelf --print-interpreter 
../src/patchelf)" \
++      --set-rpath /foo:/bar:/xxxxxxxxxxxxxxx scratch/no-rpath
+ 
+-newRPath=$(../src/patchelf --print-rpath scratch/no-rpath)
+-if ! echo "$newRPath" | grep -q '/foo:/bar'; then
+-    echo "incomplete RPATH"
+-    exit 1
+-fi
++    newRPath=$(../src/patchelf --print-rpath scratch/no-rpath)
++    if ! echo "$newRPath" | grep -q '/foo:/bar'; then
++        echo "incomplete RPATH"
++        exit 1
++    fi
+ 
+-if [ "$(uname -m)" = i686 -a "$(uname -s)" = Linux ]; then
+     cd scratch && ./no-rpath
+ fi
-- 
1.8.4


reply via email to

[Prev in Thread] Current Thread [Next in Thread]