Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@haampie
Created January 25, 2022 23:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save haampie/ee1be0df1bac929152daab371c72da2d to your computer and use it in GitHub Desktop.
Save haampie/ee1be0df1bac929152daab371c72da2d to your computer and use it in GitHub Desktop.
runtime linker
all: exef1 exef2 exef3
EI_OSABI:=7
EI_ABIVERSION:=8
EI_PAD:=9
libf1.so:
echo 'int f(){ return 1; }' | $(CC) -o $@ -shared -Wl,-soname,$@ -x c -
printf '\x0B' | dd of=$@ bs=1 seek=$(EI_OSABI) count=1 conv=notrunc status=none
libf2.so:
echo 'int f(){ return 2; }' | $(CC) -o $@ -shared -Wl,-soname,$@ -x c -
printf '\xff' | dd of=$@ bs=1 seek=$(EI_ABIVERSION) count=1 conv=notrunc status=none
libf3.so:
echo 'int f(){ return 3; }' | $(CC) -o $@ -shared -Wl,-soname,$@ -x c -
printf '\xff' | dd of=$@ bs=1 seek=$(EI_PAD) count=1 conv=notrunc status=none
exef1: libf1.so
echo 'int f(); int main(){printf("%d\\n", f());}' | $(CC) -include stdio.h -o $@ '-Wl,-rpath,$$ORIGIN' -x c - -L. -lf1
exef2: libf2.so
echo 'int f(); int main(){printf("%d\\n", f());}' | $(CC) -include stdio.h -o $@ '-Wl,-rpath,$$ORIGIN' -x c - -L. -lf2
exef3: libf3.so
echo 'int f(); int main(){printf("%d\\n", f());}' | $(CC) -include stdio.h -o $@ '-Wl,-rpath,$$ORIGIN' -x c - -L. -lf3
clean:
rm -f -- *.so exe*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment