how a "so" load a so with fixed address?


in my program, two "so" - and have to be loaded into a fixed virtual address, it’s done by the ld script,

/* Code section, access rights RX */
. = 0x14600000;

readelf -l | 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 => (0x0000ffff917ec000) => ./ (0x0000000010000000) => ./ (0x0000000014600000) => /lib/aarch64-linux-gnu/ (0x0000ffff917b5000) => /lib/aarch64-linux-gnu/ (0x0000ffff9179d000) => /lib/aarch64-linux-gnu/ (0x0000ffff91789000) => /lib/aarch64-linux-gnu/ (0x0000ffff916d7000) => /lib/aarch64-linux-gnu/ (0x0000ffff91583000)
/lib/ (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 ./ => (0x0000ffff8d87c000) => ./ (0x0000ffff89d50000) => ./ (0x0000ffff5e350000) => /lib/aarch64-linux-gnu/ (0x0000ffff5e31c000) => /lib/aarch64-linux-gnu/ (0x0000ffff5e304000) => /lib/aarch64-linux-gnu/ (0x0000ffff5e2f0000) => /lib/aarch64-linux-gnu/ (0x0000ffff5e23e000) => /lib/aarch64-linux-gnu/ (0x0000ffff5e0ea000)
/lib/ (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 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 ./

  2349: [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=./
  2289: [0];  generating link map
  2289:       dynamic: 0x000000001462aba0  base: 0x0000000000000000   size: 0x000000002b9ff004
  2289:         entry: 0x0000000014607ad8  phdr: 0x0000ffffb2e24cc0  phnum:                  8

readelf -h ./

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

asked on Stack Overflow Dec 10, 2019 by Xinghao Chen • edited Dec 11, 2019 by Xinghao Chen

1 Answer


after adding the flag of -Wl,-Ttext-segment=0xXXXXXXXX(e.g. 0x70000000) when generating, the result shows as expected:

ldd (0x0000007fa6f04000) => ./ (0x0000000010000000) => ./ (0x0000000014600000) => /lib/aarch64-linux-gnu/ (0x0000007fa6ece000) => /lib/aarch64-linux-gnu/ (0x0000007fa6eb7000) => /lib/aarch64-linux-gnu/ (0x0000007fa6ea2000) => /lib/aarch64-linux-gnu/ (0x0000007fa6de6000) => /lib/aarch64-linux-gnu/ (0x0000007fa6c8d000)
        /lib/ (0x0000005565c4c000)
answered on Stack Overflow Dec 17, 2019 by Xinghao Chen

User contributions licensed under CC BY-SA 3.0