Bin.Cheng
2018-11-11 06:58:26 UTC
Hi,
Given below simple code:
inline int foo (int a) {
return a + 1;
}
int g = 5;
int main(void) {
return foo(g);
}
When compiled with -O0, GCC generates below assembly:
.file "test.c"
.text
.globl g
.data
.align 4
.type g, @object
.size g, 4
g:
.long 5
.text
.globl main
.type main, @function
main:
.LFB1:
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
movl g(%rip), %eax
movl %eax, %edi
call foo
popq %rbp
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE1:
.size main, .-main
.ident "GCC: (GNU) 9.0.0 20181031 (experimental)"
.section .note.GNU-stack,"",@progbits
Note the body of function foo is removed while call to foo isn't
inlined, this results in undefined reference to "foo" at linking.
Guess this is a bug?
Thanks,
bin
Given below simple code:
inline int foo (int a) {
return a + 1;
}
int g = 5;
int main(void) {
return foo(g);
}
When compiled with -O0, GCC generates below assembly:
.file "test.c"
.text
.globl g
.data
.align 4
.type g, @object
.size g, 4
g:
.long 5
.text
.globl main
.type main, @function
main:
.LFB1:
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
movl g(%rip), %eax
movl %eax, %edi
call foo
popq %rbp
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE1:
.size main, .-main
.ident "GCC: (GNU) 9.0.0 20181031 (experimental)"
.section .note.GNU-stack,"",@progbits
Note the body of function foo is removed while call to foo isn't
inlined, this results in undefined reference to "foo" at linking.
Guess this is a bug?
Thanks,
bin