Last active
December 10, 2015 13:08
-
-
Save sw17ch/4438798 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include "foo.h" | |
void foo(void) { | |
printf("foo!\n"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef FOO_H | |
#define FOO_H | |
void foo(void); | |
#endif /* FOO_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include "foo.h" | |
void foo(void) { | |
printf("shim!\n"); | |
old_foo(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include "foo.h" | |
int main(int argc, char * argv[]) { | |
foo(); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
main: main.c shim.o | |
shim.o: foo.c foo_shim.c foo.h | |
# | |
# Compile Files | |
gcc foo.c -c -o foo.o | |
gcc foo_shim.c -c -o foo_shim.o | |
# | |
# Rename the symbol we care about: foo -> old_foo | |
objcopy --redefine-sym foo=old_foo foo.o _foo.o | |
# | |
# Link foo_shim, define shim_foo as foo | |
ld foo_shim.o -r -defsym shim_foo=foo -o _foo_shim.o | |
# | |
# Smush it all together | |
ld _foo.o _foo_shim.o -r -o shim.o | |
clean: | |
rm -f main | |
rm -f *.o |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output: