定义一个初始化的全局变量 占用initialized data :4 占用uninitialized data:1
定义一个未初始化的全局变量 占用initialized data :0 占用uninitialized data:1
这怎么解释??????
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
定义一个初始化的全局变量 占用initialized data :4 占用uninitialized data:1
定义一个未初始化的全局变量 占用initialized data :0 占用uninitialized data:1
这怎么解释??????
无法上传文件啊
初始化的,以上
--------------------------------------------------------------------
未初始化的 以下
****************************************************************************** TMS320C2000 Linker PC v21.6.0 ****************************************************************************** >> Linked Wed Dec 6 08:43:45 2023 OUTPUT FILE NAME: <test.out> ENTRY POINT SYMBOL: "_c_int00" address: 0000a000 MEMORY CONFIGURATION name origin length used unused attr fill ---------------------- -------- --------- -------- -------- ---- -------- PAGE 0: BEGIN 00000000 00000002 00000000 00000002 RWIX RAMM0 00000052 000003ae 00000000 000003ae RWIX RAML0 00008000 00002000 0000001e 00001fe2 RWIX RAML1 0000a000 00002000 000000e0 00001f20 RWIX ZONE7A 00200000 0000fc00 00000000 0000fc00 RWIX RAMH0 00300000 00008000 00000000 00008000 RWIX RAMH1 00308000 00008000 00000000 00008000 RWIX RAMH2 00310000 00008000 00000000 00008000 RWIX CSM_RSVD 0033ff80 00000076 00000000 00000076 RWIX CSM_PWL_PROG 0033fff8 00000008 00000000 00000008 RWIX IQTABLES 003fe000 00000b50 00000000 00000b50 RWIX IQTABLES2 003feb50 0000008c 00000000 0000008c RWIX FPUTABLES 003febdc 000006a0 00000000 000006a0 RWIX BOOTROM 003ff27c 00000d44 00000000 00000d44 RWIX RESET 003fffc0 00000002 00000000 00000002 RWIX PAGE 1: BOOT_RSVD 00000002 00000050 00000000 00000050 RWIX RAMM1 00000400 00000400 00000300 00000100 RWIX RAML2 0000c000 00002000 0000000b 00001ff5 RWIX RAML3 0000e000 00002000 00000000 00002000 RWIX RAML4 00010000 00002000 00000000 00002000 RWIX RAML5 00012000 00002000 00000000 00002000 RWIX RAML6 00014000 00002000 00000000 00002000 RWIX RAML7 00016000 00002000 00000000 00002000 RWIX ZONE7B 0020fc00 00000400 00000000 00000400 RWIX RAMH3 00318000 00008000 00000000 00008000 RWIX RAMH4 00320000 00008000 00000000 00008000 RWIX RAMH5 00328000 00008000 00000000 00008000 RWIX SECTION ALLOCATION MAP output attributes/ section page origin length input sections -------- ---- ---------- ---------- ---------------- .cinit 0 00008000 0000001e 00008000 0000000e rts2800_fpu32.lib : exit.c.obj (.cinit) 0000800e 00000005 : _lock.c.obj (.cinit:__lock) 00008013 00000005 : _lock.c.obj (.cinit:__unlock) 00008018 00000004 main.obj (.cinit) 0000801c 00000002 --HOLE-- [fill = 0] .text 0 0000a000 000000e0 0000a000 00000056 rts2800_fpu32.lib : boot28.asm.obj (.text) 0000a056 00000029 : exit.c.obj (.text) 0000a07f 00000024 : cpy_tbl.c.obj (.text) 0000a0a3 0000001d : memcpy.c.obj (.text) 0000a0c0 00000012 : args_main.c.obj (.text) 0000a0d2 00000009 : _lock.c.obj (.text) 0000a0db 00000002 main.obj (.text) 0000a0dd 00000002 rts2800_fpu32.lib : pre_init.c.obj (.text) 0000a0df 00000001 : startup.c.obj (.text) .pinit 0 00008000 00000000 UNINITIALIZED .stack 1 00000400 00000300 UNINITIALIZED 00000400 00000300 --HOLE-- .ebss 1 0000c000 0000000b UNINITIALIZED 0000c000 00000006 rts2800_fpu32.lib : exit.c.obj (.ebss) 0000c006 00000002 : _lock.c.obj (.ebss:__lock) 0000c008 00000002 : _lock.c.obj (.ebss:__unlock) 0000c00a 00000001 main.obj (.ebss) .reset 0 003fffc0 00000002 DSECT 003fffc0 00000002 rts2800_fpu32.lib : boot28.asm.obj (.reset) csm_rsvd 0 0033ff80 00000000 DSECT csmpasswds * 0 0033fff8 00000000 DSECT MODULE SUMMARY Module code initialized data uninitialized data ------ ---- ---------------- ------------------ .\ main.obj 2 4 1 +--+-----------------+------+------------------+--------------------+ Total: 2 4 1 C:\ti\ccsv7\tools\compiler\ti-cgt-c2000_21.6.0.LTS\lib\rts2800_fpu32.lib boot28.asm.obj 86 0 0 exit.c.obj 41 14 6 cpy_tbl.c.obj 36 0 0 memcpy.c.obj 29 0 0 _lock.c.obj 9 10 4 args_main.c.obj 18 0 0 pre_init.c.obj 2 0 0 startup.c.obj 1 0 0 +--+-----------------+------+------------------+--------------------+ Total: 222 24 10 Stack: 0 0 768 +--+-----------------+------+------------------+--------------------+ Grand Total: 224 28 779 GLOBAL DATA SYMBOLS: SORTED BY DATA PAGE address data page name -------- ---------------- ---- 00000400 10 (00000400) __stack 0000c000 300 (0000c000) ___TI_enable_exit_profile_output 0000c002 300 (0000c000) ___TI_cleanup_ptr 0000c004 300 (0000c000) ___TI_dtors_ptr 0000c006 300 (0000c000) __lock 0000c008 300 (0000c000) __unlock 0000c00a 300 (0000c000) _aa GLOBAL SYMBOLS: SORTED ALPHABETICALLY BY Name page address name ---- ------- ---- 0 0000a000 .text 0 0000a056 C$$EXIT 1 00000700 __STACK_END abs 00000300 __STACK_SIZE 1 0000c002 ___TI_cleanup_ptr 1 0000c004 ___TI_dtors_ptr 1 0000c000 ___TI_enable_exit_profile_output abs ffffffff ___TI_pprof_out_hndl abs ffffffff ___TI_prof_data_size abs ffffffff ___TI_prof_data_start abs ffffffff ___binit__ abs ffffffff ___c_args__ 0 00008000 ___cinit__ 0 0000a0e0 ___etext__ abs ffffffff ___pinit__ 0 0000a000 ___text__ 0 0000a0c0 __args_main 1 0000c006 __lock 0 0000a0da __nop 0 0000a0d6 __register_lock 0 0000a0d2 __register_unlock 1 00000400 __stack 0 0000a0df __system_post_cinit 0 0000a0dd __system_pre_init 1 0000c008 __unlock 1 0000c00a _aa 0 0000a056 _abort 0 0000a000 _c_int00 0 0000a07f _copy_in 0 0000a058 _exit 0 0000a0db _main 0 0000a0a3 _memcpy abs ffffffff binit 0 00008000 cinit 0 0000a0e0 etext abs ffffffff pinit GLOBAL SYMBOLS: SORTED BY Symbol Address page address name ---- ------- ---- 0 00008000 ___cinit__ 0 00008000 cinit 0 0000a000 .text 0 0000a000 ___text__ 0 0000a000 _c_int00 0 0000a056 C$$EXIT 0 0000a056 _abort 0 0000a058 _exit 0 0000a07f _copy_in 0 0000a0a3 _memcpy 0 0000a0c0 __args_main 0 0000a0d2 __register_unlock 0 0000a0d6 __register_lock 0 0000a0da __nop 0 0000a0db _main 0 0000a0dd __system_pre_init 0 0000a0df __system_post_cinit 0 0000a0e0 ___etext__ 0 0000a0e0 etext 1 00000400 __stack 1 00000700 __STACK_END 1 0000c000 ___TI_enable_exit_profile_output 1 0000c002 ___TI_cleanup_ptr 1 0000c004 ___TI_dtors_ptr 1 0000c006 __lock 1 0000c008 __unlock 1 0000c00a _aa abs 00000300 __STACK_SIZE abs ffffffff ___TI_pprof_out_hndl abs ffffffff ___TI_prof_data_size abs ffffffff ___TI_prof_data_start abs ffffffff ___binit__ abs ffffffff ___c_args__ abs ffffffff ___pinit__ abs ffffffff binit abs ffffffff pinit [36 symbols]
****************************************************************************** TMS320C2000 Linker PC v21.6.0 ****************************************************************************** >> Linked Wed Dec 6 08:49:17 2023 OUTPUT FILE NAME: <test.out> ENTRY POINT SYMBOL: "_c_int00" address: 0000a000 MEMORY CONFIGURATION name origin length used unused attr fill ---------------------- -------- --------- -------- -------- ---- -------- PAGE 0: BEGIN 00000000 00000002 00000000 00000002 RWIX RAMM0 00000052 000003ae 00000000 000003ae RWIX RAML0 00008000 00002000 0000001a 00001fe6 RWIX RAML1 0000a000 00002000 000000e0 00001f20 RWIX ZONE7A 00200000 0000fc00 00000000 0000fc00 RWIX RAMH0 00300000 00008000 00000000 00008000 RWIX RAMH1 00308000 00008000 00000000 00008000 RWIX RAMH2 00310000 00008000 00000000 00008000 RWIX CSM_RSVD 0033ff80 00000076 00000000 00000076 RWIX CSM_PWL_PROG 0033fff8 00000008 00000000 00000008 RWIX IQTABLES 003fe000 00000b50 00000000 00000b50 RWIX IQTABLES2 003feb50 0000008c 00000000 0000008c RWIX FPUTABLES 003febdc 000006a0 00000000 000006a0 RWIX BOOTROM 003ff27c 00000d44 00000000 00000d44 RWIX RESET 003fffc0 00000002 00000000 00000002 RWIX PAGE 1: BOOT_RSVD 00000002 00000050 00000000 00000050 RWIX RAMM1 00000400 00000400 00000300 00000100 RWIX RAML2 0000c000 00002000 0000000b 00001ff5 RWIX RAML3 0000e000 00002000 00000000 00002000 RWIX RAML4 00010000 00002000 00000000 00002000 RWIX RAML5 00012000 00002000 00000000 00002000 RWIX RAML6 00014000 00002000 00000000 00002000 RWIX RAML7 00016000 00002000 00000000 00002000 RWIX ZONE7B 0020fc00 00000400 00000000 00000400 RWIX RAMH3 00318000 00008000 00000000 00008000 RWIX RAMH4 00320000 00008000 00000000 00008000 RWIX RAMH5 00328000 00008000 00000000 00008000 RWIX SECTION ALLOCATION MAP output attributes/ section page origin length input sections -------- ---- ---------- ---------- ---------------- .cinit 0 00008000 0000001a 00008000 0000000e rts2800_fpu32.lib : exit.c.obj (.cinit) 0000800e 00000005 : _lock.c.obj (.cinit:__lock) 00008013 00000005 : _lock.c.obj (.cinit:__unlock) 00008018 00000002 --HOLE-- [fill = 0] .text 0 0000a000 000000e0 0000a000 00000056 rts2800_fpu32.lib : boot28.asm.obj (.text) 0000a056 00000029 : exit.c.obj (.text) 0000a07f 00000024 : cpy_tbl.c.obj (.text) 0000a0a3 0000001d : memcpy.c.obj (.text) 0000a0c0 00000012 : args_main.c.obj (.text) 0000a0d2 00000009 : _lock.c.obj (.text) 0000a0db 00000002 main.obj (.text) 0000a0dd 00000002 rts2800_fpu32.lib : pre_init.c.obj (.text) 0000a0df 00000001 : startup.c.obj (.text) .pinit 0 00008000 00000000 UNINITIALIZED .stack 1 00000400 00000300 UNINITIALIZED 00000400 00000300 --HOLE-- .ebss 1 0000c000 0000000b UNINITIALIZED 0000c000 00000006 rts2800_fpu32.lib : exit.c.obj (.ebss) 0000c006 00000002 : _lock.c.obj (.ebss:__lock) 0000c008 00000002 : _lock.c.obj (.ebss:__unlock) 0000c00a 00000001 main.obj (.ebss) .reset 0 003fffc0 00000002 DSECT 003fffc0 00000002 rts2800_fpu32.lib : boot28.asm.obj (.reset) csm_rsvd 0 0033ff80 00000000 DSECT csmpasswds * 0 0033fff8 00000000 DSECT MODULE SUMMARY Module code initialized data uninitialized data ------ ---- ---------------- ------------------ .\ main.obj 2 0 1 +--+-----------------+------+------------------+--------------------+ Total: 2 0 1 C:\ti\ccsv7\tools\compiler\ti-cgt-c2000_21.6.0.LTS\lib\rts2800_fpu32.lib boot28.asm.obj 86 0 0 exit.c.obj 41 14 6 cpy_tbl.c.obj 36 0 0 memcpy.c.obj 29 0 0 _lock.c.obj 9 10 4 args_main.c.obj 18 0 0 pre_init.c.obj 2 0 0 startup.c.obj 1 0 0 +--+-----------------+------+------------------+--------------------+ Total: 222 24 10 Stack: 0 0 768 +--+-----------------+------+------------------+--------------------+ Grand Total: 224 24 779 GLOBAL DATA SYMBOLS: SORTED BY DATA PAGE address data page name -------- ---------------- ---- 00000400 10 (00000400) __stack 0000c000 300 (0000c000) ___TI_enable_exit_profile_output 0000c002 300 (0000c000) ___TI_cleanup_ptr 0000c004 300 (0000c000) ___TI_dtors_ptr 0000c006 300 (0000c000) __lock 0000c008 300 (0000c000) __unlock 0000c00a 300 (0000c000) _aa GLOBAL SYMBOLS: SORTED ALPHABETICALLY BY Name page address name ---- ------- ---- 0 0000a000 .text 0 0000a056 C$$EXIT 1 00000700 __STACK_END abs 00000300 __STACK_SIZE 1 0000c002 ___TI_cleanup_ptr 1 0000c004 ___TI_dtors_ptr 1 0000c000 ___TI_enable_exit_profile_output abs ffffffff ___TI_pprof_out_hndl abs ffffffff ___TI_prof_data_size abs ffffffff ___TI_prof_data_start abs ffffffff ___binit__ abs ffffffff ___c_args__ 0 00008000 ___cinit__ 0 0000a0e0 ___etext__ abs ffffffff ___pinit__ 0 0000a000 ___text__ 0 0000a0c0 __args_main 1 0000c006 __lock 0 0000a0da __nop 0 0000a0d6 __register_lock 0 0000a0d2 __register_unlock 1 00000400 __stack 0 0000a0df __system_post_cinit 0 0000a0dd __system_pre_init 1 0000c008 __unlock 1 0000c00a _aa 0 0000a056 _abort 0 0000a000 _c_int00 0 0000a07f _copy_in 0 0000a058 _exit 0 0000a0db _main 0 0000a0a3 _memcpy abs ffffffff binit 0 00008000 cinit 0 0000a0e0 etext abs ffffffff pinit GLOBAL SYMBOLS: SORTED BY Symbol Address page address name ---- ------- ---- 0 00008000 ___cinit__ 0 00008000 cinit 0 0000a000 .text 0 0000a000 ___text__ 0 0000a000 _c_int00 0 0000a056 C$$EXIT 0 0000a056 _abort 0 0000a058 _exit 0 0000a07f _copy_in 0 0000a0a3 _memcpy 0 0000a0c0 __args_main 0 0000a0d2 __register_unlock 0 0000a0d6 __register_lock 0 0000a0da __nop 0 0000a0db _main 0 0000a0dd __system_pre_init 0 0000a0df __system_post_cinit 0 0000a0e0 ___etext__ 0 0000a0e0 etext 1 00000400 __stack 1 00000700 __STACK_END 1 0000c000 ___TI_enable_exit_profile_output 1 0000c002 ___TI_cleanup_ptr 1 0000c004 ___TI_dtors_ptr 1 0000c006 __lock 1 0000c008 __unlock 1 0000c00a _aa abs 00000300 __STACK_SIZE abs ffffffff ___TI_pprof_out_hndl abs ffffffff ___TI_prof_data_size abs ffffffff ___TI_prof_data_start abs ffffffff ___binit__ abs ffffffff ___c_args__ abs ffffffff ___pinit__ abs ffffffff binit abs ffffffff pinit [36 symbols]
左侧为初始化变量的map, 右侧为未初始化变量的map
主要的区别在这里,.cinit段。
对于COFF格式,未初始化的全局变量分配在.ebss段(全局变量是运行时初始化,所以编译之后全局变量属于未被初始化的部分),而初始化值储存在.cinit段用于初始化全局变量的表中。在器件上电后,由 _c_int00 函数将初始化值从.cinit段复制到.ebss,完成全局变量的运行时初始化。
可以看到,左侧有为.cinit分配相应的空间。
map文件中统计的大小是按字节8位算的,还是按字16位算的?
我定义了一个 int a; 占用uninitialized data:1 可以理解位一个16位的字
而我定义一个 int a = 1; 占用ninitialized data:1 ,initialized data :4,您的意思这个初始化的数字1这个数也占一个内存,我理解initialized data 也应该为1才对,为什么会是4呢?占用四倍的内存?
1. 16位,C2000的一个地址上都是16位;
2. 因为.cinit段中包含的不仅仅只有需要拷贝的值,还有一些其它信息,比如一些标志位,以及值与全局变量之间的映射(这个是我的推测),来控制拷贝的过程。比如,请看一下zhcu875z_TMS320C28x 汇编语言工具 v22.6.0.LTS (Rev. Z)第42、43页:
它是有自己的格式的。
更多的信息,汇编手册中也没有描述了,这些都是与更底层的编译器相关的东西了。如果感兴趣的话你可以查一下相关方面的资料;也可以结合目标文件中相关位置的内容来看一下。
感谢!
1、这里提到EABI与COFF,这两种格式较老的C2000 处理器(如F28335,C28346)支持EABI格式吗?
2、EABI 格式的就不会存在讨论初始化和未初始化占用字节不一致的问题,但是较老的C2000的一些库都是COFF格式的不支持设置成EABI格式共同编译,fatal error #16000: object files have incompatible formats ("C:/ti/ccsv7/tools/compiler/ti-cgt-c2000_21.6.0.LTS/lib/rts2800_fpu32.lib<boot28.asm.obj>" = TI-COFF, "./main.obj" = ELF)
没有,较老的器件只有COFF格式的;对于新的器件,正在逐步迁移到EABI格式。
另外COFF格式的文档也供参考:spraao8_Common Object File Format (COFF