Results 1 to 5 of 5
This is my file, named xxx.c. And there are two functions in it.
void axx()
{
bxx();
}
static void bxx() //It's called by axx only , in this file.
...
- 11-18-2010 #1Just Joined!
- Join Date
- Nov 2010
- Posts
- 3
Can --gc-sections remove all the function not used?
This is my file, named xxx.c. And there are two functions in it.
void axx()
{
bxx();
}
static void bxx() //It's called by axx only , in this file.
{
...
}
When I try to compile the whole project, I used -ffunction-sections,-fdata-sections to generate the .o files, use Wl,--gc-sections -Wl,--print-gc-sections
to link to the exacutable file.
gcc 4.3.2
ld 2.18
Debian 5
After the first time I compiled it, I got a list of Removed functions. Iwas so happy.
But one second later, I rememberd that I forget to close the Compile Switch:
Debug. Then I had to recompile it and got another list.
Compare these two lists, I found that , bxx isn't on the second list.
First I guess that bxx is a debug function but never used in debug mode, and it won't be compiled in release mode .
I check the source and find that there was no compile switch for bxx........
But it's caller function axx, is removed, both the debug switch is on and off.
I try to compiled the project for several times , but the result is the same.
I can't realized it , why?
Is that the --gc-sections won't remove all the functions not used?
- 11-18-2010 #2
I think the static switch will do the change.
- 11-18-2010 #3Just Joined!
- Join Date
- Nov 2010
- Posts
- 3
God, you're right, but WHY~~~~~~~~~
When I make the function not static, it was removed correctly by linker.
God, you're right, but WHY~~~~~~~~~???????
Obviously, it's a bug ~!!!!! Because not all the situation it won't be removed.
Please, my lord, tell me WHY?
Could this problem be fixed by any methods?
- 11-18-2010 #4
It's the special of _static_ methods. He can't optimize it away. Read it up in a C cookbook.
- 11-19-2010 #5Just Joined!
- Join Date
- Nov 2010
- Posts
- 3
A little bit confused
Sorry, actually, I've got a lot of static functions in Removed list.
And I have said that this function could be removed if a no related compiled switch
ebug is on.
But this is the only difference from these two compile process, it must change some situation that I don't know.
You're right ,but I can't change all the static functions to nonstatic.
So the question now is ,
① I've a lot of C cookbook, but I don't know where to find an article that mentioned if a function couldn't be automatically removed by GNU linker,then you can change the function to nonstatic,and the linker would be worked correctly.
(Could you give me a hyperlink?)
②And still I can't find an article that mentioned which situation would prevent the GNU linker to removed the unused static functions.
I know you have saved me once, I know I ask a little bit more.
But please save me to the end....
~~~Alleluia~~~


Reply With Quote
