Created
July 4, 2012 23:05
-
-
Save hraban/3049982 to your computer and use it in GitHub Desktop.
Inlining through namespaces
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
.file "test.c" | |
.text | |
.p2align 4,,15 | |
.globl inline_value_proper | |
.type inline_value_proper, @function | |
inline_value_proper: | |
.LFB7: | |
.cfi_startproc | |
movl $5000, %eax | |
ret | |
.cfi_endproc | |
.LFE7: | |
.size inline_value_proper, .-inline_value_proper | |
.p2align 4,,15 | |
.globl inline_value_improper | |
.type inline_value_improper, @function | |
inline_value_improper: | |
.LFB8: | |
.cfi_startproc | |
movl $6000, %eax | |
ret | |
.cfi_endproc | |
.LFE8: | |
.size inline_value_improper, .-inline_value_improper | |
.p2align 4,,15 | |
.globl my_test | |
.type my_test, @function | |
my_test: | |
.LFB9: | |
.cfi_startproc | |
subq $8, %rsp | |
.cfi_def_cfa_offset 16 | |
movl $5000, %edi | |
xorl %eax, %eax | |
call sink | |
call *A+8(%rip) | |
addq $8, %rsp | |
movl %eax, %edi | |
xorl %eax, %eax | |
jmp sink | |
.cfi_endproc | |
.LFE9: | |
.size my_test, .-my_test | |
.globl A | |
.section .rodata | |
.align 16 | |
.type A, @object | |
.size A, 16 | |
A: | |
.quad inline_value_proper | |
.quad inline_value_improper | |
.ident "GCC: (Debian 4.4.5-8) 4.4.5" | |
.section .note.GNU-stack,"",@progbits |
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> | |
#include <stdlib.h> | |
int inline_value_proper(void) | |
{ | |
return 5000; | |
} | |
int inline_value_improper() | |
{ | |
return 6000; | |
} | |
struct A_namespace | |
{ | |
int (* first) ( void ); | |
int (* second) ( void ); | |
}; | |
const struct A_namespace A = { | |
.first = &inline_value_proper, | |
.second = &inline_value_improper | |
}; | |
void | |
my_test(void) | |
{ | |
sink(A.first()); | |
sink(A.second()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment