STACKPROTECT | NOSTACKPROTECT

Category

Error checking and debugging

Pragma equivalent

None.

Purpose

Provides protection against malicious code or programming errors that overwrite or corrupt the stack.

Syntax

Read syntax diagramSkip visual syntax diagramNOSTACKPROTECTSTACKPROTECT(ALLSIZE(n)NOSKIPSPCSKIPSPC)

Defaults

NOSTACKPROTECT

Parameters

ALL
Protects all procedures whether they have vulnerable objects or not.
SIZE(n)
Protects all procedures with vulnerable objects whose sizes are greater than or equal to n bytes. The value of n cannot exceed 231 - 2. The default size is 8 bytes, and STACKPROTECT expands to STACKPROTECT(SIZE(8)) only if you do not set the value of the SIZE parameter explicitly.
SKIPSPC | NOSKIPSPC
Ignores the stack protection checks if the generated code is running in SPC mode. This suboption should be specified only if the module runs in an SPC environment; otherwise, it might cause performance degradation. This suboption requires ARCH(7) or a higher level. NOSKIPSPC is the default.
Note: Examples of vulnerable objects include arrays, variable length arrays, objects that are created from the alloca() function, and variables that have their address taken.

Usage

The protection takes effect only if the compilation unit that contains the main function is compiled with STACKPROTECT. Otherwise, the protection will not apply to any linked libraries even if the libraries have been compiled with STACKPROTECT. STACKPROTECT generates extra code to protect procedures with vulnerable objects against stack corruption. This option is disabled by default because it can cause performance degradation.

Occasionally, the compiler optimizes certain procedures into leaf procedures. In this case, STACKPROTECT is not enabled for the procedure and a warning message is generated if INFO(STP) is enabled.

This option cannot be used with pragma options. #pragma info(stp) is not supported.

The usage status of this option is inserted in the object file to aid you in diagnosing a problem with your program.

IPA effects

If you specify the STACKPROTECT option for any compilation unit in the IPA compile step, the compiler generates information for the IPA link step. This option also affects the regular object module if you request one by specifying the IPA(OBJECT) option.

The IPA link step merges and optimizes the application code; then the IPA link step divides it into sections for code generation. Each of these sections is a partition.

If you specify the STACKPROTECT option on the IPA link step, it uses the value of that option for all partitions. The IPA link step Prolog and all Partition Map sections of the IPA link step listing display that value.

If you do not specify the option on the IPA link step, the value used for a partition depends on the value on the IPA compile step for each compilation unit that provided code for that partition.

The object module and the Partition Map section of the IPA link step listing display the final option value for each partition. If you override this option on the IPA link step, the Prolog section of the IPA link step listing displays the value of the option.

The Compiler Options Map section of the IPA link step listing displays the option value that you specified for each IPA object file during the IPA compile step.

Predefined macros

None.

Related information