Page 1 of 1
AR archive file (.a) layout
Posted: Sun Feb 07, 2021 2:56 pm
by pvc
I am working on my own linker/archiver and I have some trouble finding any definitive description of .a file format. There are few known .a file variants so I decided to use System V/GNU one. Normally .a files are capable of storing only 15 (+ '/' terminator) file name characters. Longer filenames are stored in separate pseudo-file (named "//") and referenced by archived files that need long names. GNU tools seem to always store that long file name pseudo-file before any regular files. So does my linker/archiver. But I wonder if it is guaranteed to be like that. Or can long file name pseudo-file exist anywhere in the archive? Do I have to deal with such case? Doing so would complicate things a little bit.
Re: AR archive file (.a) layout
Posted: Sun Feb 07, 2021 3:59 pm
by PeterX
I quote from Levine "Linkers & Loaders":
In UNIX archives, the // member ... follows the symbol table."
Re: AR archive file (.a) layout
Posted: Sun Feb 07, 2021 4:50 pm
by pvc
Ok… I assume that by "symbol table" he means symbol index (which is BTW optional). So, that's +1 for "do nothing" option. I would add another +1 for "do nothing" because I'm lazy.
But the question is still open.
Re: AR archive file (.a) layout
Posted: Mon Feb 08, 2021 2:06 am
by neon
Hi,
Our AR files are compatible with MSVC but it sounds like it does it similarly. That is, the first member is always \ ("first linker member") followed by \ ("second linker member") and another \\ ("long file names") then the file list. File names that are "/<digits>" are looked up via the long file name table. There is no way to differentiate between the first and second linker member entries with just looking at the file header alone so I would expect them to always have to be the first three members in that specific order. If requested....I can generate an AR file with the members out of order to see what happens. Am betting the linker won't like it though.
Re: AR archive file (.a) layout
Posted: Mon Feb 08, 2021 3:20 am
by PeterX
neon wrote:Hi,
Our AR files are compatible with MSVC but it sounds like it does it similarly. That is, the first member is always \ ("first linker member") followed by \ ("second linker member") and another \\ ("long file names") then the file list. File names that are "/<digits>" are looked up via the long file name table. There is no way to differentiate between the first and second linker member entries with just looking at the file header alone so I would expect them to always have to be the first three members in that specific order. If requested....I can generate an AR file with the members out of order to see what happens. Am betting the linker won't like it though.
The same book from which I qouted says indeed that the long filename entry is always the third in Windows archives.
Re: AR archive file (.a) layout
Posted: Mon Feb 08, 2021 3:39 am
by pvc
If that's the case, I am going for "do nothing" option. And thanks for letting me know about the book.
Re: AR archive file (.a) layout
Posted: Mon Feb 08, 2021 3:40 am
by bzt
There's a
wiki page on a.out. As for AR,
normal wikipedia, but I think your best bet would be to read binutil's ar
source for aout AR and see how that does it. The bfd source is actually full of comments.
Also check out include/aout/aout64.h and include/aout/ar.h (again, lots of comments)
Cheers,
bzt
Re: AR archive file (.a) layout
Posted: Mon Feb 08, 2021 7:55 pm
by neon
Hi,
We can always provide our archive utility source if needed -- it just sounded like from the original post that you have already written one and was just inquiring on the ordering of its special files. If you think it might be helpful though or would like to compare, please feel free to let me know.