How to remove unused functions coming from static library

Asked by Vinay Kumar Kotegowder on 2017-10-05

Hello,

I am using static library to build my custom application using arm-gnu tool.

My custom application does call function coming from static library, when doing so I do see all other function from one or more objects files from static library are reflecting in final application ELF which is increasing my ELF size.

Is it possible to use only the required function and dependent functions within my application from static library and get rid off unused functions?

If yes can you tell me how to do that please!

Best Regards,
Vinay

Question information

Language:
English Edit question
Status:
Solved
For:
GNU ARM Embedded Toolchain Edit question
Assignee:
No assignee Edit question
Solved by:
Thomas Preud'homme
Solved:
2017-10-05
Last query:
2017-10-05
Last reply:
2017-10-05

It's possible to get rid of unused section (ie section containing no function needed transitivtely). To do so, pass -Wl,--gc-sections to the GCC *link* command-line.

Best regards.

Hi Thomas,

I have used -fdata-sections and -ffunction-sections during compile stage and -Wl,--gc-sections at link stage which does what I expected.

Thank you for your quick reply.

Best Regards,
Vinay

Thanks Thomas Preud'homme, that solved my question.