linux 修改 elf 文件的dynamic linker 和 rpath
linux 修改 elf 文件的dynamic linker 和 rpath
https://nixos.org/patchelf.html
下载地址
https://nixos.org/releases/patchelf/patchelf-0.9/patchelf-0.9.tar.gz
https://nixos.org/releases/patchelf/patchelf-0.9/patchelf-0.9.tar.bz2
PatchELF
PatchELF is a small utility to modify the dynamic linker and RPATH of ELF executables.
Description
Dynamically linked ELF executables always specify a dynamic linker or interpreter, which is a program that actually loads the executable along with all its dynamically linked libraries. (The kernel just loads the interpreter, not the executable.) For example, on a Linux/x86 system the ELF interpreter is typically the file /lib/ld-linux.so.2. It is sometimes necessary to use a different ELF interpreter, say, when you want to test a version of Glibc installed in a location other than /lib. And in the Nix Packages collection we build our own Glibc, which we obviously want to use. Building programs with a different interpreter is a matter of using the linker flag -dynamic-linker:
gcc -Wl,-dynamic-linker,/my/lib/ld-linux.so.2 ...
However, this doesn’t work with third-party binaries (such as Adobe Reader in Nixpkgs). This is where PatchELF comes in. You can simply rewrite the executable:
patchelf --set-interpreter /my/lib/my-ld-linux.so.2 program
This modifies the interpreter section of program to refer to the specified file. This is not quite trivial because the path of the new interpreter may be longer than the old one, in which case it won’t fit. PatchELF takes care of “growing” the executable with sufficient space at the beginning to contain the new interpreter field. As a result, the resulting program may be one page (4 KiB) larger.
Likewise, you can change the RPATH, the linker search path embedded into executables and dynamic libraries:
patchelf --set-rpath /opt/my-libs/lib:/foo/lib program
This causes the dynamic linker to search in /opt/my-libs/lib and /foo/lib for the shared libraries needed by program. Of course, you could also set the environment variable LD_LIBRARY_PATH, but that’s often inconvenient as it requires a wrapper script to set up the environment.
Finally, it is possible to remove unused paths from the RPATH:
patchelf --shrink-rpath program
A path is considered unused if none of the program’s library dependencies can be found in that path. This is primarily useful in the standard build environment of Nixpkgs, where it is used to get rid of unnecessary runtime dependencies.
Compatibility
PatchELF has been tested on i386-linux, x86_64-linux and powerpc-linux. It should definitely work on all 32 or 64-bit, big or little-endian Linux platforms. With minor modifications it should also work on other ELF platforms.
Download
The most recent stable release is PatchELF 0.9.
Unstable releases
You can get the latest source code of PatchELF from its Git repository. You can also download the latest pre-release, or view a list of all prereleases built in our build farm.
Bugs
You can report bugs in the issue tracker.
$ ./patchelf --help
syntax: ./patchelf
[--set-interpreter FILENAME]
[--page-size SIZE]
[--print-interpreter]
[--print-soname] Prints 'DT_SONAME' entry of .dynamic section. Raises an error if DT_SONAME doesn't exist
[--set-soname SONAME] Sets 'DT_SONAME' entry to SONAME.
[--set-rpath RPATH]
[--remove-rpath]
[--shrink-rpath]
[--print-rpath]
[--force-rpath]
[--add-needed LIBRARY]
[--remove-needed LIBRARY]
[--replace-needed LIBRARY NEW_LIBRARY]
[--print-needed]
[--no-default-lib]
[--debug]
[--version]
FILENAME
================= End
linux 修改 elf 文件的dynamic linker 和 rpath的更多相关文章
- Linux修改profile文件改错了,恢复的方法
Linux修改profile文件改错了,恢复的方法在改profile的时候,改出问题了,除了cd以外的命令基本都不能用了,连vi都不能用了,上网查了下,用export PATH=/usr/bin:/u ...
- Linux之ELF文件初探
对比windowsPE文件与概述 在windows中可执行文件是pe文件格式,Linux中可执行文件是ELF文件,其文件格式是ELF文件格式,在Linux下的ELF文件除了可执行文件(Excutabl ...
- linux 修改目录文件权限,目录文件所属用户,用户组
1:查看命令:ll drwxr-xr-x 4 gamer ftp 4096 Mar 7 16:56 gstore drwxrwxrwx 10 root ftp 4096 De ...
- Linux 修改hostname 文件
linux 的机器修改hostname: 修改 /etc/hosts 修改 /etc/sysconfig/network 重启机器reboot
- Linux 修改默认文件关联打开程序
从总体上讲 /etc/gnome/defaults.list 保存了全局的打开方式-/.local/share/applications/mimeapps.list 保存了个人的打开方式当这两个文件不 ...
- linux 修改hosts文件
1.修改hostssudo gedit /etc/hosts2.添加解析记录( . )完整案例:127.0.0.1 localhost.localdomain localhost简洁记录:127.0. ...
- 利用linux判断elf文件是64位还是32位
readelf 命令,参数为-h 例如 文件名为python >>>readelf -h python 得到的是ELF Header中的项Magic 第五个数 02时为64位,01时 ...
- ELF文件的加载过程(load_elf_binary函数详解)--Linux进程的管理与调度(十三)
加载和动态链接 从编译/链接和运行的角度看,应用程序和库程序的连接有两种方式. 一种是固定的.静态的连接,就是把需要用到的库函数的目标代码(二进制)代码从程序库中抽取出来,链接进应用软件的目标映像中: ...
- Linux 可执行文件 ELF结构 及程序载入执行
Linux下ELF文件类型分为以下几种: 1.可重定位文件,比如SimpleSection.o: 2.可运行文件,比如/bin/bash. 3.共享目标文件,比如/lib/libc.so. 在Linu ...
随机推荐
- RHCE-EXAM 模拟题目
真实考试环境说明: 你考试所用的真实物理机器会使用普通账号自动登陆,登陆后,桌面会有两个虚拟主机图标,分别是system1和system2.所有的考试操作都是在system1和system2上完成.S ...
- RHCSA-day3
10.配置LDAP客户端 在classroom.example.com上已经部署了一台LDAP认证服务器,按以下要求将你的系统加入到该LDAP服务中,并使用Kerberos认证用户密码: 该LDAP认 ...
- mysql 错误代码 1248
1248 - Every derived table must have its own alias (MYSQL错误) 这句话的意思是说每个派生出来的表都必须有一个自己的别名,给派生表加上一个别名就 ...
- unity游戏在ios11上不显示泰语解决办法
最近在开发中遇到unity游戏在ios11上不显示泰语的问题,全部显示为方框内一个问号. 通过搜索发现这是Unity的一个bug,在2017.3中修复了 但升级unity风险很大,所以我采用了该文中提 ...
- pytest使用笔记(一)
使用环境及预置条件:pycharm+win10+python3.6+pytest 1,创建示范的测试功能脚本,另存为test_sample.py,代码如下: # test_sample.py def ...
- CentOS7.2安装mysql-5.7.19多实例
安装多实例之前首先需要先安装mysql,这里就不介绍如何安装mysql了,参考前面的博客:https://www.cnblogs.com/hei-ma/p/9505509.html 安装多实例之前需要 ...
- Laxcus大数据操作系统单机集群版
Laxcus大数据管理系统是我们Laxcus大数据实验室历时5年,全体系全功能设计研发的大数据产品,目前的最新版本是2.1版本.从三年前的1.0版本开始,Laxcus大数据系统投入到多个大数据和云计算 ...
- Tess4J -4.0.2- Linux 实践 [解决:Tess4J - Native library (linux-x86-64/libtesseract.so) not found in resource path]
[本文编写于2018年7月5日] Tess4J是Tesseract的Java JNA wrapper.本文介绍了在CentOS 7 操作系统中使用Tess4J的步骤及注意事项.在正式开始之前,先花一点 ...
- 一个简单的rest_framework demo
models.py from django.db import models class UserInfo(models.Model): username = models.CharField(max ...
- WEB前端开发流程总结
作者声明:本博客中所写的文章,都是博主自学过程的笔记,参考了很多的学习资料,学习资料和笔记会注明出处,所有的内容都以交流学习为主.有不正确的地方,欢迎批评指正 WEB前端开发项目流程总结 1.新建项目 ...