- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我知道动态链接器使用mmap()
来加载库。我猜是内核将可执行文件及其 .interp
reter 加载到同一地址空间,但它如何确定位置?我注意到 ld.so
在禁用 ASLR 的情况下的加载地址是 0x555555554000
(在 x86_64 上)——这个地址来自哪里?我试过遵循 do_execve()
的代码路径,但它太复杂了,我不至于被搞糊涂。
最佳答案
阅读更多关于 ELF 的信息, 特别是 elf(5) ,以及关于 execve(2)系统调用。
一个 ELF 文件可能包含一个解释器。 elf(5)提及:
PT_INTERP
The array element specifies the location and size of a null-terminated pathname to invoke as an interpreter. This segment type is meaningful only for executable files (though it may occur for shared objects). However it may not occur more than once in a file. If it is present, it must precede any loadable segment entry.
那个解释器几乎总是 ld-linux(8) (例如使用 GNU glibc ),更准确地说(在我的 Debian/Sid 上)/lib64/ld-linux-x86-64.so.2
。如果编译musl-libc然后用它构建一些软件,你会得到一个不同的解释器,/lib/ld-musl-x86_64.so.1
。那个 ELF 解释器是 dynamic linker .
execve(2)系统调用正在使用该解释器:
If the executable is a dynamically linked ELF executable, the interpreter named in the
PT_INTERP
segment is used to load the needed shared libraries. This interpreter is typically/lib/ld-linux.so.2
for binaries linked with glibc.
另请参阅 Levine 关于 Linkers and loaders 的书, 和 Drepper's paper: How To Write Shared Libraries
请注意 execve
也在处理 shebang(即第一行以 #!
开头);查看 execve(2) 的解释器脚本部分.顺便说一句,对于 ELF 二进制文件,execve
正在执行 mmap(2) 的等效在某些分割市场上。
另请阅读 vdso(7) , proc(5) & ASLR .在您的 shell 中键入 cat/proc/self/maps
。
(我猜,但我不确定,0x555555554000 地址在您的可执行文件的 ELF 程序头中,或者可能在 ld-linux.so
中;它也可能来自来自内核,因为 0x55555555 似乎出现在内核源代码中)
关于linux - Linux内核如何确定ld.so的加载地址?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29856044/
我正在尝试创建尽可能小的 ELF。我创建了一个这样的测试文件(NASM 语法): SECTION .text dd 0xdeadbeef 使用此链接描述文件: SECTIONS { .text
GNU LD 链接器命令语言是否有条件语句? 背景:我正在为 arm cortex m0+ 开发固件,该固件由引导加载程序和应用程序组成。两者都在单独的项目中进行编译和刷新,但我使用了一个框架,其中包
我很确定 ld 有一个手册页链接器脚本语法,但我找不到它。 最佳答案 如果您更喜欢比 info 更方便的东西, 这是一个可浏览的 HTML 版本:ld.info: Scripts .但它可能不是完全最
谁能解决这个练习,这样我就能明白我错在哪里,因为有太多的 LOL 变量。 生成一个 C 代码,将其放在以下表达式之前 printf ("% ld% ld% ld \ n", lol, & lol, *
在他关于理解 Linux Kernel Initcall Mechanism 的文章中, Trevor 创建了一个用户空间程序来模拟调用 linux 驱动程序的 init_module() 的机制。
/usr/bin/ld: cannot find -ldlib /usr/bin/ld: cannot find -lcblas /usr/bin/ld: cannot find -llapack 在
我想以 json-ld 格式创建一组人,但我需要保留一些键而不是使用数组,所以我首先尝试了这个: { "@context" : { "@base" : "http://www.exampl
所以我试图围绕 JSON-LD 进行思考,我看到的所有示例主要包括嵌入“链接数据”。但我想提供对链接数据的引用(主要是因为嵌入所有数据可能会产生 10MB 的有效负载)。所以我想知道我这样做是否正确。
我在这里复制了 json-ld standard 中的示例的一部分: { "@context": { "foaf": "http://xmlns.com/foaf/0.1/", "
考虑这样一个程序: #include void foo() __attribute__((__weak__)); int main() { printf("%p\n", (void *)fo
我正在尝试使用一个名为 GLV 的小部件库对于我正在开发的应用程序。我正在运行 Linux Mint 17。我安装了所有库并成功构建了 GLV 库,但是当我尝试运行已构建的示例之一时,出现了此共享库错
在将未编辑的 JSON 数据转换为 JSON-LD 时,使用前缀和数据值为对象构造 IRI 时遇到问题。我运行的示例代码是: { "@context" : { "prefix" : "
假设我有一个 JSON 对象,它在嵌套对象中包含一些属性。 { "title": "My Blog Post", "meta": { "publishedAt": "2
我是 JSON-LD 和 LOD 的新手,所以请原谅我使用的术语。我正致力于在 JSON-LD 中创建数据模型,以描述基于欧洲数据模型 (http://pro.europeana.eu/edm-doc
我有一个玩具 x86 汇编程序,我正在用 as 编写和编译它和 ld : .text .global _start _start: movq $1, %rax movq
我正在尝试创建 Google 的结构化数据,但不知道我在做什么。我将其设置为一个组织,然后将 SD 标记工具用于我的所有产品。我将每个 JSON-LD 产品直接从标记工具而不是嵌套放入它自己的脚本标签
我正在尝试创建 Google 的结构化数据,但不知道我在做什么。我将其设置为一个组织,然后将 SD 标记工具用于我的所有产品。我将每个 JSON-LD 产品直接从标记工具而不是嵌套放入它自己的脚本标签
我正在尝试使用 vcpkg 和 ndk r20 为 android arm 构建 tesseract我必须编辑 CMakeLists.txt 并添加 glob.c 和 glob.h,因为它们不在 nd
长话短说: 有没有办法让我(没有 root 访问权限)使链接器(由 gcc 调用)不知道 /etc/ld.so.conf 中包含的目录的内容 在通过 ldconfig 缓存之后? 详细说明: 我正在尝
我想将/opt/vertica/lib64 添加到系统库路径中,所以我执行以下步骤: (1) 将/opt/vertica/lib64加入/etc/ld.so.conf,运行ldconfig, (2)
我是一名优秀的程序员,十分优秀!