1PATCHELF(1)                      User Manuals                      PATCHELF(1)
2
3
4

NAME

6       patchelf - Modify ELF files
7
8

SYNOPSIS

10       patchelf OPTION FILE ...
11
12

DESCRIPTION

14       PatchELF is a simple utility for modifying existing ELF executables and
15       libraries.  It can change the dynamic loader ("ELF interpreter") of ex‐
16       ecutables and change the RPATH of executables and libraries.
17
18

OPTIONS

20       The single option given operates on each FILE, editing in place.
21
22       Any  option  taking a string argument can also take a file by prefixing
23       the argument with the @ symbol. See EXAMPLES
24
25
26       --page-size SIZE
27              Uses the given page size instead of the default.
28
29
30       --set-interpreter INTERPRETER
31              Change the dynamic  loader  ("ELF  interpreter")  of  executable
32              given to INTERPRETER.
33
34
35       --print-interpreter
36              Prints the ELF interpreter of the executable.
37
38
39       --print-os-abi
40              Prints  the  OS  ABI of the executable (EI_OSABI field of an ELF
41              file).
42
43
44       --set-os-abi ABI
45              Changes the OS ABI of the executable (EI_OSABI field of  an  ELF
46              file).   The  ABI parameter is pretty flexible. For example, you
47              can specify it as a "Linux", "linux",  or  even  "lInUx"  -  all
48              those  names  will  set  EI_OSABI field of the ELF header to the
49              value "3", which corresponds to Linux OS ABI.  The same  applies
50              to other ABI names - System V, FreeBSD, Solaris, etc.
51
52
53       --print-soname
54              Prints  DT_SONAME entry of .dynamic section.  Raises an error if
55              DT_SONAME doesn't exist.
56
57
58       --set-soname SONAME
59              Sets DT_SONAME entry of a library to SONAME.
60
61
62       --set-rpath RUNPATH
63              Change the DT_RUNPATH of the executable or library to RUNPATH.
64
65
66       --add-rpath RUNPATH
67              Add RUNPATH to the existing DT_RUNPATH of the executable or  li‐
68              brary.
69
70
71       --remove-rpath
72              Removes  the  DT_RPATH  or DT_RUNPATH entry of the executable or
73              library.
74
75
76       --shrink-rpath
77              Remove from the DT_RUNPATH or DT_RPATH all directories  that  do
78              not contain a library referenced by DT_NEEDED fields of the exe‐
79              cutable or library.
80
81              For instance, if an executable references one library libfoo.so,
82              has an RPATH "/lib:/usr/lib:/foo/lib", and libfoo.so can only be
83              found in /foo/lib, then the new RPATH will be "/foo/lib".
84
85
86       --allowed-rpath-prefixes PREFIXES
87              Combined with the "--shrink-rpath" option, this can be used  for
88              further  rpath  tuning.  For  instance,  if an executable has an
89              RPATH "/tmp/build-foo/.libs:/foo/lib", it is probably  desirable
90              to keep the "/foo/lib" reference instead of the "/tmp" entry.
91
92
93       --print-rpath
94              Prints the DT_RUNPATH or DT_RPATH for an executable or library.
95
96
97       --force-rpath
98              Forces  the  use of the obsolete DT_RPATH in the file instead of
99              DT_RUNPATH. By default DT_RPATH is converted to DT_RUNPATH.
100
101
102       --add-needed LIBRARY
103              Adds a declared dependency on  a  dynamic  library  (DT_NEEDED).
104              This option can be given multiple times.
105
106
107       --replace-needed LIB_ORIG LIB_NEW
108              Replaces a declared dependency on a dynamic library with another
109              one (DT_NEEDED).  This option can be given multiple times.
110
111
112       --remove-needed LIBRARY
113              Removes a declared dependency on LIBRARY (DT_NEEDED entry). This
114              option can be given multiple times.
115
116
117       --print-needed
118              Prints all DT_NEEDED entries of the executable.
119
120
121       --no-default-lib
122              Marks the object so that the search for dependencies of this ob‐
123              ject will ignore any default library search paths.
124
125
126       --no-sort
127              Do not sort program headers or section headers.  This is  useful
128              when  debugging  patchelf,  because  it  makes it easier to read
129              diffs of the output of "readelf -a".
130
131
132       --add-debug-tag
133              Adds DT_DEBUG tag to the .dynamic section if not yet present  in
134              an  ELF  object.  A shared library (-shared) by default does not
135              receive DT_DEBUG tag.  This means that when a shared library has
136              an entry point (so that it can be run as an executable), the de‐
137              bugger does not connect to it correctly and symbols are not  re‐
138              solved.
139
140
141       --print-execstack
142              Prints the state of the executable flag of the GNU_STACK program
143              header, if present.
144
145
146       --clear-execstack
147              Clears the executable flag of the GNU_STACK program  header,  or
148              adds a new header.
149
150
151       --set-execstack
152              Sets  the  executable  flag  of the GNU_STACK program header, or
153              adds a new header.
154
155
156       --rename-dynamic-symbols NAME_MAP_FILE
157              Renames dynamic symbols. The name map file should contain  lines
158              with the old and the new name separated by spaces like this:
159
160              old_name new_name
161
162              Symbol  names  do  not  contain  version specifier that are also
163              shown in the output of the nm -D command from binutils.  So  in‐
164              stead of the name write@GLIBC_2.2.5 it is just write.
165
166
167       --output FILE
168              Set  the  output file name.  If not specified, the input will be
169              modified in place.
170
171
172       --debug
173              Prints details of the changes made to the input file.
174
175
176       --version
177              Shows the version of patchelf.
178
179

EXAMPLES

181       To use the contents on an external file as a parameter:
182
183              $ patchelf a.out --add-rpath @/tmp/generated-rpath.bin
184
185       To change the RPATH of a binary. Note that $ORIGIN is a special  symbol
186       used by the loader, so must be quoted.
187
188              patchelf --set-rpath '$ORIGIN/../lib64' a.out
189
190
191

AUTHOR

193       Eelco Dolstra <e.dolstra@tudelft.nl>
194
195

SEE ALSO

197       elf(5), ld.so(8)
198
199
200
201
202
203PATCHELF                           JULY 2022                       PATCHELF(1)
Impressum