Skip to content

Instantly share code, notes, and snippets.

@tiqwab
Created July 11, 2020 04:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tiqwab/9db07648829c81caa08496691e70546a to your computer and use it in GitHub Desktop.
Save tiqwab/9db07648829c81caa08496691e70546a to your computer and use it in GitHub Desktop.
How to access symbol and its content by assembly (and with PIE)
$ 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
.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
#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