Best Viewed Sources (Top 5)

Assembler syntax differences of ELF on Linux and PE-COFF on Windows

Last week when we tried to cross-compile shabal hash library for Windows using i686-w64-mingw32-as on Ubuntu, but we got the following error:

shabal.s: Assembler messages:
shabal.s:56: Warning: .type pseudo-op used outside of .def/.endef ignored.
shabal.s:56: Error: junk at end of line, first unrecognized character is `s'
shabal.s:1201: Warning: .size pseudo-op used outside of .def/.endef ignored.
shabal.s:1201: Error: junk at end of line, first unrecognized character is `s'
shabal.s:1208: Warning: .type pseudo-op used outside of .def/.endef ignored.
shabal.s:1208: Error: junk at end of line, first unrecognized character is `s'
shabal.s:1245: Warning: .size pseudo-op used outside of .def/.endef ignored.
shabal.s:1245: Error: junk at end of line, first unrecognized character is `s'
shabal.s:1249: Warning: .type pseudo-op used outside of .def/.endef ignored.
shabal.s:1249: Error: junk at end of line, first unrecognized character is `i'
shabal.s:1459: Warning: .size pseudo-op used outside of .def/.endef ignored.
shabal.s:1459: Error: junk at end of line, first unrecognized character is `i'
shabal.s:1463: Warning: .type pseudo-op used outside of .def/.endef ignored.
shabal.s:1463: Error: junk at end of line, first unrecognized character is `r'
shabal.s:1472: Warning: .size pseudo-op used outside of .def/.endef ignored.
shabal.s:1472: Error: junk at end of line, first unrecognized character is `r'
shabal.s:1489: Warning: .type pseudo-op used outside of .def/.endef ignored.
shabal.s:1489: Error: junk at end of line, first unrecognized character is `a'
shabal.s:1509: Warning: .size pseudo-op used outside of .def/.endef ignored.
shabal.s:1509: Error: junk at end of line, first unrecognized character is `a'
shabal.s:1520: Warning: .type pseudo-op used outside of .def/.endef ignored.
shabal.s:1520: Error: junk at end of line, first unrecognized character is `a'
shabal.s:1535: Warning: .size pseudo-op used outside of .def/.endef ignored.
shabal.s:1535: Error: junk at end of line, first unrecognized character is `a'
shabal.s:1543: Warning: .type pseudo-op used outside of .def/.endef ignored.
shabal.s:1543: Error: junk at end of line, first unrecognized character is `s'
shabal.s:1643: Warning: .size pseudo-op used outside of .def/.endef ignored.
shabal.s:1643: Error: junk at end of line, first unrecognized character is `s'
shabal.s:1652: Warning: .type pseudo-op used outside of .def/.endef ignored.
shabal.s:1652: Error: junk at end of line, first unrecognized character is `s'
shabal.s:1736: Warning: .size pseudo-op used outside of .def/.endef ignored.
shabal.s:1736: Error: junk at end of line, first unrecognized character is `s'
****  Error: junk at end of line, first unrecognized character is `s'
Makefile:24: recipe for target 'shabal.o' failed
make: *** [shabal.o] Error 1

The error seemed to be obvious. Because the assembler syntaxes of ELF on Linux and PE/COFF on Windows are different.

To see the actual differences, run this command in terminal of Ubuntu Linux first:

echo "void a_function_definition () { }" | gcc -S -x c - -o -

Result of gcc on Ubuntu:

.file    ""
    .text
    .globl    a_function_definition
    .type    a_function_definition, @function
a_function_definition:
.LFB0:
    .cfi_startproc
    pushl    %ebp
    .cfi_def_cfa_offset 8
    .cfi_offset 5, -8
    movl    %esp, %ebp
    .cfi_def_cfa_register 5
    nop
    popl    %ebp
    .cfi_restore 5
    .cfi_def_cfa 4, 4
    ret
    .cfi_endproc
.LFE0:
    .size    a_function_definition, .-a_function_definition
    .ident    "GCC: (Ubuntu 5.4.0-6ubuntu1~16.04.10) 5.4.0 20160609"
    .section    .note.GNU-stack,"",@progbits

Then run the following command for the cross-compiler i686-w64-mingw32-gcc on Ubuntu:

echo "void a_function_definition () { }" | i686-w64-mingw32-gcc -S -x c - -o -

Result of i686-w64-mingw32-gcc on Ubuntu:

    .file    ""
    .text
    .globl    _a_function_definition
    .def    _a_function_definition;    .scl    2;    .type    32;    .endef
_a_function_definition:
    pushl    %ebp
    movl    %esp, %ebp
    nop
    popl    %ebp
    ret
    .ident    "GCC: (GNU) 5.3.1 20160211"


Finally, run this command of mingw gcc on Windows:

echo "void a_function_definition () { }" | gcc -S -x c - -o -

Result of gcc on Windows:

        .file   ""
        .text
        .globl  _a_function_definition
        .def    _a_function_definition; .scl    2;      .type   32;     .endef
_a_function_definition:
LFB0:
        .cfi_startproc
        pushl   %ebp
        .cfi_def_cfa_offset 8
        .cfi_offset 5, -8
        movl    %esp, %ebp
        .cfi_def_cfa_register 5
        nop
        popl    %ebp
        .cfi_restore 5
        .cfi_def_cfa 4, 4
        ret
        .cfi_endproc
LFE0:
        .ident  "GCC: (i686-posix-dwarf-rev0, Built by MinGW-W64 project) 5.4.0"

So, we applied the fix by changing necessary def in the assembler code directly.

Run make again, and it works as expected.

0 comments:

Post a Comment

Best Viewed Sources (Weekly)

Search More Related Sources...