bug-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

COFF to ELF conversion bug?


From: Serge Semashko
Subject: COFF to ELF conversion bug?
Date: Wed, 8 May 2002 12:19:11 +0300

Hello All,

We are developing a crossplatform project. Some parts of our program are
written in assembly and compiled with TASM. Switch to other assembler
is impossible due to massive use of TASM specific macros. It is
possible to convert OMF object files to COFF using EDITBIN utility by
Microsoft. All these object files link well when the project is being
compiled with Mingw and everything works properly. The problems appear
when trying to compile the project in linux. The executable compiles
normally but when executed it dies from access violation signal.
Tracing the program with debugger shows that there is invalid code
generated for relative call instructions (0xE8 opcode). All the target
addresses are 4 bytes shifted and the program does not work. As far as
I know there is ELF object file format used in linux and it is likely
that object files are improperly converted from COFF to ELF.

This bug is easily reproduced with Mingw when using objcopy utility.
The steps of reproducing the bug are the following:
1. create a simple program test.cpp consisting of empty main function
2. compile it with Mingw compiler to get object code "gcc -c test.cpp"
3. convert the object file test.o with objcopy utility
   "objcopy -O elf32-i386 test.o"
4. link the program using "gcc test.o"
5. execute a.exe and see that it crashes.

When step 3 is skipped everything works well.

The disassemby of converted test.o file is listed bellow.

.text:08000000 _main           proc near
.text:08000000                 push    ebp            
.text:08000001                 mov     ebp, esp
.text:08000003                 sub     esp, 8
.text:08000006                 call    near ptr ___main+4
.text:0800000B                 xor     eax, eax
.text:0800000D                 jmp     short locret_8000014
.text:0800000F                 xor     eax, eax
.text:08000011                 jmp     short locret_8000014
.text:08000014 locret_8000014:
.text:08000014                 leave
.text:08000015                 retn
.text:08000015 _main           endp

PS. The objcopy utility works the same on Mingw and linux
with the latest development snapshot of binutils.

-- 
Best regards,
 Serge                          mailto:address@hidden





reply via email to

[Prev in Thread] Current Thread [Next in Thread]