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
- #include <stdio.h>
- int add (int x, int y)
- {
- return x + y;
- }
- int AAA;
- int BBB = 1;
- Char sztest[] = "good";
- int main ()
- {
- int CCC = 2;
- return 0;
- }
Then we look at the results:
[Plain]View PlainCopy
- [[email protected] learn_strip]$ ls
- Main.c
- [Email protected] learn_strip]$ gcc main.c
- [Email protected] learn_strip]$ ls-l a.out
- -rwxrwxr-x 1 taoge taoge 4673 Jul 05:30 a.out
- [[Email protected] learn_strip]$ file a.out
- 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
- [Email protected] learn_strip]$ nm a.out
- 08049538 D _dynamic
- 08049604 D _global_offset_table_
- 0804847c R _io_stdin_used
- W _jv_registerclasses
- 08049528 D __ctor_end__
- 08049524 D __ctor_list__
- 08049530 D __dtor_end__
- 0804952C D __dtor_list__
- 08048520 R __frame_end__
- 08049534 D __jcr_end__
- 08049534 D __jcr_list__
- 08049628 A __bss_start
- 08049618 D __data_start
- 08048430 T __do_global_ctors_aux
- 08048310 T __do_global_dtors_aux
- 08048480 R __dso_handle
- W __gmon_start__
- 0804842a T __I686.GET_PC_THUNK.BX
- 08049524 D __init_array_end
- 08049524 D __init_array_start
- 080483C0 T __libc_csu_fini
- 080483d0 T __libc_csu_init
- U [email protected] @GLIBC_2.0
- 08049628 A _edata
- 08049634 A _end
- 0804845C T _fini
- 08048478 R _FP_HW
- 08048274 T _init
- 080482E0 T _start
- 08049630 B AAA
- 08048394 T Add
- 0804961c D BBB
- 08049628 b completed.5963
- 08049618 W Data_start
- 0804962C b dtor_idx.5965
- 08048370 T Frame_dummy
- 080483A2 T Main
- 08049620 D Sztest
- [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
- [[email protected] learn_strip]$ ls
- A.out MAIN.C
- [email protected] learn_strip]$ strip a.out
- [Email protected] learn_strip]$ ls-l a.out
- -rwxrwxr-x 1 taoge taoge 2980 Jul 05:34 a.out
- [[Email protected] learn_strip]$ file a.out
- A.out:elf 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for Gnu/linux 2.6. Stripped,
- [Email protected] learn_strip]$ nm a.out
- Nm:a.out:no symbols
- [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