使用方式如下:
链接脚本:
Code:
Select all
...
. = ALIGN(4);
user_sec
tion_tab_local_start = ABSOLUTE(.);
KEEP (*(SORT(*user_section_tab*)))
user_section_tab_local_end = ABSOLUTE(.);
...
a.h:
Code:
Select all
#define USER_SECTION_NAME __attribute__((section("user_section_name_tab")))
#define USER_SECTION __attribute__((section("user_section_tab")))
extern void *user_section_tab_local_start;
extern void *user_section_tab_local_end;
const static uint32_t user_section_tab_local_start_addr = (uint32_t)&user_section_tab_local_start;
const static uint32_t user_section_tab_local_end_addr = (uint32_t)&user_section_tab_local_end;
b.h:
Code:
Select all
typedef int (*user_func_t)(void *);
struct user_cmd_object {
user_func_t func;
const char *breif;
uint32_t *const param;
};
#define USER_CMD_EXPORT(name, f, c, p)
uint32_t _USER_CMD_##name##_param = (uint32_t)p;
const char _USER_CMD_##name##_name[] SECTION_A_NAME = #c;
__attribute__((used)) const struct user_cmd_object _USER_CMD_##name##_obj USER_SECTION =
{
.func = f,
.breif = _USER_CMD_##name##_name,
.param = &_USER_CMD_##name##_param
}
b.c:
Code:
Select all
#include "b.h"
//at+version
static int func_version(void *param)
{
printf("%srn", "V1.0.0");
return 0;
}
USER_CMD_EXPORT(VERSION, func_version, AT+VERSION, 0);
//at+uid
static int func_uid(void *param)
{
printf("%08xrn", u_devid_get());
return 0;
}
USER_CMD_EXPORT(UID, func_uid, AT+UID, 0);
编译后得到的map文件:
Code:
Select all
0x000000003c029614 . = ALIGN (0x4)
0x000000003c029614 user_section_tab_local_start = ABSOLUTE (.)
*(SORT_BY_NAME(*user_section_tab*))
0x000000003c029614 user_section_tab_local_end = ABSOLUTE (.)
问题是编译之后user_section_tab段里的内容是空的,请问这个问题怎么处理呢?