TipsAndTricks/Running YP binaries on Ubuntu and Vice Versa: Difference between revisions

From Yocto Project
Jump to navigationJump to search
No edit summary
Line 10: Line 10:
  -sh: ./gawk-ubuntu: No such file or directory   
  -sh: ./gawk-ubuntu: No such file or directory   
  </code>
  </code>
* so, what does this mean? It means that the  dynamic loader ("ELF interpreter") for the ubuntu binary "knows" what it is looking for and is not finding it on the qemux86-64 system. So, how can we "fix" this. I have 2 different ways.
* so, what does this mean? It means that the  dynamic loader ("ELF interpreter") for the ubuntu binary "knows" what it is looking for and is not finding it on the qemux86-64 system. So, how can we "fix" this. We have 2 different options.
** Path 1: add patchelf to your qemux86-64 image, and use it to change the interpreter that gawk-ubuntu is looking for. Do this by  
** Path 1: add patchelf to your qemux86-64 image, and use it to change the interpreter that gawk-ubuntu is looking for. Do this by  
  <code> $ patchelf --set-interpreter /lib/ld-linux-x86-64.so.2 gawk-ubuntu  </code>
  <code> $ patchelf --set-interpreter /lib/ld-linux-x86-64.so.2 gawk-ubuntu  </code>

Revision as of 23:50, 23 March 2017

Fun with moving things between os's!

Note: This is a hack to allow you to do some interesting things for experimental purposes. There are a large number of undiscovered ways this can fail. Use at your own risk :).

So, you want to run your ubuntu binary on qemux86-64 built with YP

  • We'll assume that the binary of interest is gawk. Chosen pretty randomly...
  • I will call the ubuntu native gawk gawk-ubuntu and the qemu gawk gawk-qemux86-64. I got it by cp /usr/bin/gawk ~/gawk-ubuntu
  • If I scp the gawk-ubuntu onto qemux86-64 and try to run it, I get the following:

root@qemux86-64:~# ./gawk-ubuntu   
-sh: ./gawk-ubuntu: No such file or directory  

  • so, what does this mean? It means that the dynamic loader ("ELF interpreter") for the ubuntu binary "knows" what it is looking for and is not finding it on the qemux86-64 system. So, how can we "fix" this. We have 2 different options.
    • Path 1: add patchelf to your qemux86-64 image, and use it to change the interpreter that gawk-ubuntu is looking for. Do this by
 $ patchelf --set-interpreter /lib/ld-linux-x86-64.so.2 gawk-ubuntu  
      • Now when we run it we get:
 
root@qemux86-64:~# ./gawk-ubuntu
./gawk-ubuntu: error while loading shared libraries: libsigsegv.so.2: cannot open shared object file: No such file or directory

      • Better, (it is!). Now we just need the shared libs we are missing. In particular: libsigsegv.so.2: I could build this on qemux86-64 with YP if I have a recipe for it, (I don't) or I can grab it from Ubuntu as well. It looks like this:

root@qemux86-64:~# ls  
gawk-ubuntu       gawk-ubuntu-orig  libsigsegv.so.2  
root@qemux86-64:~# LD_LIBRARY_PATH=/home/root/ ./gawk-ubuntu   
Usage: gawk-ubuntu [POSIX or GNU style options] -f progfile [--] file ...  
Usage: gawk-ubuntu [POSIX or GNU style options] [--] 'program' file ...  
< more usage details ....>

      • - SUCCESS! This means it ran:)
      • But, what if you don't like modifying your binary? See Path2
    • Path2: change your system aka rootfs aka qemu image to accommodate ubuntu binaries:
      • What is the ubuntu gawk looking for anyway?

root@qemux86-64:~# patchelf --print-interpreter gawk-ubuntu-orig
/lib64/ld-linux-x86-64.so.2

      • Ahh, so what if we soft link /lib/ld-linux-x86-64.so.2 to /lib64/ld-linux-x86-64.so.2?

root@qemux86-64:~# ln -s /lib/ld-linux-x86-64.so.2 /lib64/ld-linux-x86-64.so.2
root@qemux86-64:~# ./gawk-ubuntu-orig 
./gawk-ubuntu-orig: error while loading shared libraries: libsigsegv.so.2: cannot open shared object file: No such file or directory

      • That looks familiar and we know how to fix that.

root@qemux86-64:~# LD_LIBRARY_PATH=/home/root ./gawk-ubuntu-orig 
Usage: gawk-ubuntu-orig [POSIX or GNU style options] -f progfile [--] file ...
Usage: gawk-ubuntu-orig [POSIX or GNU style options] [--] 'program' file ...
< more usage details ....>

      • - SUCCESS! This means it ran using Path 2:)

So, you want to run your YP binary built for qemux86-64 on Ubuntu

  • You should read the prior information since this is a mirror image of the above.
    • Only 1 path since I don't want to add random softlinks to interpreters on my main box. - Use patchelf
      • If your distro doesn't have it, you can grab and build it in ~ 2 minutes from - https://github.com/NixOS/patchelf
      • Then you use patchelf to set the loader for the qemux86-64 binary to the one on your ubuntu box and grab any needed libraries from either the running qemu instance using scp or just from the build dir itself. Code snippet here:

bavery@XX:~/src//poky$ ./patchelf/src/patchelf --set-interpreter /lib64/ld-linux-x86-64.so.2   gawk-qemux86-64   
bavery@XX:~/src//poky$ ./gawk-qemux86-64   
./gawk-qemux86-64: error while loading shared libraries: libreadline.so.7: cannot open shared object file: No such file or directory  
bavery@XX:~/src//poky$ LD_LIBRARY_PATH=`pwd` ./gawk-qemux86-64                                             
Usage: gawk-qemux86-64 [POSIX or GNU style options] -f progfile [--] file ...  
Usage: gawk-qemux86-64 [POSIX or GNU style options] [--] 'program' file ...  
 < more usage details ....>

      • SUCCESS - Once I set the interpreter to the ubuntu loader and copied over the missing libreadline library (the one on my ubuntu box was libreadline6 ...) it worked. We ran a YP built Qemu binary on a std Ubuntu box!