2010-09-18 44 views
20

我有一个.a文件,我想从中获取架构信息。运行file myFile.a结果在file.a: current ar archive。如何获得更多关于该文件包含哪些体系结构的信息?如何获得'.a'文件的体系结构?

回答

30

您也可以跳过ar命令,并使用readelf对其进行检查,通过像:

readelf -h <archive>.a | grep 'Class\|File\|Machine'

[00:32:15] /usr/lib $ readelf -h libxslt.a | grep 'Class\|File\|Machine' 
File: libxslt.a(attrvt.o) 
    Class:        ELF32 
    Machine:       Intel 80386 
File: libxslt.a(xslt.o) 
    Class:        ELF32 
    Machine:       Intel 80386 
... #Trimmed this, it goes on a bit 
File: libxslt.a(transform.o) 
    Class:        ELF32 
    Machine:       Intel 80386 
File: libxslt.a(security.o) 
    Class:        ELF32 
    Machine:       Intel 80386 
[00:32:24] /usr/lib $ 

如果相关,可以从readelf -h获取其他信息。我只是修剪以上grep,很明显:

File: libxslt.a(security.o) 
ELF Header: 
    Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 
    Class:        ELF32 
    Data:        2's complement, little endian 
    Version:       1 (current) 
    OS/ABI:       UNIX - System V 
    ABI Version:      0 
    Type:        REL (Relocatable file) 
    Machine:       Intel 80386 
    Version:       0x1 
    Entry point address:    0x0 
    Start of program headers:   0 (bytes into file) 
    Start of section headers:   2548 (bytes into file) 
    Flags:        0x0 
    Size of this header:    52 (bytes) 
    Size of program headers:   0 (bytes) 
    Number of program headers:   0 
    Size of section headers:   40 (bytes) 
    Number of section headers:   16 
    Section header string table index: 13 

即输出为libxslt.a目标文件一个,但它给每个文件相同的信息。

+1

建议在该列表中添加'Machine'。这将包括目标文件所针对的特定CPU的信息,而不仅仅是32位或64位等等。 – cHao 2010-09-18 04:46:46

+0

@cHao:是的,我也想到了。我正在做另一个编辑(并且我添加了'readelf -h'的整个输出)。 – eldarerathis 2010-09-18 04:50:20

+0

谢谢!这正是我所期待的。 – Mike 2010-09-18 04:52:22

2

http://linux.die.net/man/1/ar

从归档中提取的目标文件,并用文件(1),纳米(1)等

+0

有没有任何方法可以在不提取其内容的情况下获取架构信息(至少不会留下任何残留物)? – Mike 2010-09-18 04:32:48

+0

没有<填充物让你快乐> – jer 2010-09-18 04:33:56

+0

@jer,实际上,你可以用'readelf'或'objdump'来完成。 – 2010-09-18 04:47:04

5

objdump是另一种选择:

objdump -a file.a|grep 'file format' 
13

使用

脂-info libExample.a

这将是谁的架构是建立。其他功能,如otool或文件不会给出确切的答案,有时它会冗长以获取正确的信息。

+2

lipo似乎是特定于OS X的。 – MetalGodwin 2015-11-16 10:11:47

0

我会建议使用objdump而不是lipo。 objdump提供比lipo更详细的信息。