understanding size command for data bss segment in C

后端 未结 3 634
滥情空心
滥情空心 2021-01-05 15:03

I\'m getting unexpected output from size command.

Afaik initialized global and static variables stored in data segment and uninitialized

3条回答
  •  孤城傲影
    2021-01-05 15:29

    This is from gcc on linux:

    No Variable
       text    data     bss     dec     hex filename
        915     248       8    1171     493 none.out
    Uninitialized Global
       text    data     bss     dec     hex filename
        915     248      12    1175     497 u_g.out
    Initialized Global to 123
       text    data     bss     dec     hex filename
        915     252       8    1175     497 i_g.out
    Initialized Local to 124
       text    data     bss     dec     hex filename
        915     252       8    1175     497 i_l.out
    Initialized Global to 0
       text    data     bss     dec     hex filename
        915     248      12    1175     497 i_g_0.out
    Initialized Local to 0
       text    data     bss     dec     hex filename
        915     248      12    1175     497 i_l_0.out
    

    This is from mingw64 on Windows:

    No Variable
       text    data     bss     dec     hex filename
       3173    1976     448    5597    15dd none.out
    Uninitialized Global
       text    data     bss     dec     hex filename
       3173    1976     464    5613    15ed u_g.out
    Initialized Global to 123
       text    data     bss     dec     hex filename
       3173    1976     448    5597    15dd i_g.out
    Initialized Local to 124
       text    data     bss     dec     hex filename
       3173    1976     448    5597    15dd i_l.out
    Initialized Global to 0
       text    data     bss     dec     hex filename
       3173    1976     480    5629    15fd i_g_0.out
    Initialized Local to 0
       text    data     bss     dec     hex filename
       3173    1976     480    5629    15fd i_l_0.out
    

    So although I don't have a final answer to the question (wouldn't fit in a comment), results make me suspect the executable file format of Windows and/or MinGW (i.e. not gcc).

提交回复
热议问题