static variables some are seen in map and some are not seen in map

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
lock attach
Attachments are accessible only for community members.
BaT_3785171
Level 2
Level 2
First like given

43xxx_Wi-Fi project:

I modified linker script to add a section by name '.vtable' .Changes are as follows.

    .vtable :

    {

        link_vtable_start = .;

        *(.vtable)

        link_vtable_end = .;

    }> SRAM AT>SRAM :bss

I declared and used two variables in a file 43xxx_Wi-Fi_Check\apps\snip\scan\scan.c as follows

static int My_Variable_One __attribute__((section (".vtable")));

static int My_Variable_Two;

void application_start( )
{

    My_Variable_One = 1;
    My_Variable_Two = My_Variable_One;

}

I am able to see variable My_Variable_Two in map file.

I am not able to see variable My_Variable_One in map file.

Why this difference even though both are static variables?

0 Likes
1 Solution
PriyaM_16
Moderator
Moderator
Moderator
250 replies posted 100 replies posted 50 replies posted

Hello,

The inclusion of static variables in the map file is dependent on linker. You may check the wiced_toolchain_ARM_GNU.mk file in WICED to check the flags for release build and debug build.

Please check these two flags which are mainly responsible for optimization:

COMPILER_SPECIFIC_OPTIMIZED_CFLAGS    := -Os

COMPILER_SPECIFIC_UNOPTIMIZED_CFLAGS  := -O0

For release build, the optimization is -Os whereas for debug build there is no optimization O0. Hence all the symbols will be included in case of debug build while the release build has ~O2 level of optimization which removes the static variables which are not used in the code. The variable My_Variable_Two is assigned the value of My_Variable_One in application_start and hence it appears in the map file.

If you want to check how optimization affects the symbols in the map file, kindly build a project for debug and check the map file. Since there is no optimization, all the symbols(whether static and not used) are shown in the map file.

View solution in original post

1 Reply
PriyaM_16
Moderator
Moderator
Moderator
250 replies posted 100 replies posted 50 replies posted

Hello,

The inclusion of static variables in the map file is dependent on linker. You may check the wiced_toolchain_ARM_GNU.mk file in WICED to check the flags for release build and debug build.

Please check these two flags which are mainly responsible for optimization:

COMPILER_SPECIFIC_OPTIMIZED_CFLAGS    := -Os

COMPILER_SPECIFIC_UNOPTIMIZED_CFLAGS  := -O0

For release build, the optimization is -Os whereas for debug build there is no optimization O0. Hence all the symbols will be included in case of debug build while the release build has ~O2 level of optimization which removes the static variables which are not used in the code. The variable My_Variable_Two is assigned the value of My_Variable_One in application_start and hence it appears in the map file.

If you want to check how optimization affects the symbols in the map file, kindly build a project for debug and check the map file. Since there is no optimization, all the symbols(whether static and not used) are shown in the map file.