Andes Workshop

It is currently Sat Aug 19, 2017 3:12 am

All times are UTC + 8 hours [ DST ]




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: 查詢--gc-sections移去哪些sections
PostPosted: Fri Sep 14, 2012 10:51 am 
Offline
User avatar

Joined: Fri Mar 04, 2011 9:36 pm
Posts: 500
(一) 在Console下查詢的方法:
1. "Remove unused sections" 就只是remove unused sections.
user可以自行檢查被移除function及data。

可以利用 linker option的--print-gc-sections來印出被remove的sections, 例如
$ gcc test.c -ffunction-sections -Wl,--gc-sections,--print-gc-sections
/usr/bin/ld: Removing unused section '.rodata' in file '/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../i386-linux-gnu/crt1.o'
/usr/bin/ld: Removing unused section '.data' in file '/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../i386-linux-gnu/crt1.o'
/usr/bin/ld: Removing unused section '.data' in file '/usr/lib/gcc/i686-linux-gnu/4.6.1/crtbegin.o'
/usr/bin/ld: Removing unused section '.text.foo' in file '/tmp/cc19xY66.o' ß foo function被移除

會發生不預期的移除, 通常是像 if/else的condition可以在compiling time推算出來, 所以被gcc當成dead code optimize掉

(二) 如何將上述的指令加在Andesight裡?
附件有一個example,大家可以匯入Andesight後試試。
設定如下:
(1) 在Andes C Compiler/Miscellaneous裡加上 -ffunction-sections -fdata-sections

Attachment:
p1.png
p1.png [ 12.72 KiB | Viewed 4406 times ]


(2) 取消勾選Remove unused sections (因為我把原本的選項拆開來設定
Remove unused sections即為 -ffunction-sections -fdata-sections及--gc-sections)

Attachment:
p2.png
p2.png [ 22.54 KiB | Viewed 4406 times ]


(3) 在Andes C Linker/Muscellaneous裡加上這2個option (按下綠色的十字button可增加)

Attachment:
p3.png
p3.png [ 23.55 KiB | Viewed 4406 times ]


(4)我的原始碼

Code:
#include <stdio.h>
#include <stdlib.h>

int int1=34;
int int2=56;

void foo(void);
void foo2(void);

int main(void) {
   puts("!!!Hello World!!!"); /* prints !!!Hello World!!! */
   return EXIT_SUCCESS;
}

void foo()
{
   puts("foo"); /* prints !!!Hello World!!! */
}

void foo2()
{
   puts("foo2"); /* prints !!!Hello World!!! */
}



(5) Build code得到結果如下。原本的int1 int2 foo1 foo2都被刪掉了

Attachment:
p4.png
p4.png [ 10.54 KiB | Viewed 4406 times ]


(6)在project出現紅色x不用理會它。只是因為有輸出message。
它還是能正常產生結果。有.adx檔輸出。

Attachment:
p5.png
p5.png [ 4.94 KiB | Viewed 4406 times ]


完整example code下載
Attachment:
hello2.7z [19.77 KiB]
Downloaded 354 times


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 2 guests


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