|
相关文档找不到 __attribute__ 的用法, 写了一个测试文件编译通过。
- #include <stdint.h>
- uint32_t VarInSection __attribute__ ( (section (".Var")) );
- uint8_t AlignedArray[ 128 ] __attribute__( ( aligned( 128 ) ) );
- typedef struct
- {
- uint8_t Var8a;
- uint16_t Var16a __attribute__( ( aligned( 8 ) ) );
- uint32_t Text[ 4 ];
- } AlignedMember_TypeDef;
- AlignedMember_TypeDef AlignedMember;
- typedef struct __attribute__( (packed) )
- {
- uint8_t Var8a;
- uint16_t Var16a;
- uint32_t Text[ 4 ];
- } PackedStruct_TypeDef;
- PackedStruct_TypeDef PackedStruct;
- typedef struct
- {
- uint8_t Var8a;
- uint16_t Var16a;
- uint32_t Text[ 4 ];
- } __attribute__( (packed) ) PackedStruct2_TypeDef;
- PackedStruct2_TypeDef PackedStruct2;
- typedef struct __attribute__( (packed, aligned( 128 ) ) )
- {
- uint8_t Var8a;
- uint16_t Var16a;
- uint32_t Text[ 4 ];
- } AlignedPackedStruct_TypeDef;
- AlignedPackedStruct_TypeDef AlignedPackedStruct;
- void Foo( void ) __attribute__ ( (section (".Foo")) );
- void Foo( void )
- {
- VarInSection = 0;
- AlignedArray[ 0 ] = 0;
- PackedStruct.Text[ 0 ] = 1;
- PackedStruct2.Text[ 0 ] = 1;
- AlignedMember.Var16a = 0;
- AlignedPackedStruct.Text[ 0 ] = 1;
- }
- // .textrw and .text
- __root __ramfunc void ramfunc0(void)
- {
- }
- // No effect : .ramfunc
- __root void ramfunc1(void) __attribute__ ( (section(".ramfunc") ) );
- __root void ramfunc1(void)
- {
- ramfunc0();
- }
复制代码
列表文件部分内容
- *******************************************************************************
- *** PLACEMENT SUMMARY
- ***
- "A0": place at 0x00000000 { ro section .intvec };
- "P1": place in [from 0x00000000 to 0x0007ffff] { ro };
- "P3": place in [from 0x00000000 to 0x00000000] |
- [from 0x20000000 to 0x2000ffff] {
- rw, block CSTACK, block PROC_STACK, block HEAP };
- initialize by copy { rw };
- Section Kind Address Size Object
- ------- ---- ------- ---- ------
- "P1": 0x13a8
- .ramfunc ro code 0x0000133c 0x4 __attribute__.o [1]
- .Foo ro code 0x00001218 0x2c __attribute__.o [1]
- "P3", part 1 of 3: 0xb0
- .textrw inited 0x200000ac 0x2 __attribute__.o [1]
- "P3", part 2 of 3: 0x142c
- .bss zero 0x20001280 0x80 __attribute__.o [1]
- .bss zero 0x20001300 0x80 __attribute__.o [1]
- .bss zero 0x200014c4 0x14 __attribute__.o [1]
- .Var zero 0x200014d8 0x4 __attribute__.o [1]
- - 0x200014dc 0x142c
- *******************************************************************************
- *** ENTRY LIST
- ***
- Entry Address Size Type Object
- ramfunc1 0x0000133d 0x4 Code Gb __attribute__.o [1]
- ramfunc0 0x200000ad 0x2 Code Gb __attribute__.o [1]
- AlignedArray 0x20001280 0x80 Data Gb __attribute__.o [1]
- AlignedPackedStruct 0x20001300 0x80 Data Gb __attribute__.o [1]
- Foo 0x00001219 0x2c Code Gb __attribute__.o [1]
- PackedStruct 0x200014c4 0x14 Data Gb __attribute__.o [1]
- VarInSection 0x200014d8 0x4 Data Gb __attribute__.o [1]
复制代码
|
阿莫论坛20周年了!感谢大家的支持与爱护!!
一只鸟敢站在脆弱的枝条上歇脚,它依仗的不是枝条不会断,而是自己有翅膀,会飞。
|