in my program, two "so" - libcpss.so and libhelper.so have to be loaded into a fixed virtual address, it’s done by the ld script,
SECTIONS
{
/* Code section, access rights RX */
. = 0x14600000;
…
}
readelf -l libhelper.so | less
Elf file type is DYN (Shared object file) Entry point 0x14607ad8 There are 8 program headers, starting at offset 64
Program Headers:
Type Offset VirtAddr PhysAddr
FileSiz MemSiz Flags Align
LOAD 0x0000000000010000 0x0000000014600000 0x0000000014600000
0x000000000001aaec 0x000000000001aaec R E 0x10000
an elf program linked with these two ".so", we can see the two so indeed were loaded into the expected fixed address,
ldd ./appDemo
linux-vdso.so.1 => (0x0000ffff917ec000)
libcpss.so => ./libcpss.so (0x0000000010000000)
libhelper.so => ./libhelper.so (0x0000000014600000)
libpthread.so.0 => /lib/aarch64-linux-gnu/libpthread.so.0 (0x0000ffff917b5000)
librt.so.1 => /lib/aarch64-linux-gnu/librt.so.1 (0x0000ffff9179d000)
libdl.so.2 => /lib/aarch64-linux-gnu/libdl.so.2 (0x0000ffff91789000)
libm.so.6 => /lib/aarch64-linux-gnu/libm.so.6 (0x0000ffff916d7000)
libc.so.6 => /lib/aarch64-linux-gnu/libc.so.6 (0x0000ffff91583000)
/lib/ld-linux-aarch64.so.1 (0x0000aaaadd94f000)
however, i built another "so" that linking(depending on) these two so, seems not able to load these two so into proper fixed address, see below -
ldd ./libtestScript.so
linux-vdso.so.1 => (0x0000ffff8d87c000)
libcpss.so => ./libcpss.so (0x0000ffff89d50000)
libhelper.so => ./libhelper.so (0x0000ffff5e350000)
libpthread.so.0 => /lib/aarch64-linux-gnu/libpthread.so.0 (0x0000ffff5e31c000)
librt.so.1 => /lib/aarch64-linux-gnu/librt.so.1 (0x0000ffff5e304000)
libdl.so.2 => /lib/aarch64-linux-gnu/libdl.so.2 (0x0000ffff5e2f0000)
libm.so.6 => /lib/aarch64-linux-gnu/libm.so.6 (0x0000ffff5e23e000)
libc.so.6 => /lib/aarch64-linux-gnu/libc.so.6 (0x0000ffff5e0ea000)
/lib/ld-linux-aarch64.so.1 (0x0000aaaae0958000)
do i missed any LD flags during building of the “joint .so" ? i saw the only difference between elf main program and “joint” so is the flag of “-shared”, so why “joint .so" missed the info of the two dependent so’s loading address? seems when the ld.so load "joint .so" and try to resolve and load the dependency two ".so", but it doesn't load them into the fixed address(0x10000000 / 0x14600000)
NOK: LD_DEBUG=all ldd ./libtestScript.so
2349: file=libhelper.so [0]; generating link map
2349: dynamic: 0x0000ffff5d581ba0 base: 0x0000ffff48f57000 size: 0x000000002b9ff004
2349: entry: 0x0000ffff5d55ead8 phdr: 0x0000ffff8ca6fcc0 phnum: 8
OK: LD_DEBUG=all ldd ./appDemo
2289: trying file=./libhelper.so
2289:
2289: file=libhelper.so [0]; generating link map
2289: dynamic: 0x000000001462aba0 base: 0x0000000000000000 size: 0x000000002b9ff004
2289: entry: 0x0000000014607ad8 phdr: 0x0000ffffb2e24cc0 phnum: 8
readelf -h ./libhelper.so
ELF Header:
Magic: 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00
Class: ELF64
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: DYN (Shared object file)
Machine: AArch64
Version: 0x1
Entry point address: 0x14607ad8
Start of program headers: 64 (bytes into file)
Start of section headers: 228680 (bytes into file)
Flags: 0x0
Size of this header: 64 (bytes)
Size of program headers: 56 (bytes)
Number of program headers: 8
Size of section headers: 64 (bytes)
Number of section headers: 34
Section header string table index: 31
i appreciate if you can help me out. Best regards Xinghao Chen
after adding the flag of -Wl,-Ttext-segment=0xXXXXXXXX(e.g. 0x70000000) when generating libtestScript.so, the result shows as expected:
ldd libtestScript.so
linux-vdso.so.1 (0x0000007fa6f04000)
libcpss.so => ./libcpss.so (0x0000000010000000)
libhelper.so => ./libhelper.so (0x0000000014600000)
libpthread.so.0 => /lib/aarch64-linux-gnu/libpthread.so.0 (0x0000007fa6ece000)
librt.so.1 => /lib/aarch64-linux-gnu/librt.so.1 (0x0000007fa6eb7000)
libdl.so.2 => /lib/aarch64-linux-gnu/libdl.so.2 (0x0000007fa6ea2000)
libm.so.6 => /lib/aarch64-linux-gnu/libm.so.6 (0x0000007fa6de6000)
libc.so.6 => /lib/aarch64-linux-gnu/libc.so.6 (0x0000007fa6c8d000)
/lib/ld-linux-aarch64.so.1 (0x0000005565c4c000)
User contributions licensed under CC BY-SA 3.0