"otool" and "file" cannot display the architecture of the ".a" file

I created some static libraries for ARM7 using cMake. Usually, when you use the following command for a .a file, it shows architectures:

fe

mac:libs User$ file ./libcurl.a ./libcurl.a: Mach-O universal binary with 3 architectures ./libcurl.a (for architecture armv6): current ar archive random library ./libcurl.a (for architecture armv7): current ar archive random library ./libcurl.a (for architecture i386): current ar archive random library 

or fe

 mac:libs User$ otool -vf ./libboost_regex.a Fat headers fat_magic FAT_MAGIC nfat_arch 3 architecture armv6 cputype CPU_TYPE_ARM cpusubtype CPU_SUBTYPE_ARM_V6 capabilities 0x0 offset 68 size 9550024 align 2^2 (4) architecture armv7 cputype CPU_TYPE_ARM cpusubtype CPU_SUBTYPE_ARM_V7 capabilities 0x0 offset 9550092 size 9390544 align 2^2 (4) architecture i386 cputype CPU_TYPE_I386 cpusubtype CPU_SUBTYPE_I386_ALL capabilities 0x0 offset 18940636 size 9595040 align 2^2 (4) 

but now, when I build my library, "otool" and "file" cannot display its architecture.

 mac:libs User$ otool -vf ./mylib_meta.a Archive : ./mylib_meta.a 

What does it mean? What mistakes can I make when creating my library?

Update: Igor, thanks!

I extracted the object file using the commands:

ar -t mylib.a

ar -xv mylib.a myobj.o

-t shows a list of binary files

-xv retrieves a specific binary

+5
source share
2 answers

Apple uses two forms of AR archives. The first one is very similar to the traditional Unix archive ("a.out archive") - basically just a bunch of .o files attached along with the character index in front:

 "<!arch>\n" header 0 SYMDEF entry header 1 object 1 header 2 object 2 ... 

To determine the architecture for which this archive is intended, you need to extract at least one object file and use file or otool on it. The archive header itself does not contain this information. (In fact, the object files are not necessarily all for the same arch, and in theory you can have any files, not just objects, but this is unlikely.) You can use the ar utility to extract individual files from the archive.

Another view is Apple's own invention. They took the Bold / Universal Binary concept used for Mach-O multicast files and used it for archives. So, the bold archive looks like this:

  Fat Mach-O header Architecture 1 header --+ Architecture 2 header --|--+ Architecture 3 header --|--|--+ [padding] | | | Archive 1 <-------------+ | | Archive 2 <----------------+ | Archive 3 <-------------------+ 

In this case, file and otool can look at the bold header and list of supported architectures.

To create or edit fat files (both archives and executables), you can use the lipo tool.

+4
source

One alternative is to use objdump from the GNU binutils package (available, for example, via homebrew). On macOS, it is renamed to gobjdump . Calling it in the archive will show the archive header information, possibly saving you the need to extract object files (just as you originally wanted)

 > gobjdump -a ./libboost_regex.a In archive ./libboost_regex.a: c_regex_traits.o: file format mach-o-x86-64 rw-r--r-- 502/20 140976 Nov 8 08:03 2018 c_regex_traits.o cpp_regex_traits.o: file format mach-o-x86-64 rw-r--r-- 502/20 106424 Nov 8 08:03 2018 cpp_regex_traits.o ... 

Late answer, but adding here for future reference.

0
source

Source: https://habr.com/ru/post/1489678/


All Articles