Everything

 

-stack_protector/-stack_protector_all [Professional Edition only] [V1.02 or later]


This option generates a code for detection of stack smashing.

[Specification format]

-stack_protector[=num]
-stack_protector_all[=num]

 

-

Interpretation when omitted

A code for detection of stack smashing is not generated.

[Detailed description]

-

This option generates a code for detection of stack smashing at the entry and end of a function.

-

A 2-byte area is allocated just before the local variable area (in the direction towards address 0xFFFFF) at the entry to a function, and the value specified by num is stored. After that, the 2-byte area in which num was stored is checked for smashing at the end of the function. If smashing has occurred, the __stack_chk_fail function is called.

-

The __stack_chk_fail function needs to be created by the user. It should be defined as a function having no parameters or return values, it should be located in the far area, and the processing to be executed at stack smashing should be written.

-

Do not define the function as static.

-

When calling another function in the __stack_chk_fail function, note that stack smashing is not detected recursively in the function that was called.

-

Specify an integer from 0 to 65535 for num.

-

If num is omitted, the compiler automatically determines the integer value.

-

If -stack_protector is specified, this option generates a code for detection of stack smashing for only functions having a structure, union, or array that exceeds eight bytes as a local variable.

-

If -stack_protector_all is specified, this option generates a code for detection of stack smashing for all functions.

-

If this option is used simultaneously with #pragma stack_protector, the specification by #pragma stack_protector becomes valid.

-

A code for detection of stack smashing is not generated for the functions in which the following is specified.

#pragma inline, __inline keyword, #pragma inline_asm, #pragma no_stack_protector, #pragma rtos_interrupt, or #pragma rtos_task

[Example of use]

-

To generate a code for detection of stack smashing, describe as:

>ccrl -stack_protector=1000 -cpu=S2 -dev=dr5f100pj.dvf main.c