Guest User

Untitled

a guest
Aug 21st, 2017
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.44 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. cat>test.c<<'C'
  4. #include <unistd.h>
  5. #include <stdio.h>
  6.  
  7. int add(int x,int y);
  8.  
  9. int main(int argc,char** argv) {
  10.     enum { buf_size=4096 }; char buf[buf_size];
  11.     int rd=readlink("/proc/self/exe",buf,buf_size-1); buf[rd]=0;
  12.     printf("readlink=%s\n",buf);
  13.     return add(1,-1);
  14. }
  15.  
  16. C
  17.  
  18. cat>add.c<<'C'
  19. int add(int x,int y) { return x+y; }
  20.  
  21. C
  22.  
  23. echo '--build x32 executables--'
  24. gcc -m32 -o libadd.so -shared add.c
  25. gcc -m32 -o test test.c -L. -ladd -Xlinker '-rpath=$ORIGIN/../libs:$ORIGIN/libs'
  26. mkdir -p libs
  27. mv libadd.so libs
  28.  
  29. echo '--test localy--'
  30. ./test && echo success1 || echo fail1
  31.  
  32. echo '--prepare archives--'
  33.  
  34. mkdir -p bin
  35. sudo mount -t tmpfs -osize=1M none bin
  36. cp test bin
  37. mkdir -p bin/libs
  38. cp libs/libadd.so bin/libs
  39. rm -f bin.squashfs
  40. mksquashfs bin bin.squashfs -comp xz 2>&1 > /dev/null
  41. sudo umount bin
  42.  
  43. echo '--mount fs--'
  44.  
  45. sudo mount -t tmpfs -osize=1M none bin
  46. mkdir bin/app bin/rom bin/diff
  47. sudo mount -t squashfs -o ro bin.squashfs bin/rom
  48. sudo mount -t overlayfs -o lowerdir=bin/rom,upperdir=bin/diff none bin/app
  49. #sudo mount -t aufs -o br=bin/rom:bin/diff none bin/app
  50. cd bin/app
  51. ./test && echo success2 || (
  52.     echo fail2
  53.     strace ./test 2>&1 | grep open | head
  54. )
  55. echo '--using crutch--'
  56. LD_LIBRARY_PATH=$PWD/libs ./test && echo success3 || echo fail3
  57.  
  58. cd ../..
  59.  
  60. cd bin/rom
  61. ./test && echo success4 || echo fail4
  62. cd ../..
  63. sudo umount bin/app
  64. sudo umount bin/rom
  65. sudo umount bin
Add Comment
Please, Sign In to add comment