Skip to content

Instantly share code, notes, and snippets.

@Vogtinator
Created August 19, 2020 14:35
Show Gist options
  • Save Vogtinator/67393dd09fc579fc88d51758b0a1aa84 to your computer and use it in GitHub Desktop.
Save Vogtinator/67393dd09fc579fc88d51758b0a1aa84 to your computer and use it in GitHub Desktop.
void setValue(int v);
extern int value;
int main()
{
setValue(42);
return value;
}
With -Bsymbolic-functions, it works as expected:
fvogt@linux-e202:/tmp/breakutils> gcc -fPIC -shared -Wl,-Bsymbolic-functions -Wl,--dynamic-list,lib.dynlist -o lib.so lib.i && readelf --dyn-syms -r lib.so | grep value
000000003fe8 000600000006 R_X86_64_GLOB_DAT 0000000000004024 value + 0
6: 0000000000004024 4 OBJECT GLOBAL DEFAULT 22 value
fvogt@linux-e202:/tmp/breakutils> gcc lib.so break.i -o break && LD_LIBRARY_PATH=$PWD ./break; echo $?
42
Without, the relocation is missing and setValue writes into a different value than main reads from:
fvogt@linux-e202:/tmp/breakutils> gcc -fPIC -shared -Wl,--dynamic-list,lib.dynlist -o lib.so lib.i && readelf --dyn-syms -r lib.so | grep value
6: 0000000000004024 4 OBJECT GLOBAL DEFAULT 22 value
fvogt@linux-e202:/tmp/breakutils> gcc lib.so break.i -o break && LD_LIBRARY_PATH=$PWD ./break; echo $?
0
{
extern "C" {
"setValue";
};
};
int value = 0;
void setValue(int v) {
value = v;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment