Page 1 of 1

NASM 2.09 turns on optimisation by default

Posted: Fri Jul 15, 2011 10:24 am
by M-Saunders
Hi folks,

Just something I discovered today that may be useful (although I guess many people will already know about it). I was having some strange problems with MikeOS after building it on Ubuntu 11.04 (my test box had been running Ubuntu 9.04 before that). It turns out that NASM 2.09, released last year, enables the -Ox optimisation flag by default, which was doing funny things to my executables.

Using "-O0" (dash oh zero) fixed that and left the resulting binaries as intended. Just thought I'd note it here in case anyone has similar problems in the future and suspects it's something else in eg Linux/QEMU that's at fault (like I did for a few hours!).

Cheers,
Mike

Re: NASM 2.09 turns on optimisation by default

Posted: Fri Jul 15, 2011 11:07 am
by IanSeyler
They need to update the wording then. I just did a 'nasm -h' with 2.09.09:

-O<digit> optimize branch offsets
-O0: No optimization (default)
-O1: Minimal optimization
-Ox: Multipass optimization (recommended)

-Ian

Re: NASM 2.09 turns on optimisation by default

Posted: Fri Jul 15, 2011 10:46 pm
by Brendan
Hi,
M-Saunders wrote:It turns out that NASM 2.09, released last year, enables the -Ox optimisation flag by default, which was doing funny things to my executables.
For high level languages like C, when someone says "enabling optimisations breaks my code" it almost always means their code is wrong (e.g. missing "volatile" somewhere, use of uninitialised data, etc).

Given that NASM's optimiser doesn't really do much (optimises short/near jump offsets and simplifies a few operands); I'd be tempted to use the same logic for NASM - e.g. "enabling optimisations breaks my code" probably means your code is broken (e.g. missing "strict" qualifier somewhere, making assumptions about the length/s of instruction/s, etc). ;)


Cheers,

Brendan

Re: NASM 2.09 turns on optimisation by default

Posted: Sat Jul 16, 2011 5:44 am
by M-Saunders
Hi,

Ian: I just saw it here: http://www.nasm.us/doc/nasmdocc.html

"Make -Ox the default optimization level. For the legacy behavior, specify -O0 explicitly."

Brendan: Oh absolutely, and I suspect that this is symptomatic of another problem in my code. Still, with different people on the MikeOS mailing list having different kernels, going back to -O0 will have us all "singing from the same hymn sheet" and we can look at it from there.

Cheers,
Mike