Runtime Checking Options

The +check options allow you to check your application for errors at runtime.

+check

+check=allnoneboundsglobalslockmallocstackthreadtruncateuninit

The +check=xxx options provide runtime checks to detect many common coding errors in the user program. These options introduce additional instructions for runtime checks that can significantly slow down the user program. By default, a failed check will result in the program aborting at the end of execution at runtime. In most cases, an error message and a stack trace will be emitted to stderr before program termination. The environment variable RTC_NO_ABORT can be set to 0, 1, or 2 to change the behavior of failed runtime checks:

0 — A failed runtime check will abort the program immediately after the error message is emitted.

1 — The default setting, which will abort the program at the end of execution upon failure.

2 — A failed runtime check will not enable the end of execution abort.

The +check options need to be specified at both compile time and link time, since they may require additional libraries to be linked into the user program. If different +check options are specified while compiling different source files, all the specified +check options are needed at link time.

Multiple +check options are interpreted left to right. In case of conflicting options, the one on the right will override an earlier +check option.

NOTE: The +check option is only supported on Integrity servers.

+check=all

The +check=all option enables all runtime checks provided by the compiler, except for +check=truncate, +check=lock, and +check=thread, which must be explicitly specified to enable them. It overrides any +check=xxx options that appear earlier on the command line. The +check=all option is currently equivalent to the following options:

+check=bounds:array +check=globals +check=malloc +check=stack:variables +check=uninit -z

The -zoption, which is part of +check=all, can be overridden by an explicit -Zoption.

+check=none

The +check=none option turns off all runtime checking options. It disables any +check=xxxoptions that appear earlier on the command line.

+check=bounds

The +check=bounds option enables checks for out-of-bounds references to array variables or to buffers through pointer access. The check is performed for each reference to an array element or pointer access. If a check fails, an error message is emitted and the program is aborted.

The +check=bounds option applies only to local and global array variables. It also applies to references to array fields of structs. It does not apply to arrays allocated dynamically using malloc or alloca.

You can specify one of the following +check=bounds suboptions:

array - Enables check for out-of-bounds references to array variables.

pointer - Enables check for out-of-bounds references to buffers through pointer access. The buffer could be a heap object, global variable, or local variable. This suboption also checks out-of-bounds access through common libc function calls such as strcpy, strcat, memset,

Runtime Checking Options 75

Page 75
Image 75
HP C/aC++ for PA-RISC Software manual Runtime Checking Options, +check=all, +check=none, +check=bounds