【问题标题】:Why file command report dynamic linked with gcc -static为什么文件命令报告动态与 gcc -static 链接
【发布时间】:2017-10-23 04:55:25
【问题描述】:
gcc -static -g -O2 -static -o init init-init.o 
file init
# init: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, with debug_info, not stripped
ldd init
#    ldd (0x7fd49e2ed000)

objdump -p 初始化

init:     file format elf64-x86-64

Program Header:
    LOAD off    0x0000000000000000 vaddr 0x0000000000000000 paddr 0x0000000000000000 align 2**21
        filesz 0x00000000000076e4 memsz 0x00000000000076e4 flags r-x
    LOAD off    0x0000000000007e30 vaddr 0x0000000000207e30 paddr 0x0000000000207e30 align 2**21
        filesz 0x00000000000002d8 memsz 0x0000000000001488 flags rw-
DYNAMIC off    0x0000000000007e60 vaddr 0x0000000000207e60 paddr 0x0000000000207e60 align 2**3
        filesz 0x0000000000000150 memsz 0x0000000000000150 flags rw-
STACK off    0x0000000000000000 vaddr 0x0000000000000000 paddr 0x0000000000000000 align 2**4
        filesz 0x0000000000000000 memsz 0x0000000000000000 flags rw-
RELRO off    0x0000000000007e30 vaddr 0x0000000000207e30 paddr 0x0000000000207e30 align 2**0
        filesz 0x00000000000001d0 memsz 0x00000000000001d0 flags r--

Dynamic Section:
SYMBOLIC             0x0000000000000000
INIT                 0x00000000000002c0
FINI                 0x0000000000006473
GNU_HASH             0x0000000000000158
STRTAB               0x00000000000001b0
SYMTAB               0x0000000000000180
STRSZ                0x0000000000000007
SYMENT               0x0000000000000018
DEBUG                0x0000000000000000
PLTGOT               0x0000000000207fb0
RELA                 0x00000000000001b8
RELASZ               0x0000000000000108
RELAENT              0x0000000000000018
BIND_NOW             0x0000000000000000
FLAGS_1              0x0000000008000001
RELACOUNT            0x000000000000000b

readelf init -h

ELF Header:
Magic:   7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00 
Class:                             ELF64
Data:                              2's complement, little endian
Version:                           1 (current)
OS/ABI:                            UNIX - System V
ABI Version:                       0
Type:                              DYN (Shared object file)
Machine:                           Advanced Micro Devices X86-64
Version:                           0x1
Entry point address:               0x1158
Start of program headers:          64 (bytes into file)
Start of section headers:          308248 (bytes into file)
Flags:                             0x0

为什么是Type: DYN (Shared object file)

试图在alpine下编译supermin,但是src/Makefile.am#L159 require init 是由file 命令静态链接的。

【问题讨论】:

    标签: c++ gcc makefile alpine


    【解决方案1】:

    ET_DYN 用于与位置无关的可执行文件 (PIE),无论它们是否静态链接。缺少程序解释器和动态部分中的DT_NEEDED 条目表明该程序确实是静态链接的。你可以使用readelf -l(没有.interp)和readelf -d(没有NEEDED)来检查。

    strace 下运行程序还将验证在程序启动时没有加载任何共享对象。

    【讨论】:

    • 所以file 命令只报告ET_DYN,不检查DT_NEEDED?
    • 显然。静态链接的 PIE 二进制文件是一项相当新的创新。
    • 所以,这是文件的功能/错误?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-11-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多