【发布时间】:2014-10-17 21:17:28
【问题描述】:
这个问题的答案:
gcc/ld: Allow Code Placement And Removal of Unused Functions
似乎是一个非常好的。但是,在尝试使用它时,我发现只要遇到斜杠 (/) 字符,部分名称就会被截断。
__FILE__ 包含文件的路径,因此包含 / 字符。链接器在创建节名时删除 / 字符后面的所有内容,例如:
#define SEC_TEXT __attribute__((section(".mytext.bl/ah.c")))
unsigned char SEC_TEXT poll(void)
我最终得到了这个部分名称:
[ 8] .mytext.bl PROGBITS 00000000 000120 00003d 00 0 0 1
如果我使用你的答案,使用__LINE__ 和__FILE__:
#define __S(s) #s
#define _S(s) __S(s)
#define SECTION __FILE__ "." _S(__LINE__)
#define SEC_MYTEXT __attribute__((section(".mytext." SECTION)))
unsigned char SEC_MYTEXT poll(void)
我明白了:
[ 8] .mytext. PROGBITS 00000000 000120 00003d 00 0 0 1
但是你可以从预处理器的输出中看到它应该给我一个包含文件和行的部分名称:
unsigned char __attribute__((section(".mytext." "/path/to/mycode/poll.c" "." "250"))) poll
有什么办法可以解决这个问题?
【问题讨论】: