next up previous contents
Next: keep-symbol Up: strip 工具 Previous: strip-debug   Contents

strip-unneeded

  1. 重新編譯程式。
    [dywang@dyH gcc]$ gcc -g -o stripex1 stripex1.c
    
  2. 先移除除錯的資訊,以 -a 選項觀看所有 elf 檔案資訊並存檔。
    [dywang@dyH gcc]$ strip --strip-debug stripex1
    [dywang@dyH gcc]$ readelf -a stripex1 | tee elfad.txt
    
  3. 移除不需要的資訊,以 -a 選項觀看所有 elf 檔案資訊並存檔。
    [dywang@dyH gcc]$ strip --strip-unneeded stripex1
    [dywang@dyH gcc]$ readelf -a stripex1 | tee elfadun.txt
    [dywang@dyH gcc]$ diff elfad.txt elfadun.txt
    
  4. 比較兩個檔案。
    [dywang@dyH gcc]$ diff elfad.txt elfadun.txt | tee elfaundiff.txt
    
  5. 修整後的執行檔,符號項目都被移除了。
    13c13
    <   Start of section headers:          2592 (bytes into file)
    ---
    >   Start of section headers:          2576 (bytes into file)
    19c19
    <   Number of section headers:         30
    ---
    >   Number of section headers:         28
    80,84c80
    <        00000000000000fe  0000000000000000           0     0     1
    <   [28] .symtab           SYMTAB           0000000000000000  000011a0
    <        0000000000000618  0000000000000018          29    45     8
    <   [29] .strtab           STRTAB           0000000000000000  000017b8
    <        00000000000001fd  0000000000000000           0     0     1
    ---
    >        00000000000000ee  0000000000000000           0     0     1
    165,232d160
    < Symbol table '.symtab' contains 65 entries:
    <    Num:    Value          Size Type    Bind   Vis      Ndx Name
    <      0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND 
    <      1: 000000000040040c     0 FUNC    LOCAL  DEFAULT   13 call_gmon_start
    <      2: 0000000000600700     0 OBJECT  LOCAL  DEFAULT   18 __CTOR_LIST__
    <      3: 0000000000600710     0 OBJECT  LOCAL  DEFAULT   19 __DTOR_LIST__
    <      4: 0000000000600720     0 OBJECT  LOCAL  DEFAULT   20 __JCR_LIST__
    <      5: 0000000000400430     0 FUNC    LOCAL  DEFAULT   13 __do_global_dtors_aux
    <      6: 00000000006008f8     1 OBJECT  LOCAL  DEFAULT   25 completed.6349
    <      7: 0000000000600900     8 OBJECT  LOCAL  DEFAULT   25 dtor_idx.6351
    <      8: 00000000004004a0     0 FUNC    LOCAL  DEFAULT   13 frame_dummy
    <      9: 0000000000600708     0 OBJECT  LOCAL  DEFAULT   18 __CTOR_END__
    <     10: 00000000004006f8     0 OBJECT  LOCAL  DEFAULT   17 __FRAME_END__
    <     11: 0000000000600720     0 OBJECT  LOCAL  DEFAULT   20 __JCR_END__
    <     12: 00000000004005d0     0 FUNC    LOCAL  DEFAULT   13 __do_global_ctors_aux
    <     13: 00000000006008ec     4 OBJECT  LOCAL  DEFAULT   24 i
    <     14: 0000000000600908     4 OBJECT  LOCAL  DEFAULT   25 local.2052
    <     15: 00000000006008c0     0 OBJECT  LOCAL  DEFAULT   23 _GLOBAL_OFFSET_TABLE_
    <     16: 00000000006006fc     0 NOTYPE  LOCAL  DEFAULT   18 __init_array_end
    <     17: 00000000006006fc     0 NOTYPE  LOCAL  DEFAULT   18 __init_array_start
    <     18: 0000000000600728     0 OBJECT  LOCAL  DEFAULT   21 _DYNAMIC
    <     19: 0000000000400200     0 SECTION LOCAL  DEFAULT    1 
    <     20: 000000000040021c     0 SECTION LOCAL  DEFAULT    2 
    <     21: 000000000040023c     0 SECTION LOCAL  DEFAULT    3 
    <     22: 0000000000400260     0 SECTION LOCAL  DEFAULT    4 
    <     23: 0000000000400280     0 SECTION LOCAL  DEFAULT    5 
    <     24: 00000000004002e0     0 SECTION LOCAL  DEFAULT    6 
    <     25: 0000000000400320     0 SECTION LOCAL  DEFAULT    7 
    <     26: 0000000000400328     0 SECTION LOCAL  DEFAULT    8 
    <     27: 0000000000400348     0 SECTION LOCAL  DEFAULT    9 
    <     28: 0000000000400360     0 SECTION LOCAL  DEFAULT   10 
    <     29: 0000000000400390     0 SECTION LOCAL  DEFAULT   11 
    <     30: 00000000004003a8     0 SECTION LOCAL  DEFAULT   12 
    <     31: 00000000004003e0     0 SECTION LOCAL  DEFAULT   13 
    <     32: 0000000000400608     0 SECTION LOCAL  DEFAULT   14 
    <     33: 0000000000400618     0 SECTION LOCAL  DEFAULT   15 
    <     34: 0000000000400634     0 SECTION LOCAL  DEFAULT   16 
    <     35: 0000000000400660     0 SECTION LOCAL  DEFAULT   17 
    <     36: 0000000000600700     0 SECTION LOCAL  DEFAULT   18 
    <     37: 0000000000600710     0 SECTION LOCAL  DEFAULT   19 
    <     38: 0000000000600720     0 SECTION LOCAL  DEFAULT   20 
    <     39: 0000000000600728     0 SECTION LOCAL  DEFAULT   21 
    <     40: 00000000006008b8     0 SECTION LOCAL  DEFAULT   22 
    <     41: 00000000006008c0     0 SECTION LOCAL  DEFAULT   23 
    <     42: 00000000006008e8     0 SECTION LOCAL  DEFAULT   24 
    <     43: 00000000006008f8     0 SECTION LOCAL  DEFAULT   25 
    <     44: 0000000000000000     0 SECTION LOCAL  DEFAULT   26 
    <     45: 00000000006008e8     0 NOTYPE  WEAK   DEFAULT   24 data_start
    <     46: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND printf@@GLIBC_2.2.5
    <     47: 0000000000400530     2 FUNC    GLOBAL DEFAULT   13 __libc_csu_fini
    <     48: 00000000004003e0     0 FUNC    GLOBAL DEFAULT   13 _start
    <     49: 0000000000000000     0 NOTYPE  WEAK   DEFAULT  UND __gmon_start__
    <     50: 0000000000000000     0 NOTYPE  WEAK   DEFAULT  UND _Jv_RegisterClasses
    <     51: 0000000000400608     0 FUNC    GLOBAL DEFAULT   14 _fini
    <     52: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND __libc_start_main@@GLIBC_
    <     53: 00000000006008f0     4 OBJECT  GLOBAL DEFAULT   24 global
    <     54: 0000000000400618     4 OBJECT  GLOBAL DEFAULT   15 _IO_stdin_used
    <     55: 00000000006008e8     0 NOTYPE  GLOBAL DEFAULT   24 __data_start
    <     56: 0000000000400620     0 OBJECT  GLOBAL HIDDEN    15 __dso_handle
    <     57: 0000000000600718     0 OBJECT  GLOBAL HIDDEN    19 __DTOR_END__
    <     58: 0000000000400540   137 FUNC    GLOBAL DEFAULT   13 __libc_csu_init
    <     59: 00000000006008f4     0 NOTYPE  GLOBAL DEFAULT  ABS __bss_start
    <     60: 0000000000600910     0 NOTYPE  GLOBAL DEFAULT  ABS _end
    <     61: 00000000006008f4     0 NOTYPE  GLOBAL DEFAULT  ABS _edata
    <     62: 00000000004004c4    27 FUNC    GLOBAL DEFAULT   13 inc_func
    <     63: 00000000004004df    67 FUNC    GLOBAL DEFAULT   13 main
    <     64: 0000000000400390     0 FUNC    GLOBAL DEFAULT   11 _init
    < 
    
  6. 查看檔案大小,從 8195 bytes 降至 4368 bytes。
    [dywang@dyH gcc]$ ll stripex1*
    -rwxrwxr-x. 1 dywang dywang 4368 Sep  1 08:34 stripex1
    -rw-rw-r--. 1 dywang dywang  323 Aug 31 22:19 stripex1.c
    



2015-01-16