4.2.1.26 The optimization test

  Problem:  Insufficient optimization prevents security features from working
  Fix By:   Compiling with -O2
  Waive If: The application does not use string/memory functions
  
  Example:  FAIL: optimization test because optimization level too low
  Example:  FAIL: optimization test because level too low
  Example:  MAYB: optimization test because no valid notes found regarding this test

This test checks that the application was compiled with sufficient optimization enabled.

The C library security hardening features enabled via the -D_FORTIFY_SOURCE=2 or -D_FORTIFY_SOURCE=3 preprocessor command line options will only work properly if the compiler is run at an optimization level of at least -O2. Hence this test checks to make sure that this level (or higher) has been used.

Normally the only reason for not using -O2 or higher is because the application is space sensitive and needs to be compiled with -Os or the compilation process is so time intensive that using -O0 is the only way to obtain reasonable build times.

If necessary the test can be disabled via the --skip-optimization option and re-enabled via the --test-optimization option.