Created
July 11, 2020 04:00
-
-
Save tiqwab/9db07648829c81caa08496691e70546a to your computer and use it in GitHub Desktop.
How to access symbol and its content by assembly (and with PIE)
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
$ as -o foo.obj foo.S | |
$ cc -o sample sample.c foo.obj | |
$ ./sample | |
0x557727162030 # address of value1 | |
0x1122334455667788 # content of value1 | |
0x55772716203c # address of z |
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
.text | |
.global foo | |
.global bar | |
foo: | |
lea value1(%rip), %rax | |
retq | |
bar: | |
lea value1(%rip), %rdx | |
movq (%rdx), %rax | |
retq | |
.data | |
.align 16 | |
value1: | |
.quad 0x1122334455667788 |
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> | |
long foo(); | |
long bar(); | |
int z = 0; | |
int main(int argc, const char *argv[]) { | |
long x = foo(); | |
printf("0x%lx\n", x); | |
long y = bar(); | |
printf("0x%lx\n", y); | |
printf("0x%lx\n", (long) &z); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment