[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Bug gas/10677] New: incorrect code generated with asm function pointers
From: |
scott dot sourceware dot 2009 at scottrix dot co dot uk |
Subject: |
[Bug gas/10677] New: incorrect code generated with asm function pointers when compiled with -fPIC on x84_64 |
Date: |
21 Sep 2009 10:18:32 -0000 |
This problem only occurs on x86_64, not i686.
Example code (a.c):
#include <stdio.h>
extern void my_asm_func(void);
asm(".text\n" \
"my_asm_func:\n" \
" mov 1234,%rax\n" \
" ret\n" \
".previous\n");
int my_c_func() { return 1; }
int main()
{
void *fred;
fred=(void *)my_asm_func;
printf("function = %p\n",fred);
fred=(void *)my_c_func;
printf("function = %p\n",fred);
return 0;
}
if this is compiled with the line:
gcc -c -g -o a.o a.c
The assemble code for the two "fred=" function pointer assignments are correct:
fred=(void *)my_asm_func;
1c: 48 c7 45 f8 00 00 00 movq $0x0,-0x8(%rbp)
23: 00
fred=(void *)my_c_func;
37: 48 c7 45 f8 00 00 00 movq $0x0,-0x8(%rbp)
3e: 00
as expected. However, when used with -fPIC:
gcc -fPIC -c -g -o a.o a.c
we get :
fred=(void *)my_asm_func;
1c: 48 8b 05 dd ff ff ff mov -0x23(%rip),%rax # 0
<my_asm_func>
23: 48 89 45 f8 mov %rax,-0x8(%rbp)
fred=(void *)my_c_func;
3c: 48 8b 05 00 00 00 00 mov 0x0(%rip),%rax # 43 <main+0x2f>
43: 48 89 45 f8 mov %rax,-0x8(%rbp)
For some reason the asm function pointer has already been fixed up with a value,
which is actually the location the of the function, but it will move the value
at that address into rax, not the address itself. Looking at the intermediate
.s file:
movq address@hidden(%rip), %rax
movq address@hidden(%rip), %rax
Both functions have the same fixup type (assuming that is the correct
terminology). However, they produce different code. If I add a .global to the
assembler then it works, however, I don't think that I should need to, and on
i686 it works fine.
I have reproduced this problem on gcc 4.3.2 and 4.4.1, both with binutils
2.19.1. I have only given objdump -S output for the relevant sections of code.
If you require more information please let me know.
This problem was actually found while compiling valgrind for a 64 bit x86
target machine.
--
Summary: incorrect code generated with asm function pointers when
compiled with -fPIC on x84_64
Product: binutils
Version: 2.19
Status: NEW
Severity: normal
Priority: P2
Component: gas
AssignedTo: unassigned at sources dot redhat dot com
ReportedBy: scott dot sourceware dot 2009 at scottrix dot co dot uk
CC: bug-binutils at gnu dot org
http://sourceware.org/bugzilla/show_bug.cgi?id=10677
------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.
- [Bug gas/10677] New: incorrect code generated with asm function pointers when compiled with -fPIC on x84_64,
scott dot sourceware dot 2009 at scottrix dot co dot uk <=