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 ...
随机推荐
- OpenStack入门篇(五)之KVM性能优化及IO缓存介绍
1.KVM的性能优化,介绍CPU,内存,IO性能优化 KVM CPU-->qemu进行模拟ring 3-->用户应用 (用户态,用户空间)ring 0-->操作系统 (内核态,内核空 ...
- Error running 'Tomcat 7': Unable to open debugger port (127.0.0.1:9342)
这个只需要把java虚拟机进程结束掉就行了
- 获取文件mimes
<?php /* * Copyright 2010-2013 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Licen ...
- HTML中CSS入门基础
HTML.CSS 实用css有三种格式:内嵌:内联:外部: 分类:内联:写在标记的属性位置,优先级最高,重用性最差内嵌:写在页面的head中,优先级第二,重用性一般外部:写在一个以css结尾的文件中, ...
- 小计Tomcat的调优思路
描述 最近在补充自己的短板,刚好整理到Tomcat调优这块,基本上面试必问,于是就花了点时间去搜集一下tomcat调优 都调了些什么,先记录一下调优手段,更多详细的原理和实现以后用到时候再来补充记录, ...
- 一个IP可以登几个拼多多后台 拼多多如何推广营销
想要在拼多多上开双店?担心一根网线会引起IP冲突?那么一根网线可以登几个拼多多后台呢?有数据显示,挂双店是没有问题的,甚至可以多开.那么解决了一根网线的事情,要怎么对自己的店铺进行营销推广呢?下面是小 ...
- linux 下 python 安装 Django
安装 setuptools 使用easy_install命令 easy_install django
- Kubernetes-----Endpoints
Endpoints是实现实际服务的端点集合. Kubernetes在创建Service时,根据Service的标签选择器(Label Selector)来查找Pod,据此创建与Service同名的En ...
- less 语法特性翻译稿 - 特性快速预览部分
原文地址 http://lesscss.cn/features/ 概述 作为CSS的一种扩展语法,Less不仅仅向后兼容CSS,新的特性也是基于CSS现有语法.这使得学习Less变得容易,如果你有所怀 ...
- 4th 课堂SCRM会议旁观记录
项目名称:基于C#的连连看设计 小组名称:待定 小组成员:张政.张金生.武志远.李权 Master:张政 项目已完成部分: 现阶段已经实现了一定的功能,可以运行使用,进行第一关的游戏. 今天计划要完成 ...