Menu

#581 objcopy bug conversion from pe-i386 to elf32-i386

OTHER
closed
binutils (105)
out-of-date
Unknown
2013-02-04
2004-05-29
A Fog
No

I found a problem when using objcopy to convert object
files or static library files from pe-i386 to elf32-i386
format.

The problem is documented by the following test files:
---begin test1.cpp ---
#include <stdio.h>
extern "C" int test2();
int main () {
int i = test2();
printf ("%i\n", i);
return 0;}
--- end test1.cpp ---

---begin test2.asm ---
.386
.model flat
.code
public test2
extrn test3:near
test2 proc near
mov eax, 0
call test3
ret
test2 endp
end
--- end test2.asm ---

---begin test3.asm ---
.386
.model flat
.code
public test3

; this procedure should add 8 to eax.
test3 proc near
inc eax ; these instructions take 1 byte each
inc eax
inc eax
inc eax
inc eax
inc eax
inc eax
inc eax
ret
test3 endp
end
--- end test3.asm ---

Assemble the two .asm files with MASM v. 6.15 under
Windows or Wine:
ML /c /Cx /W3 /coff test2.asm test3.asm

Convert the two .obj files to ELF format using objcopy:
objcopy -Oelf32-i386 test2.obj test2.o
objcopy -Oelf32-i386 test3.obj test3.o

Now transfer test1.cpp, test2.o and test3.o to a Linux
or FreeBSD machine and compile/link them together and
run:
g++ test1.cpp test2.o test3.o
./a.out

The output of the test program is 4. The correct value
should be 8. The self-relative reference from test2 to
test3 points to an address that is 4 bytes too high. If
the two procedures test2 and test3 are in the same
module, then the result is correct (output = 8).

My guess is that the error is due to the two object file
formats differing in whether self-relative fixups are
calculated relative to the beginning or the end of the 32-
bit reference word.

This may be a generic error in the Gnu package, but I
can't check this because I don't know how to make Gnu
under Linux support the pe-i386 format.

The reason why I want to convert object files from pe-
i386 to elf32-i386 format is that the de-facto standard
MASM syntax for x86 assembly is not supported by any
assembler that can generate ELF output, and I want to
use the same assembly source under different operating
systems.

I am using objcopy version 2.15.90 from mingw32 binutils.

Discussion

  • A Fog

    A Fog - 2004-05-29

    Test program for objcopy bug

     
  • Earnie Boyd

    Earnie Boyd - 2013-02-04
    • status: open --> closed
    • resolution: --> out-of-date
    • category: --> Unknown
    • milestone: component_package --> OTHER