Skip to content

Instantly share code, notes, and snippets.

@user202729
Last active July 7, 2024 01:36
Show Gist options
  • Save user202729/f5077701ed789d2cc50ea11d0ae998d5 to your computer and use it in GitHub Desktop.
Save user202729/f5077701ed789d2cc50ea11d0ae998d5 to your computer and use it in GitHub Desktop.
/a.o
/b.o
/c.o
/program
inline int f() {
asm(
".weak abc\n"
"abc: nop\n"
".pushsection CUSTOM, \"aw\"\n"
".quad abc\n"
".quad 0x0123456789abcdef\n"
".popsection"
);
return 1;
}
int g() { return f(); }
inline int f() {
asm(
".weak abc\n"
"abc: nop\n"
".pushsection CUSTOM, \"aw\"\n"
".quad abc\n"
".quad 0x0123456789abcdef\n"
".popsection"
);
return 1;
}
int h() { return f(); }
#!/bin/bash
set -e -x
g++ -fPIC a.cpp -c -o a.o
g++ -fPIC b.cpp -c -o b.o
ld -relocatable a.o b.o -o c.o
g++ main.cpp c.o -o program
./program
exit
objdump -D --reloc c.o
objdump -D --reloc a.o
#include<stdio.h>
int g();
int h();
int main(){
printf("%d %d\n", g(), h());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment