Andes Workshop

It is currently Tue Jun 27, 2017 7:22 am

All times are UTC + 8 hours [ DST ]




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Remove unused section vs SAG KEEP vs -flto
PostPosted: Tue Dec 13, 2016 12:07 pm 
Offline

Joined: Fri May 04, 2012 6:49 am
Posts: 16
As we know, compiler option "-ffunction-sections -fdata-sections" will remove unused funciton sections and data sectons. As for this option, we also need know follow things:
1. The unused sections is removed in linker time, so linker option "--gc-sections" can list the information about what functions or datas have been removed. You can refer:
viewtopic.php?f=23&t=621

2. If we want to keep some unused sections anyway, we can use SAG keyword "KEEP" in sag file. You can refer:
viewtopic.php?f=16&t=843&hilit=unused

3. Generally this option only remove sections in text or data section, but it dosen't remove corresponding information in debug section, so it may caused disorder when we use the output file to do debug.

3.1 As for this kind case, we need "-flto", -flto(Link Time optimization) will rebuild the whole project at the linking time, and the code and debugging information can be removed. But it is a little hard to debug when -flto option is applied.

3.2 But when we use "-flto", it is a compiler option and it can remove sections in compile time, so SAG keyword in item2 can't work because it can only save sections in link time, that's too late. To fix this problem, we need attribute "used" to tell "-flto" not remove. As:
Code:
void __attribute__((section(".my_func"))) __attribute__((used)) foo(void);
or
void __attribute__((section(".my_func"), used)) foo(void);


3.3 With item 3.1 & 3.2, it seems we can use "-ffunction-sections -fdata-sections" to do some code checking work and the cost is low. But there is still some cost that it is silent when "-flto" cut unused sections in compile time. It means we can't see what has been removed by "-flto".

As a conclusion, currently GCC is a powerful tool and can help coder do many many jobs. But for some corner case, it has limitation. At this stage, we need accept its limitation or we write code more accurately so that GCC can do its job easily.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC + 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group