简体   繁体   中英

How to discard unused function after optimization in GCC

I got problems with GCC optimization,

when I use gcc test.c -Os or gcc test.c -O2 , the main() function will put at start address.

but some unused function like <_start> <exit> <memset> , why are they still there?

I have try to use -ffunction-sections -fdata-sections or -gc-sections , it doesn't work.

my simple code:

#include <stdio.h>
int main(){
char buff[20];
sprintf(buff, "%s%d", "hello", 6);
return 0; }

_start is generally the real entrypoint of your executable (the one that initializes the C runtime before calling main ); exit is implicitly invoked when main terminates. memset is implicitly invoked by the compiler in a variety of situations (for example when zero-initializing buffers on the stack), or may be used by the printf implementation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM