关于链接脚本(ld)的使用中段(section)被优化的问题

wakojosin
Posts: 2
Joined: Tue Mar 17, 2020 1:38 am

关于链接脚本(ld)的使用中段(section)被优化的问题

Postby wakojosin » Wed Nov 09, 2022 5:43 am

使用方式如下:
链接脚本:

Code: Select all

...
    . = ALIGN(4);
    user_section_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("%s\r\n", "V1.0.0");
    return 0;
}
USER_CMD_EXPORT(VERSION, func_version, AT+VERSION, 0);
//at+uid
static int func_uid(void *param)
{
    printf("%08x\r\n", 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段里的内容是空的,请问这个问题怎么处理呢?

ESP_morris
Posts: 290
Joined: Wed Sep 05, 2018 6:23 am

Re: 关于链接脚本(ld)的使用中段(section)被优化的问题

Postby ESP_morris » Mon Nov 14, 2022 9:29 am

有官方example可以参考,文档非常详细
https://github.com/espressif/esp-idf/tr ... ke/plugins

Who is online

Users browsing this forum: Majestic-12 [Bot], virgil and 77 guests