2010-06-10 16:55:30 +08:00
. \" Process this file with
2022-07-16 14:52:07 +08:00
. \" groff -man -Tascii patchelf.1
2010-06-10 16:55:30 +08:00
. \"
2022-07-16 14:52:07 +08:00
.TH PATCHELF 1 "JULY 2022" PATCHELF "User Manuals"
2010-06-10 16:55:30 +08:00
.SH NAME
patchelf - Modify ELF files
.SH SYNOPSIS
.B patchelf
.I OPTION
.B
.I FILE
2020-04-08 21:10:19 +08:00
.SM ...
2010-06-10 16:55:30 +08:00
.B
.SH DESCRIPTION
PatchELF is a simple utility for modifying existing ELF executables
and libraries. It can change the dynamic loader ("ELF interpreter")
of executables and change the RPATH of executables and libraries.
.SH OPTIONS
2020-04-08 21:10:19 +08:00
The single option given operates on each FILE, editing in place.
2010-06-10 16:55:30 +08:00
2021-09-11 03:28:32 +08:00
Any option taking a string argument can also take a file by prefixing the
argument with the @ symbol. See EXAMPLES
2016-01-15 09:56:04 +08:00
.IP "--page-size SIZE"
Uses the given page size instead of the default.
2010-06-10 16:55:30 +08:00
.IP "--set-interpreter INTERPRETER"
Change the dynamic loader ("ELF interpreter") of executable given to
INTERPRETER.
2014-03-29 02:26:33 +08:00
.IP --print-interpreter
2010-06-10 16:55:30 +08:00
Prints the ELF interpreter of the executable.
2022-09-17 21:20:10 +08:00
.IP --print-os-abi
Prints the OS ABI of the executable (EI_OSABI field of an ELF file).
.IP "--set-os-abi ABI"
Changes the OS ABI of the executable (EI_OSABI field of an ELF file).
The ABI parameter is pretty flexible. For example, you can specify it
as a "Linux", "linux", or even "lInUx" - all those names will set EI_OSABI
field of the ELF header to the value "3", which corresponds to Linux OS ABI.
The same applies to other ABI names - System V, FreeBSD, Solaris, etc.
2015-07-25 02:34:42 +08:00
.IP --print-soname
Prints DT_SONAME entry of .dynamic section.
Raises an error if DT_SONAME doesn't exist.
.IP "--set-soname SONAME"
Sets DT_SONAME entry of a library to SONAME.
2021-10-20 17:53:19 +08:00
.IP "--set-rpath RUNPATH"
Change the DT_RUNPATH of the executable or library to RUNPATH.
2010-06-10 16:55:30 +08:00
2021-10-20 17:53:19 +08:00
.IP "--add-rpath RUNPATH"
Add RUNPATH to the existing DT_RUNPATH of the executable or library.
2020-10-05 23:59:13 +08:00
2015-07-25 02:34:42 +08:00
.IP --remove-rpath
Removes the DT_RPATH or DT_RUNPATH entry of the executable or library.
2010-06-10 16:55:30 +08:00
.IP --shrink-rpath
2021-10-20 17:53:19 +08:00
Remove from the DT_RUNPATH or DT_RPATH all directories that do not contain a
2010-06-10 16:55:30 +08:00
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".
2016-06-04 05:25:02 +08:00
.IP "--allowed-rpath-prefixes PREFIXES"
Combined with the "--shrink-rpath" option, this 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.
2010-06-10 16:55:30 +08:00
.IP --print-rpath
2021-10-20 17:53:19 +08:00
Prints the DT_RUNPATH or DT_RPATH for an executable or library.
2010-06-10 16:55:30 +08:00
.IP --force-rpath
Forces the use of the obsolete DT_RPATH in the file instead of
DT_RUNPATH. By default DT_RPATH is converted to DT_RUNPATH.
2014-06-03 21:51:53 +08:00
.IP "--add-needed LIBRARY"
Adds a declared dependency on a dynamic library (DT_NEEDED).
2021-09-11 03:28:32 +08:00
This option can be given multiple times.
2014-06-03 21:51:53 +08:00
.IP "--replace-needed LIB_ORIG LIB_NEW"
Replaces a declared dependency on a dynamic library with another one (DT_NEEDED).
2021-09-11 03:28:32 +08:00
This option can be given multiple times.
2014-06-03 21:51:53 +08:00
2014-03-19 02:04:17 +08:00
.IP "--remove-needed LIBRARY"
2017-04-04 18:37:43 +08:00
Removes a declared dependency on LIBRARY (DT_NEEDED entry). This
2014-03-19 02:04:17 +08:00
option can be given multiple times.
2013-12-18 04:05:16 +08:00
2022-05-04 01:44:11 +08:00
.IP --print-needed
Prints all DT_NEEDED entries of the executable.
2014-10-23 01:41:47 +08:00
.IP "--no-default-lib"
2021-08-26 06:02:55 +08:00
Marks the object so that the search for dependencies of this object will ignore any
2014-10-23 01:41:47 +08:00
default library search paths.
2022-06-19 13:42:16 +08:00
.IP "--no-sort"
Do not sort program headers or section headers. This is useful when
debugging patchelf, because it makes it easier to read diffs of the
output of "readelf -a".
2022-02-22 02:36:54 +08:00
.IP "--add-debug-tag"
Adds DT_DEBUG tag to the .dynamic section if not yet present in an ELF
object. A shared library (-shared) by default does not receive DT_DEBUG tag.
This means that when a shared library has an entry point (so that it
can be run as an executable), the debugger does not connect to it correctly and
symbols are not resolved.
2023-01-28 00:15:02 +08:00
.IP "--print-execstack"
Prints the state of the executable flag of the GNU_STACK program header, if present.
.IP "--clear-execstack"
Clears the executable flag of the GNU_STACK program header, or adds a new header.
.IP "--set-execstack"
Sets the executable flag of the GNU_STACK program header, or adds a new header.
2023-02-21 06:32:47 +08:00
.IP "--rename-dynamic-symbols NAME_MAP_FILE"
2023-02-21 17:12:44 +08:00
Renames dynamic symbols. The name map file should contain lines
with the old and the new name separated by spaces like this:
old_name new_name
2023-02-21 06:32:47 +08:00
2023-02-22 17:10:33 +08:00
Symbol names do not contain version specifier that are also shown in the output of the nm -D command from binutils. So instead of the name write@GLIBC_2.2.5 it is just write.
2020-05-30 06:35:56 +08:00
.IP "--output FILE"
Set the output file name. If not specified, the input will be modified in place.
2010-06-10 16:55:30 +08:00
.IP --debug
Prints details of the changes made to the input file.
.IP --version
Shows the version of patchelf.
2021-09-11 03:28:32 +08:00
.SH EXAMPLES
To use the contents on an external file as a parameter:
.RS
$ patchelf a.out --add-rpath @/tmp/generated-rpath.bin
.RE
To change the RPATH of a binary. Note that
.BR $ORIGIN
is a special symbol used by the loader, so must be quoted.
.RS
patchelf --set-rpath '$ORIGIN/../lib64' a.out
.RE
2010-06-10 16:55:30 +08:00
.SH AUTHOR
Eelco Dolstra <e.dolstra@tudelft.nl>
.SH "SEE ALSO"
.BR elf (5),
.BR ld.so (8)