Skip to content

Instantly share code, notes, and snippets.

@ajeddeloh
Last active August 29, 2015 14:07
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 ajeddeloh/a84bf973f889801e88e3 to your computer and use it in GitHub Desktop.
Save ajeddeloh/a84bf973f889801e88e3 to your computer and use it in GitHub Desktop.
Weird C stuff
.file "test.c"
.local a
.comm a,4,4
.section .rodata
.LC0:
.string "%p\n%p\n"
.LC1:
.string "%d\n%d\n"
.text
.globl main
.type main, @function
main:
.LFB0:
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
subq $16, %rsp
movq $a, -8(%rbp)
movq -8(%rbp), %rax
movl $a, %edx
movq %rax, %rsi
movl $.LC0, %edi
movl $0, %eax
call printf
movq -8(%rbp), %rax
movl $6, (%rax)
movl a(%rip), %edx
movq -8(%rbp), %rax
movl (%rax), %eax
movl %eax, %esi
movl $.LC1, %edi
movl $0, %eax
call printf
leave
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE0:
.size main, .-main
.ident "GCC: (GNU) 4.9.1 20140903 (prerelease)"
.section .note.GNU-stack,"",@progbits
GCC output:
0x600954
0x600954
6
0
Clang output:
0x4005e4
0x4005e4
Segmentation fault (core dumped)
#include <stdio.h>
static const int a;
int main(void) {
int *b = (int *) &a;
printf("%p\n%p\n", b, &a);
*b = 6;
printf("%d\n%d\n", *b, a);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment