Suppose I build a static library "mylib.a" which has many sections. one section is called ".my_test" and I put some structure in it.
Suppose My main() function call some functions in the library.
However, no functions directly access the structure in section ".my_test".
So the link process won't link the section ".my_test". How to link it?
one possible way: disable -Wl,--gc-sections
another possible way: -Lpath_to_my_lib -Wl,--whole-archive -lmylib -Wl,--no-whole-archive
third way: use KEEP(*(.my_test)) in Link script file
In my project, I used them as:
link flag is: -Lpath_to_my_lib -Wl,-whole-archive -lmylib -Wl,no-whole-archive -Wl,--gc-sections
Link script is: use KEEP(*(.my_test)) in section .data -- not create a new section.
Good luck.