Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#1433 -masm=intel flag produces bad code

OTHER
closed
nobody
gcc (462)
Bug
out-of-date
Unknown
False
2013-02-07
2010-05-24
Michael Darrett
No

Invoking gcc on a C file with the -S -masm=intel flag, then assembling the assembly file produces binary code that crashes the system.

Test file bench.c:
#include <stdio.h>
#include <stdlib.h>

#define ARRAY_SIZE 64000000

int main(void) {
short *a; int *s; int i, j;

a = malloc(ARRAY_SIZE * sizeof(short));
s = malloc(ARRAY_SIZE * sizeof(int));
if (a == NULL || s == NULL) {
printf("Memory allocation failed.\n");
return -1;
}

printf("Starting...\n");

for (i = 0; i < ARRAY_SIZE; i++) {
s[i] += a[i];
}
printf( "Finishing...\n" );

free(a); free(s);
return 0;
}

Compiling (these commands work):
gcc -S bench.c
gcc -x assembler bench.s -o works.exe

Compiling (these commands produce a bad .exe file):
gcc -S -masm=intel bench.c -o fail.s
gcc -x assembler fail.s -o fail.exe

Comparison of the EXE files:
Comparing files fail.exe and WORKS.EXE
00000088: 73 74
000000D8: D4 D5
000000D9: B1 9E
0000078B: D6 C3

I'm running gcc-3.4.5-20060117-3 with GNU ld (GNU Binutils) 2.20 on Windows XP Professional from the command-line.

Discussion

  • Earnie Boyd
    Earnie Boyd
    2013-02-07

    • status: open --> closed
    • milestone: --> OTHER
    • type: --> Bug
    • resolution: --> out-of-date
    • category: --> Unknown
    • patch_attached: --> False