3

I have a lib (*.a) file, created with armcc in the elf format. There is no possibility to recompile it with llvm or gcc. (It's assembler written for armcc).

Linking it with the gnu ld works fine on Linux, but I have problems doing it on Mac, with llvm.

Because of the different internal format for obj files, it will say "Ignoring file ... which is not the architecture being linked"

Is there a workaround for this? A way to convert elf to Mach-O format? To tell llvm about elf?

There is such a tool for x86/86-64, written by Agner Fog, but I am looking for an ARM tool.

Sam
  • 19,708
  • 4
  • 59
  • 82
  • If the library was compiled for linux, most likely you can't use it in Darwin/iOS. If it has only asm without system calls/library calls, conversion may be is possible. – osgx Feb 09 '12 at 13:57
  • Technically, it's possible. It has no OS-specific code, but I did not find any tool/script/way to convert between formats – Sam Feb 09 '12 at 14:47
  • I think it can be easer to disassemble the .a file (unpacked with ar) and then assemble it back with some Mach-O assembler (from binutils). – osgx Feb 09 '12 at 16:39
  • ar only extracts obj files. But obj format is still incompatible - The Mac ld will not be able to repack them in Mach-O – Sam Feb 09 '12 at 16:43
  • obj files needed to be disassembled. I don't know disassemblers for arm, may be try `objdump -d` and then reformat code into simple .s file? – osgx Feb 09 '12 at 16:45

1 Answers1

3

There is an objcopy from binutils, which should convert binary from one format to another. I think, you should have binutils compiled with both Linux and iOS BFDs. Unfortunately, binutils's support of Mach-O was incomplete (there are some negative reports about ARM+objcopy+Mach-O).

See also:

Other way of converting is to do a reassembly (disassemble each .o file from .a archive and reassemble it with Mach-O-compatible assembler).

Community
  • 1
  • 1
osgx
  • 90,338
  • 53
  • 357
  • 513
  • Objcopy cannot support Mach-o, especially for ARM. But I was able to convert it by dissasembling the .o files and reassembling them with a native assembler. However, it involved some hand-editing. – Sam Feb 17 '12 at 06:41
  • vasile, there is two utilities with similar names: objconv (from agner) and objcopy (from binutils). The support of Mach-O in binutils was incomplete in [2009](http://stackoverflow.com/questions/1608009/how-to-install-gnu-ld-on-mac-os-x-10-6/1618671#1618671) but things can change. – osgx Feb 17 '12 at 11:41
  • Agner is a big fan of x86, he would never go to ARM :) and GNU discontinued support for Mach-O some time ago. But the time invested in hand-editing assembler was worth the time. My app runs now 5 times faster :) – Sam Feb 17 '12 at 12:31
  • Don't know about fan; but he said "Updating the x86 manuals takes my time" and he would not describe ARM in his manuals. – osgx Feb 17 '12 at 13:31