4

I am trying to cross-prelink a simple hello world program. I use the cross-compile toolchain arm-2012.03-57-arm-none-linux-gnueabi-i686-pc-linux-gnu and I am not sure if I have used the prelink-cross options correclty. I'll be glad if someone could point me to the right direction. More details about the source code on github. Thank you.

project directory tree

|-arm-2012.03/
  |...
|-src/
  |-main.cpp
|-bin/
  |-hello
|-prelink_arm.conf

main.cpp

#include <stdio.h>
int main (int argc, char *argv[])
{
    fprintf(stdout, "hello world\n");
    return 0;
}

prelink_arm.conf

-l arm-2012.03/arm-none-linux-gnueabi/libc/lib 
-h arm-2012.03/arm-none-linux-gnueabi/libc/lib 
-l arm-2012.03/arm-none-linux-gnueabi/libc/usr/lib
-h arm-2012.03/arm-none-linux-gnueabi/libc/usr/lib

compiling

arm-2012.03/bin/arm-none-linux-gnueabi-gcc -Wall -o bin_arm/hello src/main.cpp

prelinking

PATH=/usr/local/sbin prelink --verbose --cache-file=cache/prelink_arm.cache --config-file=prelink_arm.conf --ld-library-path="arm-2012.03/arm-none-linux-gnueabi/libc/lib;arm-2012.03/arm-none-linux-gnueabi/libc/usr/lib;" -h bin_arm/hello

error message

prelink: arm-2012.03/arm-none-linux-gnueabi/libc/usr/lib/bin/getent: Could not parse `/usr/local/sbin//prelink-rtld: error while loading shared libraries: ld-linux.so.3'
prelink: arm-2012.03/arm-none-linux-gnueabi/libc/usr/lib/bin/POSIX_V6_ILP32_OFFBIG: Could not parse `/usr/local/sbin//prelink-rtld: error while loading shared libraries: ld-linux.so.3'
prelink: arm-2012.03/arm-none-linux-gnueabi/libc/usr/lib/bin/iconv: Could not parse `/usr/local/sbin//prelink-rtld: error while loading shared libraries: ld-linux.so.3'
prelink: arm-2012.03/arm-none-linux-gnueabi/libc/usr/lib/bin/sprof: Could not parse `/usr/local/sbin//prelink-rtld: error while loading shared libraries: ld-linux.so.3'
prelink: arm-2012.03/arm-none-linux-gnueabi/libc/usr/lib/bin/iconvconfig: Could not parse `/usr/local/sbin//prelink-rtld: error while loading shared libraries: ld-linux.so.3'
prelink: arm-2012.03/arm-none-linux-gnueabi/libc/usr/lib/bin/POSIX_V7_ILP32_OFF32: Could not parse `/usr/local/sbin//prelink-rtld: error while loading shared libraries: ld-linux.so.3'
prelink: arm-2012.03/arm-none-linux-gnueabi/libc/usr/lib/bin/zdump: Could not parse `/usr/local/sbin//prelink-rtld: error while loading shared libraries: ld-linux.so.3'
prelink: arm-2012.03/arm-none-linux-gnueabi/libc/usr/lib/bin/pcprofiledump: Could not parse `/usr/local/sbin//prelink-rtld: error while loading shared libraries: ld-linux.so.3'
prelink: arm-2012.03/arm-none-linux-gnueabi/libc/usr/lib/bin/gencat: Could not parse `/usr/local/sbin//prelink-rtld: error while loading shared libraries: ld-linux.so.3'
prelink: arm-2012.03/arm-none-linux-gnueabi/libc/usr/lib/bin/gdbserver: Could not parse `/usr/local/sbin//prelink-rtld: error while loading shared libraries: ld-linux.so.3'
prelink: arm-2012.03/arm-none-linux-gnueabi/libc/usr/lib/bin/pldd: Could not parse `/usr/local/sbin//prelink-rtld: error while loading shared libraries: ld-linux.so.3'
prelink: arm-2012.03/arm-none-linux-gnueabi/libc/usr/lib/bin/locale: Could not parse `/usr/local/sbin//prelink-rtld: error while loading shared libraries: ld-linux.so.3'
prelink: arm-2012.03/arm-none-linux-gnueabi/libc/usr/lib/bin/localedef: Could not parse `/usr/local/sbin//prelink-rtld: error while loading shared libraries: ld-linux.so.3'
prelink: arm-2012.03/arm-none-linux-gnueabi/libc/usr/lib/bin/XBS5_ILP32_OFFBIG: Could not parse `/usr/local/sbin//prelink-rtld: error while loading shared libraries: ld-linux.so.3'
prelink: arm-2012.03/arm-none-linux-gnueabi/libc/usr/lib/bin/zic: Could not parse `/usr/local/sbin//prelink-rtld: error while loading shared libraries: ld-linux.so.3'
prelink: arm-2012.03/arm-none-linux-gnueabi/libc/usr/lib/bin/POSIX_V7_ILP32_OFFBIG: Could not parse `/usr/local/sbin//prelink-rtld: error while loading shared libraries: ld-linux.so.3'
prelink: arm-2012.03/arm-none-linux-gnueabi/libc/usr/lib/bin/rpcgen: Could not parse `/usr/local/sbin//prelink-rtld: error while loading shared libraries: ld-linux.so.3'
prelink: arm-2012.03/arm-none-linux-gnueabi/libc/usr/lib/bin/makedb: Could not parse `/usr/local/sbin//prelink-rtld: error while loading shared libraries: ld-linux.so.3'
prelink: arm-2012.03/arm-none-linux-gnueabi/libc/usr/lib/bin/getconf: Could not parse `/usr/local/sbin//prelink-rtld: error while loading shared libraries: ld-linux.so.3'
prelink: arm-2012.03/arm-none-linux-gnueabi/libc/usr/lib/bin/XBS5_ILP32_OFF32: Could not parse `/usr/local/sbin//prelink-rtld: error while loading shared libraries: ld-linux.so.3'
prelink: arm-2012.03/arm-none-linux-gnueabi/libc/usr/lib/bin/POSIX_V6_ILP32_OFF32: Could not parse `/usr/local/sbin//prelink-rtld: error while loading shared libraries: ld-linux.so.3'
prelink: bin_arm/hello: Could not parse `/usr/local/sbin//prelink-rtld: error while loading shared libraries: ld-linux.so.3'

