Hello community, here is the log from the commit of package patchelf for openSUSE:Factory checked in at 2020-08-19 18:45:09 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/patchelf (Old) and /work/SRC/openSUSE:Factory/.patchelf.new.3399 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "patchelf" Wed Aug 19 18:45:09 2020 rev:12 rq:826921 version:0.11 Changes: -------- --- /work/SRC/openSUSE:Factory/patchelf/patchelf.changes 2019-08-27 10:28:27.095909655 +0200 +++ /work/SRC/openSUSE:Factory/.patchelf.new.3399/patchelf.changes 2020-08-19 18:46:19.447512389 +0200 @@ -1,0 +2,8 @@ +Sun Aug 16 00:47:05 UTC 2020 - Dirk Mueller <dmuel...@suse.com> + +- update to 0.11: + * More modern C++ has avoided a memory leak + * force-rpath is now consistently used + * new --output flag + +------------------------------------------------------------------- Old: ---- patchelf-0.10.tar.bz2 New: ---- patchelf-0.11.tar.bz2 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ patchelf.spec ++++++ --- /var/tmp/diff_new_pack.lAithE/_old 2020-08-19 18:46:23.151514357 +0200 +++ /var/tmp/diff_new_pack.lAithE/_new 2020-08-19 18:46:23.151514357 +0200 @@ -1,7 +1,7 @@ # # spec file for package patchelf # -# Copyright (c) 2019 SUSE LINUX GmbH, Nuernberg, Germany. +# Copyright (c) 2020 SUSE LLC # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed @@ -17,7 +17,7 @@ Name: patchelf -Version: 0.10 +Version: 0.11 Release: 0 Summary: A utility for patching ELF binaries License: GPL-3.0-only @@ -32,7 +32,7 @@ executables and change the RPATH of executables and libraries. %prep -%setup -q +%setup -q -n %{name}-0.11.20200609.d6b2a72 %build %configure @@ -43,10 +43,10 @@ %install %make_install -rm %{buildroot}%{_datadir}/doc/patchelf/README +rm -v %{buildroot}%{_datadir}/doc/patchelf/README.md %files -%doc README +%doc README.md %license COPYING %{_bindir}/patchelf %{_mandir}/man1/patchelf.1%{?ext_man} ++++++ patchelf-0.10.tar.bz2 -> patchelf-0.11.tar.bz2 ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/patchelf-0.10/Makefile.am new/patchelf-0.11.20200609.d6b2a72/Makefile.am --- old/patchelf-0.10/Makefile.am 1970-01-01 01:00:01.000000000 +0100 +++ new/patchelf-0.11.20200609.d6b2a72/Makefile.am 1970-01-01 01:00:01.000000000 +0100 @@ -1,7 +1,7 @@ SUBDIRS = src tests -EXTRA_DIST = COPYING README patchelf.spec version $(man1_MANS) +EXTRA_DIST = COPYING README.md patchelf.spec version $(man1_MANS) man1_MANS = patchelf.1 -doc_DATA = README +doc_DATA = README.md diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/patchelf-0.10/Makefile.in new/patchelf-0.11.20200609.d6b2a72/Makefile.in --- old/patchelf-0.10/Makefile.in 2019-03-28 23:23:31.000000000 +0100 +++ new/patchelf-0.11.20200609.d6b2a72/Makefile.in 2020-06-09 14:58:19.000000000 +0200 @@ -189,8 +189,8 @@ am__DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/patchelf.spec.in \ $(top_srcdir)/build-aux/compile \ $(top_srcdir)/build-aux/install-sh \ - $(top_srcdir)/build-aux/missing COPYING README \ - build-aux/compile build-aux/install-sh build-aux/missing + $(top_srcdir)/build-aux/missing COPYING build-aux/compile \ + build-aux/install-sh build-aux/missing DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) distdir = $(PACKAGE)-$(VERSION) top_distdir = $(distdir) @@ -322,9 +322,9 @@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ SUBDIRS = src tests -EXTRA_DIST = COPYING README patchelf.spec version $(man1_MANS) +EXTRA_DIST = COPYING README.md patchelf.spec version $(man1_MANS) man1_MANS = patchelf.1 -doc_DATA = README +doc_DATA = README.md all: all-recursive .SUFFIXES: diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/patchelf-0.10/README new/patchelf-0.11.20200609.d6b2a72/README --- old/patchelf-0.10/README 1970-01-01 01:00:01.000000000 +0100 +++ new/patchelf-0.11.20200609.d6b2a72/README 1970-01-01 01:00:00.000000000 +0100 @@ -1,183 +0,0 @@ -PatchELF is a simple utility for modifying existing ELF executables and -libraries. In particular, it can do the following: - -* Change the dynamic loader ("ELF interpreter") of executables: - - $ patchelf --set-interpreter /lib/my-ld-linux.so.2 my-program - -* Change the RPATH of executables and libraries: - - $ patchelf --set-rpath /opt/my-libs/lib:/other-libs my-program - -* Shrink the RPATH of executables and libraries: - - $ patchelf --shrink-rpath my-program - - This removes from the RPATH all directories that do not contain a - library referenced by DT_NEEDED fields of the executable or library. - For instance, if an executable references one library libfoo.so, has - an RPATH "/lib:/usr/lib:/foo/lib", and libfoo.so can only be found - in /foo/lib, then the new RPATH will be "/foo/lib". - - In addition, the '--allowed-rpath-prefixes' option can be used for - further rpath tuning. For instance, if an executable has an RPATH - "/tmp/build-foo/.libs:/foo/lib", it is probably desirable to keep - the "/foo/lib" reference instead of the "/tmp" entry. To accomplish - that, use: - - $ patchelf --shrink-rpath --allowed-rpath-prefixes /usr/lib:/foo/lib my-program - -* Remove declared dependencies on dynamic libraries (DT_NEEDED - entries): - - $ patchelf --remove-needed libfoo.so.1 my-program - - This option can be given multiple times. - -* Add a declared dependency on a dynamic library (DT_NEEDED): - - $ patchelf --add-needed libfoo.so.1 my-program - - This option can be give multiple times. - -* Replace a declared dependency on a dynamic library with another one - (DT_NEEDED): - - $ patchelf --replace-needed liboriginal.so.1 libreplacement.so.1 my-program - - This option can be give multiple times. - -* Change SONAME of a dynamic library: - - $ patchelf --set-soname libnewname.so.3.4.5 path/to/libmylibrary.so.1.2.3 - - -INSTALLING - -You can download a pre-compiled binary from the releases or compile it by yourself: - - ./bootstrap.sh - ./configure - make - sudo make install - - -AUTHOR - -Copyright 2004-2019 Eelco Dolstra <edols...@gmail.com>. - - -LICENSE - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or (at -your option) any later version. - -This program is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see <http://www.gnu.org/licenses/>. - - -HOMEPAGE - -http://nixos.org/patchelf.html - - -BUGS - -The `strip' command from binutils generated broken executables when -applied to the output of patchelf (if `--set-rpath' or -`--set-interpreter' with a larger path than the original is used). -This appears to be a bug in binutils -(http://bugs.strategoxt.org/browse/NIXPKGS-85). - - -RELEASE HISTORY - -0.10 (March 28, 2019): - -* Many bug fixes. Please refer to the Git commit log: - - https://github.com/NixOS/patchelf/commits/master - - This release has contributions from Adam Trhoň, Benjamin Hipple, - Bernardo Ramos, Bjørn Forsman, Domen Kožar, Eelco Dolstra, Ezra - Cooper, Felipe Sateler, Jakub Wilk, James Le Cuirot, Karl Millar, - Linus Heckemann, Nathaniel J. Smith, Richard Purdie, Stanislav - Markevich and Tuomas Tynkkynen. - -0.9 (February 29, 2016): - -* Lots of new features. Please refer to the Git commit log: - - https://github.com/NixOS/patchelf/commits/master - - This release has contributions from Aaron D. Marasco, Adrien - Devresse, Alexandre Pretyman, Changli Gao, Chingis Dugarzhapov, - darealshinji, David Sveningsson, Eelco Dolstra, Felipe Sateler, - Jeremy Sanders, Jonas Kuemmerlin, Thomas Tuegel, Tuomas Tynkkynen, - Vincent Danjean and Vladimír Čunát. - -0.8 (January 15, 2014): - -* Fix a segfault caused by certain illegal entries in symbol tables. - -0.7 (January 7, 2014): - -* Rewrite section indices in symbol tables. This for instance allows - gdb to show proper backtraces. - -* Added `--remove-needed' option. - -0.6 (November 7, 2011): - -* Hacky support for executables created by the Gold linker. - -* Support segments with an alignment of 0 (contributed by Zack - Weinberg). - -* Added a manual page (contributed by Jeremy Sanders - <jer...@jeremysanders.net>). - -0.5 (November 4, 2009): - -* Various bugfixes. - -* `--force-rpath' now deletes the DT_RUNPATH if it is present. - -0.4 (June 4, 2008): - -* Support for growing the RPATH on dynamic libraries. - -* IA-64 support (not tested) and related 64-bit fixes. - -* FreeBSD support. - -* `--set-rpath', `--shrink-rpath' and `--print-rpath' now prefer - DT_RUNPATH over DT_RPATH, which is obsolete. When updating, if both - are present, both are updated. If only DT_RPATH is present, it is - converted to DT_RUNPATH unless `--force-rpath' is specified. If - neither is present, a DT_RUNPATH is added unless `--force-rpath' is - specified, in which case a DT_RPATH is added. - -0.3 (May 24, 2007): - -* Support for 64-bit ELF binaries (such as on x86_64-linux). - -* Support for big-endian ELF binaries (such as on powerpc-linux). - -* Various bugfixes. - -0.2 (January 15, 2007): - -* Provides a hack to get certain programs (such as the - Belastingaangifte 2005) to work. - -0.1 (October 11, 2005): - -* Initial release. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/patchelf-0.10/README.md new/patchelf-0.11.20200609.d6b2a72/README.md --- old/patchelf-0.10/README.md 1970-01-01 01:00:00.000000000 +0100 +++ new/patchelf-0.11.20200609.d6b2a72/README.md 1970-01-01 01:00:01.000000000 +0100 @@ -0,0 +1,172 @@ +PatchELF is a simple utility for modifying existing ELF executables and +libraries. In particular, it can do the following: + +* Change the dynamic loader ("ELF interpreter") of executables: + + $ patchelf --set-interpreter /lib/my-ld-linux.so.2 my-program + +* Change the RPATH of executables and libraries: + + $ patchelf --set-rpath /opt/my-libs/lib:/other-libs my-program + +* Shrink the RPATH of executables and libraries: + + $ patchelf --shrink-rpath my-program + + This removes from the RPATH all directories that do not contain a + library referenced by DT_NEEDED fields of the executable or library. + For instance, if an executable references one library libfoo.so, has + an RPATH "/lib:/usr/lib:/foo/lib", and libfoo.so can only be found + in /foo/lib, then the new RPATH will be "/foo/lib". + + In addition, the '--allowed-rpath-prefixes' option can be used for + further rpath tuning. For instance, if an executable has an RPATH + "/tmp/build-foo/.libs:/foo/lib", it is probably desirable to keep + the "/foo/lib" reference instead of the "/tmp" entry. To accomplish + that, use: + + $ patchelf --shrink-rpath --allowed-rpath-prefixes /usr/lib:/foo/lib my-program + +* Remove declared dependencies on dynamic libraries (DT_NEEDED + entries): + + $ patchelf --remove-needed libfoo.so.1 my-program + + This option can be given multiple times. + +* Add a declared dependency on a dynamic library (DT_NEEDED): + + $ patchelf --add-needed libfoo.so.1 my-program + + This option can be give multiple times. + +* Replace a declared dependency on a dynamic library with another one + (DT_NEEDED): + + $ patchelf --replace-needed liboriginal.so.1 libreplacement.so.1 my-program + + This option can be give multiple times. + +* Change SONAME of a dynamic library: + + $ patchelf --set-soname libnewname.so.3.4.5 path/to/libmylibrary.so.1.2.3 + + +## COMPILING & TESTING + + ./bootstrap.sh + ./configure + make + sudo make install + make check + +## AUTHOR + +Copyright 2004-2019 Eelco Dolstra <edols...@gmail.com>. + + +## LICENSE + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or (at +your option) any later version. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see <http://www.gnu.org/licenses/>. + +## RELEASE HISTORY + +0.11 (June 9, 2020): + +* New `--output` flag. + +* Some bug fixes. + +0.10 (March 28, 2019): + +* Many bug fixes. Please refer to the Git commit log: + + https://github.com/NixOS/patchelf/commits/master + + This release has contributions from Adam Trhoň, Benjamin Hipple, + Bernardo Ramos, Bjørn Forsman, Domen Kožar, Eelco Dolstra, Ezra + Cooper, Felipe Sateler, Jakub Wilk, James Le Cuirot, Karl Millar, + Linus Heckemann, Nathaniel J. Smith, Richard Purdie, Stanislav + Markevich and Tuomas Tynkkynen. + +0.9 (February 29, 2016): + +* Lots of new features. Please refer to the Git commit log: + + https://github.com/NixOS/patchelf/commits/master + + This release has contributions from Aaron D. Marasco, Adrien + Devresse, Alexandre Pretyman, Changli Gao, Chingis Dugarzhapov, + darealshinji, David Sveningsson, Eelco Dolstra, Felipe Sateler, + Jeremy Sanders, Jonas Kuemmerlin, Thomas Tuegel, Tuomas Tynkkynen, + Vincent Danjean and Vladimír Čunát. + +0.8 (January 15, 2014): + +* Fix a segfault caused by certain illegal entries in symbol tables. + +0.7 (January 7, 2014): + +* Rewrite section indices in symbol tables. This for instance allows + gdb to show proper backtraces. + +* Added `--remove-needed' option. + +0.6 (November 7, 2011): + +* Hacky support for executables created by the Gold linker. + +* Support segments with an alignment of 0 (contributed by Zack + Weinberg). + +* Added a manual page (contributed by Jeremy Sanders + <jer...@jeremysanders.net>). + +0.5 (November 4, 2009): + +* Various bugfixes. + +* `--force-rpath' now deletes the DT_RUNPATH if it is present. + +0.4 (June 4, 2008): + +* Support for growing the RPATH on dynamic libraries. + +* IA-64 support (not tested) and related 64-bit fixes. + +* FreeBSD support. + +* `--set-rpath', `--shrink-rpath' and `--print-rpath' now prefer + DT_RUNPATH over DT_RPATH, which is obsolete. When updating, if both + are present, both are updated. If only DT_RPATH is present, it is + converted to DT_RUNPATH unless `--force-rpath' is specified. If + neither is present, a DT_RUNPATH is added unless `--force-rpath' is + specified, in which case a DT_RPATH is added. + +0.3 (May 24, 2007): + +* Support for 64-bit ELF binaries (such as on x86_64-linux). + +* Support for big-endian ELF binaries (such as on powerpc-linux). + +* Various bugfixes. + +0.2 (January 15, 2007): + +* Provides a hack to get certain programs (such as the + Belastingaangifte 2005) to work. + +0.1 (October 11, 2005): + +* Initial release. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/patchelf-0.10/configure new/patchelf-0.11.20200609.d6b2a72/configure --- old/patchelf-0.10/configure 2019-03-28 23:23:30.000000000 +0100 +++ new/patchelf-0.11.20200609.d6b2a72/configure 2020-06-09 14:58:18.000000000 +0200 @@ -1,6 +1,6 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.69 for patchelf 0.10. +# Generated by GNU Autoconf 2.69 for patchelf 0.11.20200609.d6b2a72. # # # Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc. @@ -576,8 +576,8 @@ # Identity of this package. PACKAGE_NAME='patchelf' PACKAGE_TARNAME='patchelf' -PACKAGE_VERSION='0.10' -PACKAGE_STRING='patchelf 0.10' +PACKAGE_VERSION='0.11.20200609.d6b2a72' +PACKAGE_STRING='patchelf 0.11.20200609.d6b2a72' PACKAGE_BUGREPORT='' PACKAGE_URL='' @@ -1232,7 +1232,7 @@ # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF -\`configure' configures patchelf 0.10 to adapt to many kinds of systems. +\`configure' configures patchelf 0.11.20200609.d6b2a72 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -1298,7 +1298,7 @@ if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of patchelf 0.10:";; + short | recursive ) echo "Configuration of patchelf 0.11.20200609.d6b2a72:";; esac cat <<\_ACEOF @@ -1395,7 +1395,7 @@ test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF -patchelf configure 0.10 +patchelf configure 0.11.20200609.d6b2a72 generated by GNU Autoconf 2.69 Copyright (C) 2012 Free Software Foundation, Inc. @@ -1488,7 +1488,7 @@ This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by patchelf $as_me 0.10, which was +It was created by patchelf $as_me 0.11.20200609.d6b2a72, which was generated by GNU Autoconf 2.69. Invocation command line was $ $0 $@ @@ -2352,7 +2352,7 @@ # Define the identity of the package. PACKAGE='patchelf' - VERSION='0.10' + VERSION='0.11.20200609.d6b2a72' cat >>confdefs.h <<_ACEOF @@ -4469,7 +4469,7 @@ # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" -This file was extended by patchelf $as_me 0.10, which was +This file was extended by patchelf $as_me 0.11.20200609.d6b2a72, which was generated by GNU Autoconf 2.69. Invocation command line was CONFIG_FILES = $CONFIG_FILES @@ -4526,7 +4526,7 @@ cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" ac_cs_version="\\ -patchelf config.status 0.10 +patchelf config.status 0.11.20200609.d6b2a72 configured by $0, generated by GNU Autoconf 2.69, with options \\"\$ac_cs_config\\" diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/patchelf-0.10/patchelf.1 new/patchelf-0.11.20200609.d6b2a72/patchelf.1 --- old/patchelf-0.10/patchelf.1 1970-01-01 01:00:01.000000000 +0100 +++ new/patchelf-0.11.20200609.d6b2a72/patchelf.1 1970-01-01 01:00:01.000000000 +0100 @@ -10,6 +10,7 @@ .I OPTION .B .I FILE +.SM ... .B .SH DESCRIPTION @@ -20,7 +21,7 @@ .SH OPTIONS -The single option given operates on a given FILE, editing in place. +The single option given operates on each FILE, editing in place. .IP "--page-size SIZE" Uses the given page size instead of the default. @@ -82,6 +83,9 @@ Marks the object that the search for dependencies of this object will ignore any default library search paths. +.IP "--output FILE" +Set the output file name. If not specified, the input will be modified in place. + .IP --debug Prints details of the changes made to the input file. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/patchelf-0.10/patchelf.spec new/patchelf-0.11.20200609.d6b2a72/patchelf.spec --- old/patchelf-0.10/patchelf.spec 2019-03-28 23:23:33.000000000 +0100 +++ new/patchelf-0.11.20200609.d6b2a72/patchelf.spec 2020-06-09 14:58:21.000000000 +0200 @@ -1,7 +1,7 @@ Summary: A utility for patching ELF binaries Name: patchelf -Version: 0.10 +Version: 0.11.20200609.d6b2a72 Release: 1 License: GPL Group: Development/Tools @@ -34,5 +34,5 @@ %files %{_bindir}/patchelf -%doc %{_docdir}/patchelf/README +%doc %{_docdir}/patchelf/README.md %{_mandir}/man1/patchelf.1.gz diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/patchelf-0.10/patchelf.spec.in new/patchelf-0.11.20200609.d6b2a72/patchelf.spec.in --- old/patchelf-0.10/patchelf.spec.in 1970-01-01 01:00:01.000000000 +0100 +++ new/patchelf-0.11.20200609.d6b2a72/patchelf.spec.in 1970-01-01 01:00:01.000000000 +0100 @@ -34,5 +34,5 @@ %files %{_bindir}/patchelf -%doc %{_docdir}/patchelf/README +%doc %{_docdir}/patchelf/README.md %{_mandir}/man1/patchelf.1.gz diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/patchelf-0.10/src/patchelf.cc new/patchelf-0.11.20200609.d6b2a72/src/patchelf.cc --- old/patchelf-0.10/src/patchelf.cc 1970-01-01 01:00:01.000000000 +0100 +++ new/patchelf-0.11.20200609.d6b2a72/src/patchelf.cc 1970-01-01 01:00:01.000000000 +0100 @@ -46,6 +46,8 @@ static bool forceRPath = false; static std::vector<std::string> fileNames; +static std::string outputFileName; +static bool alwaysWrite = false; static int pageSize = PAGESIZE; typedef std::shared_ptr<std::vector<unsigned char>> FileContents; @@ -497,7 +499,9 @@ static void writeFile(std::string fileName, FileContents contents) { - int fd = open(fileName.c_str(), O_TRUNC | O_WRONLY); + debug("writing %s\n", fileName.c_str()); + + int fd = open(fileName.c_str(), O_CREAT | O_TRUNC | O_WRONLY, 0777); if (fd == -1) error("open"); @@ -742,14 +746,13 @@ since DYN executables tend to start at virtual address 0, so rewriteSectionsExecutable() won't work because it doesn't have any virtual address space to grow downwards into. */ - if (isExecutable) { - if (startOffset >= startPage) { - debug("shifting new PT_LOAD segment by %d bytes to work around a Linux kernel bug\n", startOffset - startPage); - } + if (isExecutable && startOffset > startPage) { + debug("shifting new PT_LOAD segment by %d bytes to work around a Linux kernel bug\n", startOffset - startPage); startPage = startOffset; } /* Add a segment that maps the replaced sections into memory. */ + wri(hdr->e_phoff, sizeof(Elf_Ehdr)); phdrs.resize(rdi(hdr->e_phnum) + 1); wri(hdr->e_phnum, rdi(hdr->e_phnum) + 1); Elf_Phdr & phdr = phdrs[rdi(hdr->e_phnum) - 1]; @@ -1074,13 +1077,6 @@ return; } - /* Zero out the previous SONAME */ - unsigned int sonameSize = 0; - if (soname) { - sonameSize = strlen(soname); - memset(soname, 'X', sonameSize); - } - debug("new SONAME is '%s'\n", newSoname.c_str()); /* Grow the .dynstr section to make room for the new SONAME. */ @@ -1255,7 +1251,17 @@ } - if (std::string(rpath ? rpath : "") == newRPath) return; + if (!forceRPath && dynRPath && !dynRunPath) { /* convert DT_RPATH to DT_RUNPATH */ + dynRPath->d_tag = DT_RUNPATH; + dynRunPath = dynRPath; + dynRPath = 0; + } else if (forceRPath && dynRunPath) { /* convert DT_RUNPATH to DT_RPATH */ + dynRunPath->d_tag = DT_RPATH; + dynRPath = dynRunPath; + dynRunPath = 0; + } else if (std::string(rpath ? rpath : "") == newRPath) { + return; + } changed = true; @@ -1269,15 +1275,6 @@ debug("new rpath is '%s'\n", newRPath.c_str()); - if (!forceRPath && dynRPath && !dynRunPath) { /* convert DT_RPATH to DT_RUNPATH */ - dynRPath->d_tag = DT_RUNPATH; - dynRunPath = dynRPath; - dynRPath = 0; - } - - if (forceRPath && dynRPath && dynRunPath) { /* convert DT_RUNPATH to DT_RPATH */ - dynRunPath->d_tag = DT_IGNORE; - } if (newRPath.size() <= rpathSize) { strcpy(rpath, newRPath.c_str()); @@ -1567,7 +1564,7 @@ static bool noDefaultLib = false; template<class ElfFile> -static void patchElf2(ElfFile && elfFile, std::string fileName) +static void patchElf2(ElfFile && elfFile, const FileContents & fileContents, std::string fileName) { if (printInterpreter) printf("%s\n", elfFile.getInterpreter().c_str()); @@ -1603,6 +1600,9 @@ if (elfFile.isChanged()){ elfFile.rewriteSections(); writeFile(fileName, elfFile.fileContents); + } else if (alwaysWrite) { + debug("not modified, but alwaysWrite=true\n"); + writeFile(fileName, fileContents); } } @@ -1616,11 +1616,12 @@ debug("Kernel page size is %u bytes\n", getPageSize()); auto fileContents = readFile(fileName); + std::string outputFileName2 = outputFileName.empty() ? fileName : outputFileName; if (getElfType(fileContents).is32Bit) - patchElf2(ElfFile<Elf32_Ehdr, Elf32_Phdr, Elf32_Shdr, Elf32_Addr, Elf32_Off, Elf32_Dyn, Elf32_Sym, Elf32_Verneed>(fileContents), fileName); + patchElf2(ElfFile<Elf32_Ehdr, Elf32_Phdr, Elf32_Shdr, Elf32_Addr, Elf32_Off, Elf32_Dyn, Elf32_Sym, Elf32_Verneed>(fileContents), fileContents, outputFileName2); else - patchElf2(ElfFile<Elf64_Ehdr, Elf64_Phdr, Elf64_Shdr, Elf64_Addr, Elf64_Off, Elf64_Dyn, Elf64_Sym, Elf64_Verneed>(fileContents), fileName); + patchElf2(ElfFile<Elf64_Ehdr, Elf64_Phdr, Elf64_Shdr, Elf64_Addr, Elf64_Off, Elf64_Dyn, Elf64_Sym, Elf64_Verneed>(fileContents), fileContents, outputFileName2); } } @@ -1644,9 +1645,10 @@ [--replace-needed LIBRARY NEW_LIBRARY]\n\ [--print-needed]\n\ [--no-default-lib]\n\ + [--output FILE]\n\ [--debug]\n\ [--version]\n\ - FILENAME\n", progName.c_str()); + FILENAME...\n", progName.c_str()); } @@ -1730,6 +1732,11 @@ neededLibsToReplace[ argv[i+1] ] = argv[i+2]; i += 2; } + else if (arg == "--output") { + if (++i == argc) error("missing argument"); + outputFileName = argv[i]; + alwaysWrite = true; + } else if (arg == "--debug") { debugMode = true; } @@ -1751,6 +1758,9 @@ if (fileNames.empty()) error("missing filename"); + if (!outputFileName.empty() && fileNames.size() != 1) + error("--output option only allowed with single input file"); + patchElf(); return 0; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/patchelf-0.10/tests/Makefile.am new/patchelf-0.11.20200609.d6b2a72/tests/Makefile.am --- old/patchelf-0.10/tests/Makefile.am 1970-01-01 01:00:01.000000000 +0100 +++ new/patchelf-0.11.20200609.d6b2a72/tests/Makefile.am 1970-01-01 01:00:01.000000000 +0100 @@ -21,7 +21,9 @@ src_TESTS = \ plain-fail.sh plain-run.sh shrink-rpath.sh set-interpreter-short.sh \ set-interpreter-long.sh set-rpath.sh no-rpath.sh big-dynstr.sh \ - set-rpath-library.sh soname.sh shrink-rpath-with-allowed-prefixes.sh + set-rpath-library.sh soname.sh shrink-rpath-with-allowed-prefixes.sh \ + force-rpath.sh \ + output-flag.sh build_TESTS = \ $(no_rpath_arch_TESTS) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/patchelf-0.10/tests/Makefile.in new/patchelf-0.11.20200609.d6b2a72/tests/Makefile.in --- old/patchelf-0.10/tests/Makefile.in 2019-03-28 23:23:31.000000000 +0100 +++ new/patchelf-0.11.20200609.d6b2a72/tests/Makefile.in 2020-06-09 14:58:19.000000000 +0200 @@ -343,7 +343,9 @@ src_TESTS = \ plain-fail.sh plain-run.sh shrink-rpath.sh set-interpreter-short.sh \ set-interpreter-long.sh set-rpath.sh no-rpath.sh big-dynstr.sh \ - set-rpath-library.sh soname.sh shrink-rpath-with-allowed-prefixes.sh + set-rpath-library.sh soname.sh shrink-rpath-with-allowed-prefixes.sh \ + force-rpath.sh \ + output-flag.sh build_TESTS = \ $(no_rpath_arch_TESTS) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/patchelf-0.10/tests/force-rpath.sh new/patchelf-0.11.20200609.d6b2a72/tests/force-rpath.sh --- old/patchelf-0.10/tests/force-rpath.sh 1970-01-01 01:00:00.000000000 +0100 +++ new/patchelf-0.11.20200609.d6b2a72/tests/force-rpath.sh 1970-01-01 01:00:01.000000000 +0100 @@ -0,0 +1,39 @@ +#! /bin/sh -e +SCRATCH=scratch/$(basename $0 .sh) + +rm -rf ${SCRATCH} +mkdir -p ${SCRATCH} + +SCRATCHFILE=${SCRATCH}/libfoo.so +cp libfoo.so $SCRATCHFILE + +doit() { + echo patchelf $* + ../src/patchelf $* $SCRATCHFILE +} + +expect() { + out=$(echo $(objdump -x $SCRATCHFILE | grep PATH)) + + if [ "$out" != "$*" ]; then + echo "Expected '$*' but got '$out'" + exit 1 + fi +} + +doit --remove-rpath +expect +doit --set-rpath foo +expect RUNPATH foo +doit --force-rpath --set-rpath foo +expect RPATH foo +doit --force-rpath --set-rpath bar +expect RPATH bar +doit --remove-rpath +expect +doit --force-rpath --set-rpath foo +expect RPATH foo +doit --set-rpath foo +expect RUNPATH foo +doit --set-rpath bar +expect RUNPATH bar diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/patchelf-0.10/tests/output-flag.sh new/patchelf-0.11.20200609.d6b2a72/tests/output-flag.sh --- old/patchelf-0.10/tests/output-flag.sh 1970-01-01 01:00:00.000000000 +0100 +++ new/patchelf-0.11.20200609.d6b2a72/tests/output-flag.sh 1970-01-01 01:00:01.000000000 +0100 @@ -0,0 +1,38 @@ +#! /bin/sh -e +SCRATCH=scratch/$(basename $0 .sh) + +rm -rf ${SCRATCH} +mkdir -p ${SCRATCH} +mkdir -p ${SCRATCH}/libsA +mkdir -p ${SCRATCH}/libsB + +cp main ${SCRATCH}/ +cp libfoo.so ${SCRATCH}/libsA/ +cp libbar.so ${SCRATCH}/libsB/ + +oldRPath=$(../src/patchelf --print-rpath ${SCRATCH}/main) +if test -z "$oldRPath"; then oldRPath="/oops"; fi + +../src/patchelf --force-rpath --set-rpath $oldRPath:$(pwd)/${SCRATCH}/libsA:$(pwd)/${SCRATCH}/libsB ${SCRATCH}/main --output ${SCRATCH}/main2 +# make sure it copies even when there is nothing to do (because rpath is already set) +../src/patchelf --force-rpath --set-rpath $oldRPath:$(pwd)/${SCRATCH}/libsA:$(pwd)/${SCRATCH}/libsB ${SCRATCH}/main2 --output ${SCRATCH}/main3 + +if test "$(uname)" = FreeBSD; then + export LD_LIBRARY_PATH=$(pwd)/${SCRATCH}/libsB +fi + +exitCode=0 +(cd ${SCRATCH} && ./main2) || exitCode=$? + +if test "$exitCode" != 46; then + echo "bad exit code!" + exit 1 +fi + +exitCode=0 +(cd ${SCRATCH} && ./main3) || exitCode=$? + +if test "$exitCode" != 46; then + echo "bad exit code!" + exit 1 +fi diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/patchelf-0.10/tests/set-rpath-library.sh new/patchelf-0.11.20200609.d6b2a72/tests/set-rpath-library.sh --- old/patchelf-0.10/tests/set-rpath-library.sh 1970-01-01 01:00:01.000000000 +0100 +++ new/patchelf-0.11.20200609.d6b2a72/tests/set-rpath-library.sh 1970-01-01 01:00:01.000000000 +0100 @@ -26,7 +26,6 @@ if test "$exitCode" = 46; then echo "expected failure" - exit 1 fi # So set an RUNPATH on libfoo as well. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/patchelf-0.10/version new/patchelf-0.11.20200609.d6b2a72/version --- old/patchelf-0.10/version 2019-03-28 23:23:28.000000000 +0100 +++ new/patchelf-0.11.20200609.d6b2a72/version 2020-06-09 14:58:15.000000000 +0200 @@ -1 +1 @@ -0.10 +0.11.20200609.d6b2a72