Object files format

On different OS, the object file's (eg: generated a .c file  into a .o file by gcc) formats are different, just like CS:APP, chapter 7.3 said:

Object file formats vary from system to system. The first Unix systems from Bell Labs used the a.out format. (To this day, executables are still referred to as a.out files.) Early versions of System V Unix used the Common Object File format (COFF). Windows NT uses a variant of COFF called the Portable Executable (PE) format. Modern Unix systems—such as Linux, later versions of System V Unix, BSD Unix variants, and Sun Solaris—use the Unix Executable and Linkable Format (ELF). Although our discussion will focus on ELF, the basic concepts are similar, regardless of the particular format.

When I generated my .c file into object file on my mac and then use greadelf(readelf's mac version from binutils), i got the following error msg:

Error: Not an ELF file - it has the wrong magic bytes at the start

So I use a command to ensure the format of a object file on mac:

$ file p

p: Mach-O 64-bit executable x86_64

As you can see, mac os use the Mach-O object file format, however Linux uses the ELF object file format. They perform the same general purpose but in completely different ways. 

So we can's use readelf command with object files on mac os.

otool is OSX's objdump, we can use otool -l to read .o file's information

$ otool -l prog

reference: mach-binaries

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • PLEASE READ THE FOLLOWING APPLE DEVELOPER PROGRAM LICENSE...
    念念不忘的阅读 13,551评论 5 6
  • 这是你年轻时看见的样子,一切看上去都很近,那就是未来。而现在是你年迈时看见的样子,一切看上去都很远,那就是过去。
    哩哩啦啦呼呼呼阅读 287评论 0 0
  • 今天听了一天的课,讲的是制度,工会制度,后勤制度,医疗制度,保密制度。 每一项都复杂得超乎想象。 我就要去在这样的...
    NeoTDX阅读 280评论 0 0
  • 验布巾帼何其多,布缕一览适可过; 须眉观后亲上手,凝眉定神布面游; 火眼一扫疵点出,手捻修刀疵顿无; 众女望后竟长...
    化骨真人阅读 234评论 0 1