|
大家好,请教大家一个链接脚本的问题:
main.c
- #include <stdio.h>
- typedef struct
- {
- const char *name;
- void (*func)(void);
- } S_NEWDATA;
- #define __add_to_newdata(x) const S_NEWDATA x __attribute__ ((section(".newdata")))
- static void func1(void)
- {
- printf("%s\n", __func__);
- }
- static void func2(void)
- {
- printf("%s\n", __func__);
- }
- __add_to_newdata(newdata1) = {
- "data1",
- func1,
- };
- __add_to_newdata(newdata2) = {
- "data2",
- func2,
- };
- extern unsigned int __newdata_addr_start;
- extern unsigned int __newdata_addr_end;
- int main()
- {
- const char *name = "data2";
- S_NEWDATA *p = (S_NEWDATA *)&__newdata_addr_start;
- while (p++ <= (S_NEWDATA *)&__newdata_addr_end) {
- if (p->name == name) {
- p->func();
- break;
- }
- }
- }
复制代码
ldscript.ld
- SECTIONS
- {
- .text : { *(.text) }
- . = 0x6000000 ;
- .newdata :
- {
- __newdata_addr_start = . ;
- *(.newdata)
- __newdata_addr_end = . ;
- }
- . = 0x8000000 ;
- .data : { *(.data) }
- .bss : { *(.bss) }
- }
复制代码
想模仿驱动的结构实现模块化,看了脚本的教程,没有完全理解。上面的脚本是错误的,错在哪里呢?正确的又该怎么写? |
|