[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
objcopy elf32-i386 to pe-i386 breaks R_386_32 relocations
From: |
Dave Denholm |
Subject: |
objcopy elf32-i386 to pe-i386 breaks R_386_32 relocations |
Date: |
22 May 2008 17:53:10 +0100 |
User-agent: |
Gnus/5.09 (Gnus v5.9.0) Emacs/21.4 |
Hi,
I think there's a bug in the way objcopy handles R_386_32 (absolute
32-bit) relocation entries when translating from elf to pe-i386
(windows) object files.
I first found it running cygwin objcopy on windows, and reproduced it
on linux.
cygwin version is
E:\>c:\cygwin\bin\objcopy --version
GNU objcopy 2.16.91 20050610
linux version is
$ objcopy --version
GNU objcopy (GNU Binutils) 2.18.0.20080103
Copyright 2007 Free Software Foundation, Inc.
(freshly downloaded, and bfd configured with all targets)
The symptom is that R_386_32 relocations in elf get translated into
DIR16 entries in the pe-i386. (Or perhaps just not translated, since I
think DIR16 is numerical value 1, which I think is the same numerical
value as R_386_REL, and possibly also the same value as bfd uses
internally, though that part is pure speculation from a very quick
look at the source.)
Consider
$ cat test.c
extern int e;
int *p = &e;
$ gcc -c test.c
$ objdump -r test.o
test.o: file format elf32-i386
RELOCATION RECORDS FOR [.data]:
OFFSET TYPE VALUE
00000000 R_386_32 e
$ objcopy -O pe-i386 test.o test.obj
$ objdump -r -b pe-i386 test.obj
test.obj: file format pe-i386
RELOCATION RECORDS FOR [.data]:
OFFSET TYPE VALUE
00000000 1 e
# then try to convert back :
$ objcopy -I pe-i386 -O elf32-i386 test.obj back-again.o
BFD: back-again.o: unsupported relocation type (null)
./binutils_gen/binutils/objcopy: back-again.o: Bad value
Running dumpbin on windows on test.obj gives
E:\>dumpbin /relocations z:\tmp\test.obj
Microsoft (R) COFF Binary File Dumper Version 6.00.8168
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.
Dump of file z:\tmp\test.obj
File Type: COFF OBJECT
RELOCATIONS #2
Symbol Symbol
Offset Type Applied To Index Name
-------- ---------------- ----------------- -------- ------
00000000 DIR16 0000 1 e
Summary
0 .bss
23 .comment
4 .data
0 .note.GNU-stack
0 .text
(and ms linker rejects the fixup entries as invalid if I try to use
such a converted file...)
dd
--
Dave Denholm <address@hidden> http://www.esmertec.com
- objcopy elf32-i386 to pe-i386 breaks R_386_32 relocations,
Dave Denholm <=