Optimization Disables Insertion of Address-Size Override Prefix

Viewed 196

When compiling this:

#include <inttypes.h>

void foo(void)
{
        *(uint16_t *) (0xb8000) = 0xf61;
}

with

gcc test.c -c -m16 -O1

I get the following warning:

/tmp/ccyziKm4.s: Assembler messages:
/tmp/ccyziKm4.s:9: Warning: 753664 shortened to 32768

And when I drop the -O1 switch, I get none and gcc uses the 0x67 prefix to switch address size as expected (-m16 basically emits prefixed 32-bit code):

00000000 <foo>:
   0:   66 55                   push   %ebp
   2:   66 89 e5                mov    %esp,%ebp
   5:   66 b8 00 80 0b 00       mov    $0xb8000,%eax
   b:   67 c7 00 61 0f          movw   $0xf61,(%eax)
  10:   90                      nop
  11:   66 5d                   pop    %ebp
  13:   66 c3                   retl

So, obviously this has something to do with the optimization switch -O1. The gcc man page describes all the options it sets and I wrote a script to single out every one of them and pass them to gcc, but it doesn't really work. Now, gcc does not show the warning at all, even with the whole bunch of them.

I appreciate any suggestions on how to resolve this.

1 Answers
Related