[英]How to place variables in IAR compiler in specific order?
我正在嘗試將一些變量放入特定的 ROM lication 中。
在linker配置文件中:
define symbol __ICFEDIT_region_APP_ROM_start__ = 0x08070000 ;
define symbol __ICFEDIT_region_APP_ROM_end__ = 0x0807FFFF;
define region APP_ROM_region = mem:[from __ICFEDIT_region_APP_ROM_start__ to __ICFEDIT_region_APP_ROM_end__];
place in APP_ROM_region { readonly section test_data};
在源文件中:
#pragma default_variable_attributes = @ "test_data"
const U8 testVar8 = 0;
const U8 testArray512[512];
const uint32_t testVar32 = 0x1234ABCD;
const U8 testArray500[500];
#pragma default_variable_attributes =
生成的.map文件:
test_data const 0x08070000 0x200 source_file.o [1]
test_data const 0x08070200 0x1f4 source_file.o [1]
test_data const 0x080703f4 0x4 source_file.o [1]
test_data const 0x080703f8 0x1 source_file.o [1]
testArray512 0x08070000 0x200 Data Gb source_file.o [1]
testArray500 0x08070200 0x1f4 Data Gb source_file.o [1]
testVar32 0x080703f4 0x4 Data Gb source_file.o [1]
testVar8 0x080703f8 0x1 Data Gb source_file.o [1]
無論如何它都有效 - 變量位於正確的部分。
但是由於變量的大小,linker 已經把它整理好了。
有沒有辦法告訴 linker 不要更改變量的順序,所以它們會以與源文件中聲明的順序相同的順序出現在 map 文件中?
目標是:
testArray8 0x08070000 0x1 Data Gb source_file.o [1]
testArray512 0x08070001 0x200 Data Gb source_file.o [1]
testVar32 0x08070201 0x4 Data Gb source_file.o [1]
testVar500 0x08070205 0x1f4 Data Gb source_file.o [1]
有沒有辦法告訴 linker 不要更改變量的順序,所以它們會以與源文件中聲明的順序相同的順序出現在 map 文件中?
我不知道強制 linker 尊重源文件中的變量順序的選項。
但是有一種方法可以使用 linker 配置文件中的block
指令來實現您的目標。
IAR C/C++ 開發指南說明了指令中的place in
:
指令
place in
將部分和塊放置在特定區域中。 部分和塊將以任意順序放置在該區域中。 要指定特定順序,請使用block
指令。
因此,在源文件中的每個變量都需要將 go 放到一個單獨的部分中:
const U8 testVar8 @ test_data_1 = 0;
const U8 testArray512[512] @ test_data_2;
const uint32_t testVar32 @ test_data_3 = 0x1234ABCD;
const U8 testArray500[500] @ test_data_4;
在 linker 配置文件中,我們按所需順序添加帶有test_data_*
部分的block
定義,並將其放在目標區域的開頭:
define symbol __ICFEDIT_region_APP_ROM_start__ = 0x08070000 ;
define symbol __ICFEDIT_region_APP_ROM_end__ = 0x0807FFFF;
define region APP_ROM_region = mem:[from __ICFEDIT_region_APP_ROM_start__ to __ICFEDIT_region_APP_ROM_end__];
define block TEST_DATA with fixed order {
readonly section test_data_1,
readonly section test_data_2,
readonly section test_data_3,
readonly section test_data_4
};
place at start of APP_ROM_region { block TEST_DATA };
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.