If I extract all the libraries that the executable is dependent on into a separate folder and set the links accordingly, then I still get the following error:

prelink: bin_arm/hello: Could not parse `/usr/local/sbin//prelink-rtld: error while loading shared libraries: ld-linux.so.3'
Florian Boehmak
  • 431
  • 4
  • 20

2 Answers2

1

Yay, I found the solution:

I had to specify the sysroot and explicitly tell prelink which libraries to precompile.

The directory structure now looks like this:

|- arm-2012.03/arm-none-linux-gnueabi/libc/usr/local/bin/hello
  \- /arm-none-linux-gnueabi
    \- libc
      \- lib
        \- libc-2.15.so
        |- libgcc_s.so.1
        |- ld-2.15.so
        |- ...
      |- usr
        \- local
          \- bin
            \- hello
      |- etc
        \- prelink.conf
|- Makefile

prelink.conf

-l /libc/lib
-h /libc/lib

And this is the prelink command:

PATH=/usr/local/sbin prelink --verbose --root=arm-2012.03/arm-none-linux-gnueabi/libc/ --cache-file=/etc/cache/prelink.cache --config-file=/etc/prelink.conf --ld-library-path="/lib;" -h /usr/local/bin/hello /lib/libc-2.15.so /lib/libgcc_s.so.1 /lib/ld-2.15.so

The source code can be found on github, make sure to checkout both branches 'master' and 'shared-library': https://github.com/fnbk/prelink-cross-example

Florian Boehmak
  • 431
  • 4
  • 20
  • binary using /lib/ld-linux-armhf.so.3, not /home/acs/Desktop/fastboot/gcc-linaro-5.2-2015.11-1-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/libc/arm-linux-gnueabihf/lib/ld-linux-armhf.so.3 as dynamic linker – zappy Apr 22 '16 at 10:30
  • How do I get prelink binary?? should I need build it form source or just apt-get install? – zappy Apr 22 '16 at 11:10
  • Hi zappy. It does not matter. You can use install it with a package manager (apt-get) or build it from source. – Florian Boehmak Apr 23 '16 at 19:36
  • prelink binary installed by package manager doesn't have --root option. So i choose to compile the source. still I am facing lots of error while prelinking a Qt binary for ARM like " Could not prelink /lib/libpthread.so.0 because its dependency /lib/libc.so.6 could not be prelinked" etc... Could you please Help me to find the reason ? – zappy Apr 23 '16 at 20:10
  • @zappy where did you get the source from? I'm getting the same error about `--root` option. Thanks and sorry for posting on this old thread. – ramtheconqueror Oct 28 '16 at 15:01
  • @ramtheconqueror , it was just a PATH issue , giving absolute path to all linking libraries solved my problem, I don't remember from where I got the source , But surely some version of prelink had some issues. Better try with another version of source – zappy Nov 17 '16 at 11:49
0

I suppose you have to use:
Full path to lib folder here:

prelink_arm.conf

-l arm-2012.03/arm-none-linux-gnueabi/libc/lib     
-h arm-2012.03/arm-none-linux-gnueabi/libc/lib     
-l arm-2012.03/arm-none-linux-gnueabi/libc/usr/lib  
-h arm-2012.03/arm-none-linux-gnueabi/libc/usr/lib  

And here + add $PATH to PATH variable:
prelinking

PATH=/usr/local/sbin:$PATH prelink --verbose  \
--cache-file=cache/prelink_arm.cache --config-file=prelink_arm.conf \
--ld-library-path="arm-2012.03/arm-none-linux-gnueabi/libc/lib;arm-2012.03/arm-none-linux-gnueabi/libc/usr/lib;" \
-h bin_arm/hello

Actually all of these errors is pointing you on:

Could not parse /usr/local/sbin//prelink-rtld: error while loading shared libraries: ld-linux.so.3

If the first 2 notes will not help, you may try to:

  • find/download ld-linux.so.3
  • set export LD_LIBRARY_PATH=$PATH_TO_LD_LINUX_SO_3:$LD_LIBRARY_PATH
  • or add it with --ld-library-path= options, as it already done for other libs

it will add custom search path to your env.

Laser
  • 6,652
  • 8
  • 54
  • 85