如何获得'.a'文件的架构?

时间:2021-08-23 13:19:57

I have a .a file from which I want to get architecture information. Running file myFile.a results in file.a: current ar archive. How can I get more information on what architecture the file contains?

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

5 个解决方案

#1


32  

You can also skip the ar command and use readelf, via something like:

您也可以跳过ar命令并使用readelf,例如:

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

readelf -h .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 $

In case it's relevant, here's the other information that you can get from readelf -h. I just trimmed the above with grep, obviously:

如果它是相关的,这里是你可以从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

That output is for one of the object files in libxslt.a, but it gives the same information for each file.

该输出用于libxslt.a中的一个目标文件,但它为每个文件提供相同的信息。

#2


14  

Use

使用

lipo -info libExample.a

lipo -info libExample.a

It will Who the architecture it build for. Other functions like otool or file doesn't give the exact answer and sometimes it to verbose to get the correct information.

它将为谁构建的架构。其他功能,如otool或文件不能给出确切的答案,有时它会详细说明以获取正确的信息。

#3


6  

objdump is another option:

objdump是另一种选择:

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

#4


1  

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

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

extract the object files from the archive and inspect them with file(1), nm(1), etc.

从存档中提取目标文件,并使用file(1),nm(1)等检查它们。

#5


0  

I would suggest using objdump instead of lipo. objdump provides detailed information than lipo.

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

#1


32  

You can also skip the ar command and use readelf, via something like:

您也可以跳过ar命令并使用readelf,例如:

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

readelf -h .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 $

In case it's relevant, here's the other information that you can get from readelf -h. I just trimmed the above with grep, obviously:

如果它是相关的,这里是你可以从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

That output is for one of the object files in libxslt.a, but it gives the same information for each file.

该输出用于libxslt.a中的一个目标文件,但它为每个文件提供相同的信息。

#2


14  

Use

使用

lipo -info libExample.a

lipo -info libExample.a

It will Who the architecture it build for. Other functions like otool or file doesn't give the exact answer and sometimes it to verbose to get the correct information.

它将为谁构建的架构。其他功能,如otool或文件不能给出确切的答案,有时它会详细说明以获取正确的信息。

#3


6  

objdump is another option:

objdump是另一种选择:

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

#4


1  

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

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

extract the object files from the archive and inspect them with file(1), nm(1), etc.

从存档中提取目标文件,并使用file(1),nm(1)等检查它们。

#5


0  

I would suggest using objdump instead of lipo. objdump provides detailed information than lipo.

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