Skip to content

Instantly share code, notes, and snippets.

@sanxiyn
Created October 4, 2013 07:38
Show Gist options
  • Save sanxiyn/6822312 to your computer and use it in GitHub Desktop.
Save sanxiyn/6822312 to your computer and use it in GitHub Desktop.
Weak symbol
#!/bin/sh
gcc -shared -fPIC sub.c -o libhost.so
gcc main.c -L. -lhost -o host
LD_LIBRARY_PATH=. ./host
int x = 1;
void f(void);
int main(void) {
f();
return 0;
}
#include <stdio.h>
extern int x __attribute__((weak));
void f(void) {
printf("x = %d\n", x);
}
#!/bin/sh
arm-linux-androideabi-gcc -shared -fPIC sub.c -o libtarget.so
arm-linux-androideabi-gcc main.c -L. -ltarget -o target
adb shell rm -r /data/tmp
adb shell mkdir /data/tmp
adb push libtarget.so /data/tmp
adb push target /data/tmp
adb shell '(cd /data/tmp; LD_LIBRARY_PATH=. ./target)'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment