Created
August 19, 2020 14:35
-
-
Save Vogtinator/67393dd09fc579fc88d51758b0a1aa84 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
void setValue(int v); | |
extern int value; | |
int main() | |
{ | |
setValue(42); | |
return value; | |
} |
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
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 |
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
{ | |
extern "C" { | |
"setValue"; | |
}; | |
}; |
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
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