Ask for helping about LD linker

2008-06-01 Thread jian
Dear,
Excuse me,I don't know how to  remove unused functions and variable when 
linking ELF.

please let me know ASAP.

eg.

int main()
{

int i;

i= 5;
return i;
}


char tmpBuffer[5];

char *getTmpBuff()
{
return tmpBuffer;
}

char *getTmpBuff1()
{
return tmpBuffer;
}

char *getTmpBuff2()
{
return tmpBuffer;
}
how to discard the functions(getTmpBuff,getTmpBuff1,getTmpBuff2) when linking.

Best regards.


2008-06-02 



jian 
___
bug-binutils mailing list
bug-binutils@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-binutils


Re: Re: Ask for helping about LD linker

2008-06-02 Thread jian
Dear Nick,
I see, thank you so much.

Best regards


2008-06-02 



jian 



发件人: Nick Clifton 
发送时间: 2008-06-02  16:32:40 
收件人: jian 
抄送: bug-binutils 
主题: Re: Ask for helping about LD linker 
 
Hi Jian,

> But how to remove the unused functions in system library(maybe compile 
> the system library without --funciton-sections) when linking program.

Short Answer: It cannot be done.

Long Answer:

If you are linking against a *shared* library then you will not be able 
to remove any functions in the shared library.  (Nor would you want to - 
other programs may need those functions).

If you are linking against a *static* system library (which has not been 
compiled with --ffunction-sections), then unused functions should not 
normally be copied into the executable.  The exception is when an unused 
function is in the same object file inside the library as a used 
function (or used global symbol).  Ie the linker only discards code at 
the object file level.  If some part of an object file inside a static 
library is needed by the executable then the entire contents of that 
object file will be copies into the executable.

Cheers
   Nick
___
bug-binutils mailing list
bug-binutils@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-binutils


Re: Re: Ask for helping about LD linker

2008-06-02 Thread jian
Dear Nick,
Thanks for your advice,It works well according to your advice.
But how to remove the unused functions in system library(maybe compile the 
system library without --funciton-sections) when linking program.

Best regards.

2008-06-02 



jian 



发件人: Nick Clifton 
发送时间: 2008-06-02  15:08:08 
收件人: jian 
抄送: bug-binutils 
主题: Re: Ask for helping about LD linker 
 
Hi Jian,

> Excuse me,I don't know how to  remove unused functions and variable when 
> linking ELF.

Compile your program with --function-sections.  Link your program with 
-Wl,--gc-sections.

Note: This feature is not implemented for all targets.  If it does not 
work for you then it may be that the target you are working with is one 
of the unsupported targets.

Cheers
   Nick
___
bug-binutils mailing list
bug-binutils@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-binutils