How to collect data from different .a files into one array? How to keep sections in .a files with ld script?

China☆狼群 提交于 2019-12-06 04:41:57

问题


I need to collect some data from different .a files to one array. I do it by collecting data to one section

first .c file

TArElement __attribute__((section(".my.special.section"))) uwiveuve = { ...

second .c file

TArElement __attribute__((section(".my.special.section"))) egwegwxb = { ...

etc.

in ld script

__my_mega_array_begin = ABSOLUTE(.);
KEEP(*(.my.special.section))
__my_mega_array_end = ABSOLUTE(.);

in main .c file

extern TArElement *__my_mega_array_begin
extern TArElement *__my_mega_array_end
const t_size array_size = __my_mega_array_end - __my_mega_array_begin;

So anyone can link his code with my code, and my code will know about data in his code. Ok, it works, but not actually... The problem is that KEEP directive works completely with .o files, but not .a . if no sections is used in particullar .o file inside of .a file, then whole .o file will be discarded from linking even though KEEP directive is used.

Using of --whole-arhive option to ld will help, but I'm not allowed to use this option for some reasons. I should do all with ld script file only...

Another way to solve problem is to use partial linking, by creating relocatable file. So all .o files inside of .a will linked to one .o file. But I'm not allowed to use partial linking either.

So I should do it only by using ld script and using .a file.

来源:https://stackoverflow.com/questions/6568844/how-to-collect-data-from-different-a-files-into-one-array-how-to-keep-sections

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!