develooper Front page | perl.perl5.porters | Postings from December 2010

[perl #81026] Perl binary no longer relocatable

Thread Next
From:
Doug Hunt
Date:
December 20, 2010 17:11
Subject:
[perl #81026] Perl binary no longer relocatable
Message ID:
rt-3.6.HEAD-5425-1292867413-788.81026-75-0@perl.org
# New Ticket Created by  Doug Hunt 
# Please include the string:  [perl #81026]
# in the subject line of all future correspondence about this issue. 
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=81026 >



This is a bug report for perl from dhunt@ucar.edu,
generated with the help of perlbug 1.39 running under perl 5.12.2.


-----------------------------------------------------------------
[Please describe your issue here]

Hello:  For several years now, I have been building a set of relocatable
RPMs including perl and many perl modules.  I have been using a trick
I learned from the ActiveState perl distribution:  Compile perl with an
install PREFIX set to a long path name.  Then when installing the RPM
(in the RPM %post section) one can 'relocate' the perl binary by swapping
the long PREFIX path with the shorter correct path and null padding the binary.

In my perl RPM %build section, I do something like this:

sh Configure -Dprefix=/tmp/LongPathnameForInstallBeforeRelocationToNewBase/ops/tools -des

Then when I install the RPM (in the %post section) I run a perl script which
switches the install PREFIX (/tmp/LongPathnameForInstallBeforeRelocationToNewBase/ops/tools)
with the real install prefix (say /ops/tools) in the perl binary using NULLs to 
keep the binary the same length.

This stopped working sometime in perl 5.12.  The use of the STR_WITH_LEN macro
has disabled run-time checking of the length of embedded path names.
For example:

S_incpush_use_sep(aTHX_ STR_WITH_LEN(SITELIB_EXP), INCPUSH_CAN_RELOCATE);

The fixes the length of the SITELIB library path to be the same as when compiled,
thus ruining relocation.

I've been using the patch below in production for a couple of months with
no ill effects.  It passes the test suite.
This patch just replaces the above line with

S_incpush_use_sep(aTHX_ SITELIB_EXP, 0, INCPUSH_CAN_RELOCATE);

in several cases.  The '0' means that the length of SITELIB_EXP is 
computed at runtime with strlen, allowing relocation to work.

Please consider this patch, I consider the ability to make relocatable RPMs of
perl to be an essential feature of the language that I and others have profited
from.

Regards, 

  Doug Hunt (dhunt@ucar.edu)


------------------%<-----------------------------------------------------
diff -r -u -N perl-5.12.2.orig/perl.c perl-5.12.2/perl.c
--- perl-5.12.2.orig/perl.c	2010-11-01 16:33:09.000000000 -0600
+++ perl-5.12.2/perl.c	2010-11-01 16:29:08.000000000 -0600
@@ -4121,7 +4121,7 @@
     SITEARCH, SITELIB, VENDORARCH, VENDORLIB, ARCHLIB and PRIVLIB
 */
 #ifdef APPLLIB_EXP
-    S_incpush_use_sep(aTHX_ STR_WITH_LEN(APPLLIB_EXP),
+    S_incpush_use_sep(aTHX_ APPLLIB_EXP, 0,
 		      INCPUSH_ADD_SUB_DIRS|INCPUSH_CAN_RELOCATE);
 #endif
 
@@ -4129,7 +4129,7 @@
     /* sitearch is always relative to sitelib on Windows for
      * DLL-based path intuition to work correctly */
 #  if !defined(WIN32)
-	S_incpush_use_sep(aTHX_ STR_WITH_LEN(SITEARCH_EXP),
+    S_incpush_use_sep(aTHX_ SITEARCH_EXP, 0,
 			  INCPUSH_CAN_RELOCATE);
 #  endif
 #endif
@@ -4141,7 +4141,7 @@
 	if (s)
 	    incpush_use_sep(s, len, INCPUSH_ADD_SUB_DIRS|INCPUSH_CAN_RELOCATE);
 #  else
-	S_incpush_use_sep(aTHX_ STR_WITH_LEN(SITELIB_EXP), INCPUSH_CAN_RELOCATE);
+	S_incpush_use_sep(aTHX_ SITELIB_EXP, 0, INCPUSH_CAN_RELOCATE);
 #  endif
 #endif
 
@@ -4149,7 +4149,7 @@
     /* vendorarch is always relative to vendorlib on Windows for
      * DLL-based path intuition to work correctly */
 #  if !defined(WIN32)
-    S_incpush_use_sep(aTHX_ STR_WITH_LEN(PERL_VENDORARCH_EXP),
+	S_incpush_use_sep(aTHX_ PERL_VENDORARCH_EXP, 0,
 		      INCPUSH_CAN_RELOCATE);
 #  endif
 #endif
@@ -4161,13 +4161,13 @@
 	if (s)
 	    incpush_use_sep(s, len, INCPUSH_ADD_SUB_DIRS|INCPUSH_CAN_RELOCATE);
 #  else
-	S_incpush_use_sep(aTHX_ STR_WITH_LEN(PERL_VENDORLIB_EXP),
+	S_incpush_use_sep(aTHX_ PERL_VENDORLIB_EXP, 0,
 			  INCPUSH_CAN_RELOCATE);
 #  endif
 #endif
 
 #ifdef ARCHLIB_EXP
-    S_incpush_use_sep(aTHX_ STR_WITH_LEN(ARCHLIB_EXP), INCPUSH_CAN_RELOCATE);
+	S_incpush_use_sep(aTHX_ ARCHLIB_EXP, 0, INCPUSH_CAN_RELOCATE);
 #endif
 
 #ifndef PRIVLIB_EXP
@@ -4182,12 +4182,12 @@
 #  ifdef NETWARE
     S_incpush_use_sep(aTHX_ PRIVLIB_EXP, 0, INCPUSH_CAN_RELOCATE);
 #  else
-    S_incpush_use_sep(aTHX_ STR_WITH_LEN(PRIVLIB_EXP), INCPUSH_CAN_RELOCATE);
+    S_incpush_use_sep(aTHX_ PRIVLIB_EXP, 0, INCPUSH_CAN_RELOCATE);
 #  endif
 #endif
 
 #ifdef PERL_OTHERLIBDIRS
-    S_incpush_use_sep(aTHX_ STR_WITH_LEN(PERL_OTHERLIBDIRS),
+    S_incpush_use_sep(aTHX_ PERL_OTHERLIBDIRS, 0,
 		      INCPUSH_ADD_VERSIONED_SUB_DIRS|INCPUSH_NOT_BASEDIR
 		      |INCPUSH_CAN_RELOCATE);
 #endif
@@ -4225,25 +4225,25 @@
     SITELIB and VENDORLIB for older versions
 */
 #ifdef APPLLIB_EXP
-    S_incpush_use_sep(aTHX_ STR_WITH_LEN(APPLLIB_EXP), INCPUSH_ADD_OLD_VERS
+    S_incpush_use_sep(aTHX_ APPLLIB_EXP, 0, INCPUSH_ADD_OLD_VERS
 		      |INCPUSH_NOT_BASEDIR|INCPUSH_CAN_RELOCATE);
 #endif
 
 #if defined(SITELIB_STEM) && defined(PERL_INC_VERSION_LIST)
     /* Search for version-specific dirs below here */
-    S_incpush_use_sep(aTHX_ STR_WITH_LEN(SITELIB_STEM),
+    S_incpush_use_sep(aTHX_ SITELIB_STEM, 0,
 		      INCPUSH_ADD_OLD_VERS|INCPUSH_CAN_RELOCATE);
 #endif
 
 
 #if defined(PERL_VENDORLIB_STEM) && defined(PERL_INC_VERSION_LIST)
     /* Search for version-specific dirs below here */
-    S_incpush_use_sep(aTHX_ STR_WITH_LEN(PERL_VENDORLIB_STEM),
+    S_incpush_use_sep(aTHX_ PERL_VENDORLIB_STEM, 0,
 		      INCPUSH_ADD_OLD_VERS|INCPUSH_CAN_RELOCATE);
 #endif
 
 #ifdef PERL_OTHERLIBDIRS
-    S_incpush_use_sep(aTHX_ STR_WITH_LEN(PERL_OTHERLIBDIRS),
+    S_incpush_use_sep(aTHX_ PERL_OTHERLIBDIRS, 0,
 		      INCPUSH_ADD_OLD_VERS|INCPUSH_ADD_ARCHONLY_SUB_DIRS
 		      |INCPUSH_CAN_RELOCATE);
 #endif
------------------%<------------------------------------------------

[Please do not change anything below this line]
-----------------------------------------------------------------
---
Flags:
    category=core
    severity=high
---
Site configuration information for perl 5.12.2:

Configured by rpmbuild at Tue Dec  7 14:28:53 MST 2010.

Summary of my perl5 (revision 5 version 12 subversion 2) configuration:
   
  Platform:
    osname=linux, osvers=2.6.18-194.17.1.el5, archname=x86_64-linux
    uname='linux lynx.cosmic.ucar.edu 2.6.18-194.17.1.el5 #1 smp wed sep 29 12:50:31 edt 2010 x86_64 x86_64 x86_64 gnulinux '
    config_args='-Dprefix=/home/rpmbuild/rpm/aReallyLongNameForOps/tools -des'
    hint=recommended, useposix=true, d_sigaction=define
    useithreads=undef, usemultiplicity=undef
    useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
    use64bitint=define, use64bitall=define, uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cc', ccflags ='-fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize='-O2',
    cppflags='-fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include'
    ccversion='', gccversion='4.1.2 20080704 (Red Hat 4.1.2-48)', gccosandvers=''
    intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
    ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=8, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =' -fstack-protector -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib /lib64 /usr/lib64 /usr/local/lib64
    libs=-lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lc
    perllibs=-lnsl -ldl -lm -lcrypt -lutil -lc
    libc=/lib/libc-2.5.so, so=so, useshrplib=false, libperl=libperl.a
    gnulibc_version='2.5'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
    cccdlflags='-fPIC', lddlflags='-shared -O2 -L/usr/local/lib -fstack-protector'

Locally applied patches:
    

---
@INC for perl 5.12.2:
    /home/rpmbuild/rpm/aReallyLongNameForOps/tools/lib/perl5/site_perl/5.12.2/x86_64-linux
    /home/rpmbuild/rpm/aReallyLongNameForOps/tools/lib/perl5/site_perl/5.12.2
    /home/rpmbuild/rpm/aReallyLongNameForOps/tools/lib/perl5/5.12.2/x86_64-linux
    /home/rpmbuild/rpm/aReallyLongNameForOps/tools/lib/perl5/5.12.2
    .

---
Environment for perl 5.12.2:
    HOME=/home/rpmbuild
    LANG=C
    LANGUAGE (unset)
    LD_LIBRARY_PATH=/home/rpmbuild/rpm/aReallyLongNameForOps/tools/pgi/lib:/home/rpmbuild/rpm/aReallyLongNameForOps/tools/lib:/home/rpmbuild/rpm/aReallyLongNameForOps/tools/lib/qwt
    LOGDIR (unset)
    PATH=.:/home/rpmbuild/bin:/home/rpmbuild/rpm/aReallyLongNameForOps/tools/bin:/home/rpmbuild/rpm/aReallyLongNameForOps/tools/pgi/bin:/home/rpmbuild/rpm/aReallyLongNameForOps/tools/postgres/bin:/home/rpmbuild/rpm/aReallyLongNameForOps/tools/apache/bin:/home/rpmbuild/rpm/aReallyLongNameForOps/tools/bern5/BERN/PGM/EXE:/usr/local/dcs/bin:/usr/local/grace/bin:/home/rpmbuild/rpm/aReallyLongNameForOps/tools/ncarg/bin:/usr/lib64/qt-3.3/bin:/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/home/rpmbuild/bin
    PERL_BADLANG (unset)
    SHELL=/bin/bash


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About