PatchELF: Difference between revisions

From HPCWIKI
Jump to navigation Jump to search
(Add categories: Linux, Reference)
(Template migration to LLM-Optimized Wiki Template)
Line 1: Line 1:
{{Status
|status=Draft
|owner=Knowledge Agent
|last_update=2026-07-16
|review=Pending
}}
{{TOC}}
== Overview ==
PatchELF에 대한 기술 문서입니다.
=== Summary ===
* 무엇인가? - PatchELF
* 왜 필요한가? - HPC 및 서버 환경에서 필수 개념
* 언제 사용하는가? - 서버 구성, 성능 튜닝, 문제 해결 시
---
== Purpose ==
이 문서가 존재하는 이유
* Goal: PatchELF에 대한 기술 정보 제공
* Scope: PatchELF의 개념, 사용법, 설정
* Non-goals: 다른 주제로의 확장
---
== Key Concepts ==
{| class="wikitable"
! Concept
! Description
! Related
|-
| PatchELF
| HPC/서버 환경에서 중요한 기술 개념
| [[Linux]], [[Server]]
|}
---
== Detailed Explanation ==
What if an application binary app uses glibc version 2.22 and you need to configure it to use glibc 2.25 '''without recompiling the binary ? PatchELF comes to play with it.'''
What if an application binary app uses glibc version 2.22 and you need to configure it to use glibc 2.25 '''without recompiling the binary ? PatchELF comes to play with it.'''
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  * Change the [[RPATH]] of executables and libraries  * Remove declared dependencies on dynamic libraries    (DT_NEEDED entries)  
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  * Change the [[RPATH]] of executables and libraries  * Remove declared dependencies on dynamic libraries    (DT_NEEDED entries)  
=== Install patchelf is simple on Ubuntu ===
  sudo apt update
  sudo apt update
  sudo apt install patchelf
  sudo apt install patchelf
<blockquote><code>$ patchelf --set-interpreter /lib/my-ld-linux.so.2 my-program</code></blockquote>
<blockquote><code>$ patchelf --set-rpath /opt/my-libs/lib:/other-libs my-program</code></blockquote>
<blockquote>$ [[patchelf]] --shrink-rpath my-program</blockquote>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:<blockquote>$ patchelf --shrink-rpath --allowed-rpath-prefixes /usr/lib:/foo/lib my-program</blockquote>
<blockquote>$ patchelf --remove-needed libfoo.so.1 my-program</blockquote>This option can be given multiple times.
<blockquote>$ patchelf --add-needed libfoo.so.1 my-program</blockquote>This option can be give multiple times.
<blockquote>$ patchelf --replace-needed liboriginal.so.1 libreplacement.so.1 my-program</blockquote>This option can be give multiple times.
<blockquote>$ patchelf --set-soname libnewname.so.3.4.5 path/to/libmylibrary.so.1.2.3</blockquote>
https://manpages.ubuntu.com/manpages/bionic/man1/patchelf.1.html
https://anaconda.org/conda-forge/patchelf


=== Change the dynamic loader ("ELF interpreter") of executables:<ref>https://github.com/miko-ai/patchelf</ref> <ref>https://github.com/NixOS/patchelf</ref> ===
---
<blockquote><code>$ patchelf --set-interpreter /lib/my-ld-linux.so.2 my-program</code></blockquote>


=== Change the RPATH of executables and libraries: ===
== Best Practices ==
<blockquote><code>$ patchelf --set-rpath /opt/my-libs/lib:/other-libs my-program</code></blockquote>


=== Shrink the RPATH of executables and libraries: ===
* 최신 버전 사용 권장
<blockquote>$ [[patchelf]] --shrink-rpath my-program</blockquote>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:<blockquote>$ patchelf --shrink-rpath --allowed-rpath-prefixes /usr/lib:/foo/lib my-program</blockquote>
---


=== Remove declared dependencies on dynamic libraries (DT_NEEDED entries): ===
== References ==
<blockquote>$ patchelf --remove-needed libfoo.so.1 my-program</blockquote>This option can be given multiple times.


=== Add a declared dependency on a dynamic library (DT_NEEDED): ===
* [https://wiki.hpcmate.com PatchELF]
<blockquote>$ patchelf --add-needed libfoo.so.1 my-program</blockquote>This option can be give multiple times.


=== Replace a declared dependency on a dynamic library with another one (DT_NEEDED): ===
---
<blockquote>$ patchelf --replace-needed liboriginal.so.1 libreplacement.so.1 my-program</blockquote>This option can be give multiple times.


=== Change SONAME of a dynamic library: ===
== Related Pages ==
<blockquote>$ patchelf --set-soname libnewname.so.3.4.5 path/to/libmylibrary.so.1.2.3</blockquote>


== Reference ==
* [[Linux]]
https://manpages.ubuntu.com/manpages/bionic/man1/patchelf.1.html
* [[Server]]
* [[Hardware]]
* [[Network]]


https://anaconda.org/conda-forge/patchelf
---
[[Category:Linux]]


[[Category:Server]]
[[Category:Reference]]
[[Category:Reference]]

Revision as of 15:25, 16 July 2026

Template:Status

Template:TOC

Overview

PatchELF에 대한 기술 문서입니다.

Summary

  • 무엇인가? - PatchELF
  • 왜 필요한가? - HPC 및 서버 환경에서 필수 개념
  • 언제 사용하는가? - 서버 구성, 성능 튜닝, 문제 해결 시

---

Purpose

이 문서가 존재하는 이유

  • Goal: PatchELF에 대한 기술 정보 제공
  • Scope: PatchELF의 개념, 사용법, 설정
  • Non-goals: 다른 주제로의 확장

---

Key Concepts

Concept Description Related
PatchELF HPC/서버 환경에서 중요한 기술 개념 Linux, Server

---

Detailed Explanation

What if an application binary app uses glibc version 2.22 and you need to configure it to use glibc 2.25 without recompiling the binary ? PatchELF comes to play with it. 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 * Change the RPATH of executables and libraries * Remove declared dependencies on dynamic libraries (DT_NEEDED entries)

sudo apt update
sudo apt install patchelf

$ patchelf --set-interpreter /lib/my-ld-linux.so.2 my-program

$ patchelf --set-rpath /opt/my-libs/lib:/other-libs my-program

$ 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

$ patchelf --remove-needed libfoo.so.1 my-program

This option can be given multiple times.

$ patchelf --add-needed libfoo.so.1 my-program

This option can be give multiple times.

$ patchelf --replace-needed liboriginal.so.1 libreplacement.so.1 my-program

This option can be give multiple times.

$ patchelf --set-soname libnewname.so.3.4.5 path/to/libmylibrary.so.1.2.3

https://manpages.ubuntu.com/manpages/bionic/man1/patchelf.1.html https://anaconda.org/conda-forge/patchelf

---

Best Practices

  • 최신 버전 사용 권장
  • 공식 문서 참고
  • 테스트 환경에서 먼저 검증

---

References

---

Related Pages

---