[问与答] Android Native 中编译的 binary 为什么会存在 SONAME
V2EX
2024-01-29 14:50:27
收藏
最近在移植 AOSP14 ,遇到一个百思不得其解的问题。在我此前的认知里 binary=executable=可执行文件,源码实现时一定是以 main 函数作为入口 entry 的,直到今天我发现一个有意思的程序。
前提:
运行环境:AOSP14 Cuttlefish Virtual Machine
该程序位于/apex/com.android.runtime/bin 目录,我们先用 file 命令看看:
86_64:/apex/com.android.runtime/bin # file linker64
linker64: ELF shared object, 64-bit LSB x86-64, BuildID=c8f402abba648f1ad456bbf0b9cd3e7a, not stripped
看上去正常,我们使用 readelf 查看一下:
86_64:/apex/com.android.runtime/bin # readelf -d linker64 | grep SONAME
0x000000000000000e (SONAME) Library soname: [ld-android.so]
这怎么会有个 SONAME 呢,按道理这是个 binary ,不是个 shared library,接着我们再看看其所拥有的 program headers:
86_64:/apex/com.android.runtime/bin # readelf -l linker64
Elf file type is DYN (Shared object file)
Entry point 0x68390
There are 10 program headers, starting at offset 64
Program Headers:
Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
PHDR 0x000040 0x0000000000000040 0x0000000000000040 0x00230 0x00230 R 0x8
LOAD 0x000000 0x0000000000000000 0x0000000000000000 0x46b54 0x46b54 R 0x1000
LOAD 0x046b60 0x0000000000047b60 0x0000000000047b60 0x101e10 0x101e10 R E 0x1000
LOAD 0x148970 0x000000000014a970 0x000000000014a970 0x087b8 0x087b8 RW 0x1000
LOAD 0x151140 0x0000000000154140 0x0000000000154140 0x00f70 0x0eae8 RW 0x1000
DYNAMIC 0x150d90 0x0000000000152d90 0x0000000000152d90 0x00120 0x00120 RW 0x8
GNU_RELRO 0x148970 0x000000000014a970 0x000000000014a970 0x087b8 0x09690 R 0x1
GNU_EH_FRAME 0x01c1b4 0x000000000001c1b4 0x000000000001c1b4 0x0633c 0x0633c R 0x4
GNU_STACK 0x000000 0x0000000000000000 0x0000000000000000 0x00000 0x00000 RW 0
NOTE 0x000270 0x0000000000000270 0x0000000000000270 0x00020 0x00020 R 0x4
Section to Segment mapping:
Segment Sections...
00
01 .note.gnu.build-id .dynsym .gnu.hash .dynstr .relr.dyn .rela.plt .rodata .gcc_except_table .eh_frame_hdr .eh_frame
02 .text .iplt
03 .data.rel.ro .init_array .dynamic .got .got.plt
04 .data
05 .dynamic
06 .data.rel.ro .init_array .dynamic .got .got.plt
07 .eh_frame_hdr
08
09 .note.gnu.build-id
这里我们没有找到 INTERP 字段,按照这边文章 的说法,executable 是应当包含 INTERP 字段的,而 shared library 是不包含的,所以这理应是个 shared library ?所以才会有 SONAME.
可是 shared library 是没法直接在 command line 中运行的,但是实际上又可以运行:
x86_64:/apex/com.android.runtime/bin # ./linker64 --help
Usage: ./linker64 [--list] PROGRAM [ARGS-FOR-PROGRAM...]
./linker64 [--list] path.zip!/PROGRAM [ARGS-FOR-PROGRAM...]
A helper program for linking dynamic executables. Typically, the kernel loads
this program because it's the PT_INTERP of a dynamic executable.
This program can also be run directly to load and run a dynamic executable. The
executable can be inside a zip file if it's stored uncompressed and at a
page-aligned offset.
The --list option gives behavior equivalent to ldd(1) on other systems.
所以我迷糊了,是我理解产生了偏差了么。
侵权请联系站方: [email protected]
目录
最新
- [问与答] 请教了解空气能取暖的大佬
- [推广] 推广一下自己 ? AI !写的开放招聘平台 JobNode.org
- [酷工作] [招聘] 高级渗透测试工程师 / 可谈驻场可谈远程,薪资可谈
- [问与答] 大家的主业是哪个行业的?
- [分享创造] mRNA 工具包,多合一 Messenger RNA(mRNA)分析平台
- [奇思妙想] 一个关于专门为 AI 设计 web 的设想
- [问与答] 发现一个非常诡异的证书事情,阿里云专家也没搞定,明明配置正确的但访问除了谷歌以外浏览器都无法访问
- [酷工作] [上海/可远程] 外企电商团队招 Senior Java (90%后端+10%React 维护)| 965| 35w pkg