Search code examples
c++compilationarmcross-compilingprelink

Prelink Error: prelink-cross: simple hello world example


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'

Solution

  • 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