Find the answer to your Linux question:
Results 1 to 5 of 5
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    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()
    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?

  2. #2
    Linux Engineer Kloschüssel's Avatar
    Join Date
    Oct 2005
    I think the static switch will do the change.

  3. #3

    God, you're right, but WHY~~~~~~~~~

    Quote Originally Posted by Kloschüssel View Post
    I think the static switch will do the change.
    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?

  4. $spacer_open
  5. #4
    Linux Engineer Kloschüssel's Avatar
    Join Date
    Oct 2005
    It's the special of _static_ methods. He can't optimize it away. Read it up in a C cookbook.

  6. #5

    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....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts