In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains "what are the skills of program volume optimization". The content of the explanation is simple and clear, and it is easy to learn and understand. let's follow the editor's train of thought. Let's study and learn "what are the skills of program volume optimization"?
Strip usage
In Linux, you can use man strip to view the usage of strip. The most important thing is to remove the-s parameter of all symbols to clear all symbol information:
Strip-s xxx
Use nm to view the symbolic information of the following executable program before using strip:
~ / test$ nm a.out 0000000000200da0 d _ DYNAMIC 0000000000200fa0 d _ GLOBAL_OFFSET_TABLE_ 0000000000089b t _ GLOBAL__sub_I__Z4funcPc 0000000000000930 R _ IO_stdin_used w _ ITM_deregisterTMCloneTable w _ ITM_registerTMCloneTable 00000000000852 t _ Z41__static_initialization_and_destruction_0ii 00000000000007fa T _ Z4funcPc 0000000000081c T _ Z4funci U _ ZNSt8ios_base4InitC1Ev@@GLIBCXX_3.4 U _ ZNSt8ios_base4InitD1Ev@@GLIBCXX_3.4 0000000000201020 B _ ZSt4cout@@GLIBCXX_3.4 0000000000000934 r _ ZStL19piecewise_construct 000000201131 b _ ZStL8__ Ioinit U_ ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@@GLIBCXX_3.4 0000000000000b24 r_ _ FRAME_END__ 0000000000000940 r_ _ GNU_EH_FRAME_HDR 0000000000201010 D__ TMC_END__ 0000000000201010 B _ _ bss_start U_ _ cxa_atexit@@GLIBC_2.2.5 w _ _ cxa_finalize@@GLIBC_2.2.5 0000000000201000 D__ data_start 00000000000007b0 t _ _ do_global_dtors_aux 0000000000200d98 t _ _ do_global_dtors_aux_fini_array_entry 0000000000201008 D _ _ dso_handle 0000000000200d88 t__ frame_dummy_init_array_entry w _ _ gmon_start__ 0000000000200d98 t__ init_array_end 0000000000200d88 t__ init_array_start 0000000000000920 T _ _ libc_csu_fini 00000000000008b0 T _ _ libc_csu_init U _ _ libc_start_main@@GLIBC_2.2.5 0000000000201010 D _ edata 0000000000201138 B _ end 0000000000000924 T _ fini 0000000000000688 T _ init 00000000000006f0 T _ start 0000000000201130 b completed.7698 0000000000201000 W data_start 0000000000000720 t deregister_tm_clones 00000000000007f0 t Frame_dummy 000000000000083d T main 0000000000000760 t register_tm_clones
The current file size of this executable program is 8840 bytes:
-rwxrwxrwx 1 an a 8840 Nov 29 14:54 a.out
Use strip to clear symbol information:
~ / test$ strip-s a.out
Check the symbol information of the executable file after strip:
~ / test$ nm a.out nm: a.out: no symbols
It is found that there are no symbols, but it can still be executed.
The executable file size after strip is 6120 bytes:
-rwxrwxrwx 1 an a 6120 Nov 29 14:54 a.out
You can read my article: "Linux has a command you must know."
-fvisibility=hidden can be used as follows:
$layer.cxx +-fvisibility=hidden-c layer.cxx-o layer.o
Skillful use of .bss paragraph:
Look at the following code:
# include int a [1000]; int b [1000] = {1}; int main () {printf ("Program Meow\ n"); return 0;}
Let's take a look at the file size and each segment size:
$gcc testlink.c-o test $ls-l test-rwxrwxrwx 1 wzq wzq 12368 May 30 08:48 test $size test text data bss dec hex filename 1512 4616 4032 10160 27b0 test
Take a look at this initialization code:
# include int a [1000] = {1}; int b [1000] = {1}; int main () {printf ("Program Meow\ n"); return 0;}
Then check the file size and each segment size:
$gcc testlink.c-o test $ls-l test-rwxrwxrwx 1 wzq wzq 16368 May 30 08:49 test $size test text data bss dec hex filename 1512 8616 8 10136 2798 test
You can see that after only one initialization, the file size has changed from 12368 to 16368, which is exactly the size of the initialized a [1000]. The 4000 bytes have been moved from .bss segment to .bss segment, and the program size has increased. It can be seen here that .bss segment does not occupy disk space.
Skillful use of-fdata-sections and-ffunction-sections:
Today's programs and libraries are usually very large, an object file may contain hundreds of functions or variables, when you need to use any function or variable of an object file, you need to link its entire target file in. in other words, those functions that are not used will also be linked in, which will cause the link output file to become very large, resulting in a waste of space.
There is a compilation option called function-level linking, which allows a function or variable to be stored in a separate segment. When the linker needs to use a function, it will be merged into the output file, and the unused functions will be discarded, reducing the waste of space, but this will slow down the compilation and linking process. The compilation option of the GCC compiler is:
-ffunction-sections-fdata-sections Thank you for your reading, the above is the content of "what are the skills of program volume optimization". After the study of this article, I believe you have a deeper understanding of the skills of program volume optimization, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.