Cleanup for cryptographic algorithms vs. compiler optimizations

Matthias Andree matthias.andree at
Sun Jun 13 10:44:08 UTC 2010

Am 13.06.2010, 00:52 Uhr, schrieb Bernd Walter:

>> In more general terms, the compiler is allowed to make any changes it
>> likes to the program as long as the end result behaves exactly like it
>> would if it hadn't been changed.  This is called the "as if" rule.  For
>> instance, if you call printf() or fprintf() with a format string that
>> does not contain any conversion specifiers, gcc will call gets() or
>> fgets() instead.
> Amazing - this is one of the things which can get nasty if you try some
> kind of microtuning.
> Recently I had to implement my own atoi on a controller because using the
> library one magically had blown my RAM usage by 1k on a controller with
> just 8k RAM.

There are certain compiler flags to affect that. For GCC, -Os is one  
(which doesn't necessarily work in FreeBSD though, on some versions the  
compiler would go into unterminated loop, leak memory and ultimately fail  
with OOM), flags to tell the compiler that the implementation is  
freestanding, and attributes to select builtins and the likes.

Matthias Andree

More information about the freebsd-current mailing list