AR archive file (.a) layout

Programming, for all ages and all languages.
Post Reply
User avatar
pvc
Member
Member
Posts: 201
Joined: Mon Jan 15, 2018 2:27 pm

AR archive file (.a) layout

Post 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.
PeterX
Member
Member
Posts: 590
Joined: Fri Nov 22, 2019 5:46 am

Re: AR archive file (.a) layout

Post by PeterX »

I quote from Levine "Linkers & Loaders":
In UNIX archives, the // member ... follows the symbol table."
User avatar
pvc
Member
Member
Posts: 201
Joined: Mon Jan 15, 2018 2:27 pm

Re: AR archive file (.a) layout

Post 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.
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: AR archive file (.a) layout

Post 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.
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
PeterX
Member
Member
Posts: 590
Joined: Fri Nov 22, 2019 5:46 am

Re: AR archive file (.a) layout

Post 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.
User avatar
pvc
Member
Member
Posts: 201
Joined: Mon Jan 15, 2018 2:27 pm

Re: AR archive file (.a) layout

Post by pvc »

If that's the case, I am going for "do nothing" option. And thanks for letting me know about the book.
User avatar
bzt
Member
Member
Posts: 1584
Joined: Thu Oct 13, 2016 4:55 pm
Contact:

Re: AR archive file (.a) layout

Post 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
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: AR archive file (.a) layout

Post 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.
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
Post Reply