OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 4:37 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: AR archive file (.a) layout
PostPosted: Sun Feb 07, 2021 2:56 pm 
Offline
Member
Member
User avatar

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


Top
 Profile  
 
 Post subject: Re: AR archive file (.a) layout
PostPosted: Sun Feb 07, 2021 3:59 pm 
Offline
Member
Member

Joined: Fri Nov 22, 2019 5:46 am
Posts: 590
I quote from Levine "Linkers & Loaders":
Quote:
In UNIX archives, the // member ... follows the symbol table."


Top
 Profile  
 
 Post subject: Re: AR archive file (.a) layout
PostPosted: Sun Feb 07, 2021 4:50 pm 
Offline
Member
Member
User avatar

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


Top
 Profile  
 
 Post subject: Re: AR archive file (.a) layout
PostPosted: Mon Feb 08, 2021 2:06 am 
Offline
Member
Member
User avatar

Joined: Sun Feb 18, 2007 7:28 pm
Posts: 1564
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();}


Top
 Profile  
 
 Post subject: Re: AR archive file (.a) layout
PostPosted: Mon Feb 08, 2021 3:20 am 
Offline
Member
Member

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


Top
 Profile  
 
 Post subject: Re: AR archive file (.a) layout
PostPosted: Mon Feb 08, 2021 3:39 am 
Offline
Member
Member
User avatar

Joined: Mon Jan 15, 2018 2:27 pm
Posts: 201
If that's the case, I am going for "do nothing" option. And thanks for letting me know about the book.


Top
 Profile  
 
 Post subject: Re: AR archive file (.a) layout
PostPosted: Mon Feb 08, 2021 3:40 am 
Offline
Member
Member
User avatar

Joined: Thu Oct 13, 2016 4:55 pm
Posts: 1584
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


Top
 Profile  
 
 Post subject: Re: AR archive file (.a) layout
PostPosted: Mon Feb 08, 2021 7:55 pm 
Offline
Member
Member
User avatar

Joined: Sun Feb 18, 2007 7:28 pm
Posts: 1564
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();}


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 28 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group