Executable

什麼是 Unix 中剝離和未剝離的執行檔?

  • July 21, 2017

man 文件中,

EXAMPLES
  $ file file.c file /dev/{wd0a,hda}
  file.c:   C program text
  file:     ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV),
            dynamically linked (uses shared libs), stripped
  /dev/wd0a: block special (0/0)
  /dev/hda: block special (3/0)
  $ file -s /dev/wd0{b,d}
  /dev/wd0b: data
  /dev/wd0d: x86 boot sector
  $ file -s /dev/hda{,1,2,3,4,5,6,7,8,9,10}
  /dev/hda:   x86 boot sector
  /dev/hda1:  Linux/i386 ext2 filesystem
  /dev/hda2:  x86 boot sector
  /dev/hda3:  x86 boot sector, extended partition table
  /dev/hda4:  Linux/i386 ext2 filesystem
  /dev/hda5:  Linux/i386 swap file
  /dev/hda6:  Linux/i386 swap file
  /dev/hda7:  Linux/i386 swap file
  /dev/hda8:  Linux/i386 swap file
  /dev/hda9:  empty
  /dev/hda10: empty

  $ file -i file.c file /dev/{wd0a,hda}
  file.c:      text/x-c
  file:        application/x-executable, dynamically linked (uses shared libs),
  not stripped
  /dev/hda:    application/x-not-regular-file
  /dev/wd0a:   application/x-not-regular-file

可執行剝離是什麼意思?

為什麼有些執行檔被剝離,而另一些則沒有?

如果你用 gcc 的 -g 標誌編譯一個執行檔,它包含調試資訊。這意味著對於每條指令,都有原始碼的哪一行生成它的資訊,原始碼中變數的名稱被保留,並且可以在執行時與匹配的記憶體相關聯等。Strip 可以刪除此調試資訊和包含的其他數據為了減小執行檔的大小,在執行不需要的執行檔中。

引用自:https://unix.stackexchange.com/questions/2969