help! why a 'so' can't load its dependent 'so' to the pre-defined address

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Dear GCC experts

Please forgive me if it’s bothering you.

I have a question about LD and dynamic library, which I have been struggling with for a while
it will be great if you can help me out,

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(appDemo) 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" ? libtestScript.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.

For your reference on how I built the elf executable program and shared lib.
/home/ericxh/work/toolchain/marvell-gcc-5.2.1-16.02.0-armv8/armv8/le/aarch64v8-
marvell-linux-gnu-5.2.1_i686_20151110/bin/aarch64-marvell-linux-gnu-gcc  -shared
-Xlinker                                                         --whole-archive
compilation_root/cpss_4.2/armv8_DX_SHARED/cpssEnabler/libs/TESTSCRIPT.a -Xlinker
--no-whole-archive    \     compilation_root/cpss_4.2/armv8_DX_SHARED/libcpss.so
compilation_root/cpss_4.2/armv8_DX_SHARED/libhelper.so   -Xlinker   -z  -Xlinker
nocopyreloc  -rdynamic   -lpthread  -lrt   -ldl  -lm    -Xlinker  -Map  -Xlinker
compilation_root/cpss_4.2/armv8_DX_SHARED/libtestScript.map \ -Xlinker -soname -
Xlinker                           libtestScript.so                            -o
compilation_root/cpss_4.2/armv8_DX_SHARED/libtestScript.so


/home/ericxh/work/toolchain/marvell-gcc-5.2.1-16.02.0-armv8/armv8/le/aarch64v8-
marvell-linux-gnu-5.2.1_i686_20151110/bin/aarch64-marvell-linux-gnu-gcc -Xlinker
--whole-archive
compilation_root/cpss_4.2/armv8_DX_SHARED/referenceCode/libs/REFERENCECODE.a
…
…
compilation_root/cpss_4.2/armv8_DX_SHARED/cpssEnabler/libs/CPSSAPPREF.a
compilation_root/cpss_4.2/armv8_DX_SHARED/version_info.o  -Xlinker   --no-whole-
archive          \          compilation_root/cpss_4.2/armv8_DX_SHARED/libcpss.so
compilation_root/cpss_4.2/armv8_DX_SHARED/libhelper.so   -Xlinker   -z  -Xlinker
nocopyreloc  -rdynamic   -lpthread  -lrt   -ldl  -lm    -Xlinker  -Map  -Xlinker
compilation_root/cpss_4.2/armv8_DX_SHARED/appDemo.map                         -o
compilation_root/cpss_4.2/armv8_DX_SHARED/appDemo





Best regards

Xinghao Chen (陈行浩)





[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux