1PATCHELF(1) User Manuals PATCHELF(1)
2
3
4
6 patchelf - Modify ELF files
7
8
10 patchelf OPTION FILE ...
11
12
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
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-soname
40 Prints DT_SONAME entry of .dynamic section. Raises an error if
41 DT_SONAME doesn't exist.
42
43
44 --set-soname SONAME
45 Sets DT_SONAME entry of a library to SONAME.
46
47
48 --set-rpath RUNPATH
49 Change the DT_RUNPATH of the executable or library to RUNPATH.
50
51
52 --add-rpath RUNPATH
53 Add RUNPATH to the existing DT_RUNPATH of the executable or li‐
54 brary.
55
56
57 --remove-rpath
58 Removes the DT_RPATH or DT_RUNPATH entry of the executable or
59 library.
60
61
62 --shrink-rpath
63 Remove from the DT_RUNPATH or DT_RPATH all directories that do
64 not contain a library referenced by DT_NEEDED fields of the exe‐
65 cutable or library.
66
67 For instance, if an executable references one library libfoo.so,
68 has an RPATH "/lib:/usr/lib:/foo/lib", and libfoo.so can only be
69 found in /foo/lib, then the new RPATH will be "/foo/lib".
70
71
72 --allowed-rpath-prefixes PREFIXES
73 Combined with the "--shrink-rpath" option, this can be used for
74 further rpath tuning. For instance, if an executable has an
75 RPATH "/tmp/build-foo/.libs:/foo/lib", it is probably desirable
76 to keep the "/foo/lib" reference instead of the "/tmp" entry.
77
78
79 --print-rpath
80 Prints the DT_RUNPATH or DT_RPATH for an executable or library.
81
82
83 --force-rpath
84 Forces the use of the obsolete DT_RPATH in the file instead of
85 DT_RUNPATH. By default DT_RPATH is converted to DT_RUNPATH.
86
87
88 --add-needed LIBRARY
89 Adds a declared dependency on a dynamic library (DT_NEEDED).
90 This option can be given multiple times.
91
92
93 --replace-needed LIB_ORIG LIB_NEW
94 Replaces a declared dependency on a dynamic library with another
95 one (DT_NEEDED). This option can be given multiple times.
96
97
98 --remove-needed LIBRARY
99 Removes a declared dependency on LIBRARY (DT_NEEDED entry). This
100 option can be given multiple times.
101
102
103 --print-needed
104 Prints all DT_NEEDED entries of the executable.
105
106
107 --no-default-lib
108 Marks the object so that the search for dependencies of this ob‐
109 ject will ignore any default library search paths.
110
111
112 --no-sort
113 Do not sort program headers or section headers. This is useful
114 when debugging patchelf, because it makes it easier to read
115 diffs of the output of "readelf -a".
116
117
118 --add-debug-tag
119 Adds DT_DEBUG tag to the .dynamic section if not yet present in
120 an ELF object. A shared library (-shared) by default does not
121 receive DT_DEBUG tag. This means that when a shared library has
122 an entry point (so that it can be run as an executable), the de‐
123 bugger does not connect to it correctly and symbols are not re‐
124 solved.
125
126
127 --output FILE
128 Set the output file name. If not specified, the input will be
129 modified in place.
130
131
132 --debug
133 Prints details of the changes made to the input file.
134
135
136 --version
137 Shows the version of patchelf.
138
139
141 To use the contents on an external file as a parameter:
142
143 $ patchelf a.out --add-rpath @/tmp/generated-rpath.bin
144
145 To change the RPATH of a binary. Note that $ORIGIN is a special symbol
146 used by the loader, so must be quoted.
147
148 patchelf --set-rpath '$ORIGIN/../lib64' a.out
149
150
151
153 Eelco Dolstra <e.dolstra@tudelft.nl>
154
155
157 elf(5), ld.so(8)
158
159
160
161
162
163PATCHELF JUNE 2010 PATCHELF(1)