Hi
I found the following issue. This program:
#include <stdio.h>
__asm__ (".global number; number = 0x12345678");
extern void number;
int main()
{
printf("%p\n", &number);
return 0;
}
works when compiled without -fPIC and segfaults when compiled with -fPIC.
When the program is broken to two files (one file containing __asm__ line
and the second file containing main), it works fine even with -fPIC ---
even if I break it into two files and link them dynamically with each
other, it works and prints correct number --- it just doesn't work when
all program is contained in one file.
It seems like an error in gas --- gas replaced [EMAIL PROTECTED] with constant
0x12345678 when number was constant --- it probably errorneously thought
that [EMAIL PROTECTED] is equivalent to number for costant numbers.
(tested on i386)
Mikulas
Output of gcc:
.file "got.c"
#APP
.global number; number = 0x12345678
#NO_APP
.section .rodata.str1.1,"aMS",@progbits,1
.LC0:
.string "%p\n"
.text
.p2align 4,,15
.globl main
.type main, @function
main:
pushl %ebp
movl %esp, %ebp
pushl %ebx
subl $20, %esp
andl $-16, %esp
call __i686.get_pc_thunk.bx
addl $_GLOBAL_OFFSET_TABLE_, %ebx
movl [EMAIL PROTECTED](%ebx), %eax
subl $16, %esp
movl %eax, 4(%esp)
leal [EMAIL PROTECTED](%ebx), %eax
movl %eax, (%esp)
call [EMAIL PROTECTED]
movl -4(%ebp), %ebx
xorl %eax, %eax
leave
ret
.size main, .-main
.section
.gnu.linkonce.t.__i686.get_pc_thunk.bx,"ax",@progbits
.globl __i686.get_pc_thunk.bx
.hidden __i686.get_pc_thunk.bx
.type __i686.get_pc_thunk.bx, @function
__i686.get_pc_thunk.bx:
movl (%esp), %ebx
ret
.section .note.GNU-stack,"",@progbits
.ident "GCC: (GNU) 3.4.6"
objdump -d:
00000000 <main>:
0: 55 push %ebp
1: 89 e5 mov %esp,%ebp
3: 53 push %ebx
4: 83 ec 14 sub $0x14,%esp
7: 83 e4 f0 and $0xfffffff0,%esp
a: e8 fc ff ff ff call b <main+0xb>
f: 81 c3 02 00 00 00 add $0x2,%ebx
15: 8b 83 78 56 34 12 mov 0x12345678(%ebx),%eax
!!!!!!!!!!!!!!!!!!
This causes crash!!!
1b: 83 ec 10 sub $0x10,%esp
1e: 89 44 24 04 mov %eax,0x4(%esp)
22: 8d 83 00 00 00 00 lea 0x0(%ebx),%eax
28: 89 04 24 mov %eax,(%esp)
2b: e8 fc ff ff ff call 2c <main+0x2c>
30: 8b 5d fc mov 0xfffffffc(%ebp),%ebx
33: 31 c0 xor %eax,%eax
35: c9 leave
36: c3 ret
Disassembly of section .gnu.linkonce.t.__i686.get_pc_thunk.bx:
00000000 <__i686.get_pc_thunk.bx>:
0: 8b 1c 24 mov (%esp),%ebx
3: c3 ret
objdump -r:
got.o: file format elf32-i386
RELOCATION RECORDS FOR [.text]:
OFFSET TYPE VALUE
0000000b R_386_PC32 __i686.get_pc_thunk.bx
00000011 R_386_GOTPC _GLOBAL_OFFSET_TABLE_
00000024 R_386_GOTOFF .LC0
0000002c R_386_PLT32 printf
^^^^^ note that there is no R_386_GOT32 relocation for offset 00000017,
although there should be.
_______________________________________________
bug-binutils mailing list
bug-binutils@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-binutils