PATCHELF(1)
π patchelf(1) β Modify ELF files, bestie β¨
okay so this is the patchelf(1) page from the User Manuals, and itβs literally about modifying ELF files. Buckle up, bestie β itβs giving βsurgery for binariesβ energy π
πΈ NAME πΈ
patchelf β Modify ELF files
β¨ SYNOPSIS β¨
patchelf OPTION FILE ...
π¦ DESCRIPTION π¦
PatchELF is literally a simple utility for modifying existing ELF executables and libraries. It can change the dynamic loader (βELF interpreterβ) of executables, and it can change the RPATH of executables and libraries. Thatβs the whole vibe, no cap.
π OPTIONS π
okay so the single option you give operates on each FILE, editing in place. Thatβs the rule, bestie β periodt π
Any option taking a string argument can also take a file by prefixing the argument with the @ symbol. See EXAMPLES for the cute little demo β¨
--page-size SIZEβ Uses the given page size instead of the default. π--set-interpreter INTERPRETERβ Change the dynamic loader (βELF interpreterβ) of executable given toINTERPRETER. Slay.--print-interpreterβ Prints the ELF interpreter of the executable.--print-os-abiβ Prints the OS ABI of the executable (EI_OSABIfield of an ELF file).--set-os-abi ABIβ Changes the OS ABI of the executable (EI_OSABIfield of an ELF file). TheABIparameter is pretty flexible. For example, you can specify it as a"Linux","linux", or even"lInUx"β all those names will setEI_OSABIfield 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. The ABI names are flexible like that β¨--print-sonameβ PrintsDT_SONAMEentry of.dynamicsection. Raises an error ifDT_SONAMEdoesn't exist. π--set-soname SONAMEβ SetsDT_SONAMEentry of a library toSONAME.--set-rpath RUNPATHβ Change theDT_RUNPATHof the executable or library toRUNPATH.--add-rpath RUNPATHβ AddRUNPATHto the existingDT_RUNPATHof the executable or library.--remove-rpathβ Removes theDT_RPATHorDT_RUNPATHentry of the executable or library.--shrink-rpathβ Remove from theDT_RUNPATHorDT_RPATHall directories that do not contain a library referenced byDT_NEEDEDfields 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". Clean that RPATH up, bestie β¨
--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. Keep the good paths, bin the bad ones π--print-rpathβ Prints theDT_RUNPATHorDT_RPATHfor an executable or library.--force-rpathβ Forces the use of the obsoleteDT_RPATHin the file instead ofDT_RUNPATH. By defaultDT_RPATHis converted toDT_RUNPATH. Obsolete, bestie β respect the vintage π--add-needed LIBRARYβ Adds a declared dependency on a dynamic library (DT_NEEDED). This option can be given multiple times.--replace-needed LIB_ORIG LIB_NEWβ Replaces a declared dependency on a dynamic library with another one (DT_NEEDED). This option can be given multiple times.--remove-needed LIBRARYβ Removes a declared dependency onLIBRARY(DT_NEEDEDentry). This option can be given multiple times.--print-neededβ Prints allDT_NEEDEDentries of the executable.--no-default-libβ Marks the object so that the search for dependencies of this object will ignore any default library search paths.--build-resolution-cacheβ Resolves eachDT_NEEDEDdependency against the object's run path at patch time and records the result in a.note.nixos.ldcachenote, so that a loader which understands the note can skip the run-path search at startup. Directories that cannot be resolved ahead of time (empty or relative components, those containing dynamic-string tokens such as$ORIGINor aglibc-hwcapssubdirectory, and paths that cannot be searched at patch time because they are missing, not a directory, or not accessible) are stored as a search hint instead of an exact path. The cache is built once from an unpatched binary; this option cannot be combined with--force-rpath. π¨--no-sortβ Do not sort program headers or section headers. This is useful when debuggingpatchelf, because it makes it easier to read diffs of the output of"readelf -a". Debugging vibe check: passed β iykyk--add-debug-tagβ AddsDT_DEBUGtag to the.dynamicsection if not yet present in an ELF object. A shared library (-shared) by default does not receiveDT_DEBUGtag. 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. π--print-execstackβ Prints the state of the executable flag of theGNU_STACKprogram header, if present.--clear-execstackβ Clears the executable flag of theGNU_STACKprogram header, or adds a new header.--set-execstackβ Sets the executable flag of theGNU_STACKprogram header, or adds a new header.--rename-dynamic-symbols NAME_MAP_FILEβ 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
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. Iconic little rename glow-up β¨
--no-clobber-old-sectionsβ Do not clobber old section values.
patchelf defaults to overwriting replaced header sections with garbage to ensure they are not used accidentally. This option allows to opt out of that behavior, so that binaries that attempt to read their own headers from a fixed offset (e.g. Firefox) continue working.
Use sparingly and with caution. π¨
--output FILEβ Set the output file name. If not specified, the input will be modified in place.--debugβ Prints details of the changes made to the input file.--versionβ Shows the version ofpatchelf.
π EXAMPLES π
To use the contents on an external file as a parameter, you literally do this:
$ patchelf a.out --add-rpath @/tmp/generated-rpath.bin
To change the RPATH of a binary, note that $ORIGIN is a special symbol used by the loader, so must be quoted. Yes, quoted, bestie β the loader is dramatic like that π
patchelf --set-rpath '$ORIGIN/../lib64' a.out
π AUTHOR π
Eelco Dolstra <e.dolstra@tudelft.nl>
π SEE ALSO π
And thatβs the whole page, bestie! This is PATCHELF, dated JULY 2022, section 1 of the User Manuals β mwah ππβ¨
π¦ where this page comes from
- arch rolling: patchelf 0.19.3-1 Β· GPL-3.0-or-later
- nixpkgs unstable: patchelf 0.19.2
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms