Introduction to strip commands in Linux------undress files

Source: Internet
Author: User

1, remove-g, equal to the program to do the--strip-debug
2, strip program, equal to the program did--strip-debug and--strip-symbol

As a Linux developer, if you have not heard of the strip command, it is very inappropriate. Strip this word, everyone should have learned, you remember to take off clothes on the line, other don't think much. In Linux, strip also has the meaning of undressing, specifically to remove some of the symbolic information and debugging information from certain files.

Let's look at the Main.c file:

[CPP]View PlainCopy 
  1. #include <stdio.h>
  2. int add (int x, int y)
  3. {
  4. return x + y;
  5. }
  6. int AAA;
  7. int BBB = 1;
  8. Char sztest[] = "good";
  9. int main ()
  10. {
  11. int CCC = 2;
  12. return 0;
  13. }

Then we look at the results:

[Plain]View PlainCopy 
  1. [[email protected] learn_strip]$ ls
  2. Main.c
  3. [Email protected] learn_strip]$ gcc main.c
  4. [Email protected] learn_strip]$ ls-l a.out
  5. -rwxrwxr-x 1 taoge taoge 4673 Jul 05:30 a.out
  6. [[Email protected] learn_strip]$ file a.out
  7. A.out:elf 32-bit LSB executable, Intel 80386, version 1 (gnu/linux), dynamically linked (uses shared libs), for Gnu/linux 2.6.18, not stripped
  8. [Email protected] learn_strip]$ nm a.out
  9. 08049538 D _dynamic
  10. 08049604 D _global_offset_table_
  11. 0804847c R _io_stdin_used
  12. W _jv_registerclasses
  13. 08049528 D __ctor_end__
  14. 08049524 D __ctor_list__
  15. 08049530 D __dtor_end__
  16. 0804952C D __dtor_list__
  17. 08048520 R __frame_end__
  18. 08049534 D __jcr_end__
  19. 08049534 D __jcr_list__
  20. 08049628 A __bss_start
  21. 08049618 D __data_start
  22. 08048430 T __do_global_ctors_aux
  23. 08048310 T __do_global_dtors_aux
  24. 08048480 R __dso_handle
  25. W __gmon_start__
  26. 0804842a T __I686.GET_PC_THUNK.BX
  27. 08049524 D __init_array_end
  28. 08049524 D __init_array_start
  29. 080483C0 T __libc_csu_fini
  30. 080483d0 T __libc_csu_init
  31. U [email protected] @GLIBC_2.0
  32. 08049628 A _edata
  33. 08049634 A _end
  34. 0804845C T _fini
  35. 08048478 R _FP_HW
  36. 08048274 T _init
  37. 080482E0 T _start
  38. 08049630 B AAA
  39. 08048394 T Add
  40. 0804961c D BBB
  41. 08049628 b completed.5963
  42. 08049618 W Data_start
  43. 0804962C b dtor_idx.5965
  44. 08048370 T Frame_dummy
  45. 080483A2 T Main
  46. 08049620 D Sztest
  47. [Email protected] learn_strip]$

The Ls-l command indicates that the size of the a.out is 4,673 bytes;

The file command shows that A.out is an executable and not stripped, that is, no undressing.

With the NM command, you can read the symbolic information in the a.out.

Now, I strip A.out's clothes off and get the result:

[Plain]View PlainCopy 
  1. [[email protected] learn_strip]$ ls
  2. A.out MAIN.C
  3. [email protected] learn_strip]$ strip a.out
  4. [Email protected] learn_strip]$ ls-l a.out
  5. -rwxrwxr-x 1 taoge taoge 2980 Jul 05:34 a.out
  6. [[Email protected] learn_strip]$ file a.out
  7. A.out:elf 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for Gnu/linux 2.6. Stripped,
  8. [Email protected] learn_strip]$ nm a.out
  9. Nm:a.out:no symbols
  10. [Email protected] learn_strip]$

The Ls-l command indicates that the size of the a.out is 2,980 bytes, greatly reduced;

Through the file command, A.out is an executable file, and it is stripped, that is, the clothes are taken off;

Through the NM command, it was found that the symbols in the a.out were gone.

This shows that strip used to take off the files of the clothes, the file will be smaller, where the symbolic information will be lost. What's the use of this strip? That's very useful! The original a.out is larger and can be executed. After the strip, the file becomes smaller and can still be executed, which saves a lot of space.

In fact, strip can be used not only for executables, but also for target files and dynamic libraries.

In the actual development, it is often necessary to strip the dynamic library. So to reduce floor space. And when debugging (for example, with Addr2line), you need symbols. Therefore, the usual practice is: Strip before the library for debugging, strip after the library for the actual release, they have a correspondence between the two. Once the published strip library is out of the question, you can find the corresponding non-strip library to locate.

Finally, a dynamic library strip is about 18M ago, after strip is about 3M, visible, undress or have obvious advantages.

Add: Later found that in the debugging process, often involved in the library, the library is too large, very expensive transmission time, so still use strip to do it.

Introduction to strip commands in Linux------undress files

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.