Where can I find the GNU ar file format specification?
Asked Answered
B

3

8

I need to access an ar created file, but I cannot find a specification document defining the format. Can someone point me in the right direction?

Barnette answered 20/3, 2013 at 20:15 Comment(3)
Why do you want to do that? Is the ar a static library? You might perhaps use libbfd ....Intact
I'm using ar to package arbitrary files. I'm not trying to access something output by a linker. ar gives me a simple way to bundle files together.Barnette
I then would use some more usual format, like tar .... See tar(5) man page or <tar.h> header for its description.Intact
C
6

From Wikipedia:

The ar format has never been standardized; modern archives are based on a common format with two known variants, BSD and GNU.

More information is there, too.

Catricecatrina answered 20/3, 2013 at 20:17 Comment(2)
Thanks! My google-skills failed me on this one. Glad yours had better success.Barnette
This doesn't answer the question. The OP is asking for the GNU ar format.Mori
S
2

Where to find information

It seems that GNU binutils does not have documentation for the file format.

I believe the best reference out there is in the ar(5) manual page from FreeBSD. The ar utility was removed in version 5.0 but the manpage for 4.11 is still available.

As usual, the header details can be found in the header files:

Also, the Wikipedia page for the AR file format has a nice diagram that describes the file format (it is from a .deb package which is also an ar file).

File format

This file has a very simple structure:

  • File signature (the one that identifies this as an ar file).
  • For every file in the archive we have:
    • A header that contains file name, owner, group, size, and permissions (see header file).
    • The file contents
    • And optionally padding (\n).
Shannan answered 4/4, 2022 at 12:14 Comment(3)
"It seems that GNU binutils does not have documentation for the file format." -- that's my concern here; how can someone maintain code to work properly if there is no spec?Mori
To be honest, 'ar' is a dying format. Debian (.deb) packages are .arfiles and they implemented their own ar encoder/decoder instead of using the ar utility see DPKG ar.cExclude
"To be honest, 'ar' is a dying format." So if I'm programming in C for embedded systems, what format would you expect me to use in the future for statically-linked libraries? I would have to disagree with you.Mori
H
0

Some information on IBM website: http://pic.dhe.ibm.com/infocenter/aix/v7r1/index.jsp?topic=%2Fcom.ibm.aix.files%2Fdoc%2Faixfiles%2Far_big.htm

Hilde answered 20/4, 2013 at 17:37 Comment(1)
This is valid for AIX Big Format, which has a different magic marker and probably a different structure. AIX global header is much more complicated than GNU/BSD format documented on Wikipedia.Catima

© 2022 - 2024 — McMap. All rights reserved.