<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Recent changes to LibElfArchiveCreation</title><link>https://sourceforge.net/p/elftoolchain/wiki/LibElfArchiveCreation/</link><description>Recent changes to LibElfArchiveCreation</description><atom:link href="https://sourceforge.net/p/elftoolchain/wiki/LibElfArchiveCreation/feed" rel="self"/><language>en</language><lastBuildDate>Wed, 25 Dec 2013 07:30:23 -0000</lastBuildDate><atom:link href="https://sourceforge.net/p/elftoolchain/wiki/LibElfArchiveCreation/feed" rel="self" type="application/rss+xml"/><item><title>LibElfArchiveCreation modified by Joseph Koshy</title><link>https://sourceforge.net/p/elftoolchain/wiki/LibElfArchiveCreation/</link><description>&lt;div class="markdown_content"&gt;&lt;h1 id="ar1-archive-creation-using-libelf"&gt;&lt;code&gt;ar(1)&lt;/code&gt; archive creation using libelf&lt;/h1&gt;
&lt;div class="toc"&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="#ar1-archive-creation-using-libelf"&gt;ar(1) archive creation using libelf&lt;/a&gt;&lt;ul&gt;
&lt;li&gt;&lt;a href="#new-flags"&gt;New Flags&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#new-functions"&gt;New Functions&lt;/a&gt;&lt;ul&gt;
&lt;li&gt;&lt;a href="#elf_add_member"&gt;elf_add_member&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#elf_add_symtab"&gt;elf_add_symtab&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#elf_flagarhdr"&gt;elf_flagarhdr&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#other-changes"&gt;Other changes&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href="#using-the-extension"&gt;Using the extension&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;p&gt;We would like applications to be able to create &lt;code&gt;ar(1)&lt;/code&gt; archive using libelf. &lt;/p&gt;
&lt;p&gt;The new functions and symbols use an &lt;code&gt;ELF_&lt;/code&gt;/&lt;code&gt;elf_&lt;/code&gt; prefix to avoid polluting the namespace any more than is being done already by &lt;code&gt;&amp;lt;libelf.h&amp;gt;&lt;/code&gt;. &lt;/p&gt;
&lt;p&gt;The proposed API changes are as follows: &lt;/p&gt;
&lt;h2 id="new-flags"&gt;New Flags&lt;/h2&gt;
&lt;p&gt;Two new flags, namely &lt;code&gt;ELF_F_ARCHIVE&lt;/code&gt; and &lt;code&gt;ELF_F_ARCHIVE_SYSV&lt;/code&gt; will be defined in &lt;code&gt;libelf.h&lt;/code&gt; for use with &lt;code&gt;elf_flagelf()&lt;/code&gt;. These flag an &lt;code&gt;Elf&lt;/code&gt; descriptor as being for a new &lt;code&gt;ar(1)&lt;/code&gt; archive. These flags are only valid for use with &lt;code&gt;Elf&lt;/code&gt; descriptors that were created using &lt;code&gt;ELF_C_WRITE&lt;/code&gt;. &lt;/p&gt;
&lt;p&gt;The default format for an archive would be the BSD format, using the &lt;code&gt;ELF_F_ARCHIVE_SYSV&lt;/code&gt; flag changes that to SYSV style. &lt;/p&gt;
&lt;h2 id="new-functions"&gt;New Functions&lt;/h2&gt;
&lt;p&gt;Three new functions are defined: &lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;elf_add_member&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;elf_add_symtab&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;elf_flagarhdr&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="elf_add_member"&gt;&lt;code&gt;elf_add_member&lt;/code&gt;&lt;/h3&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span class="kt"&gt;off_t&lt;/span&gt;
&lt;span class="nf"&gt;elf_add_member&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Elf&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;ar&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ElfArhdr&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;arhdr&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This function adds object &lt;em&gt;data&lt;/em&gt; to the current archive at the end. The header metadata for the object, in particular the size of &lt;em&gt;data&lt;/em&gt; would be in &lt;em&gt;arhdr&lt;/em&gt;. The return value is a "tentative" offset that may be used to construct an &lt;code&gt;Elf_Arsym&lt;/code&gt; table for the symbols in this object. &lt;/p&gt;
&lt;p&gt;The offset is "tentative" because the actual sizes of the string and symbol table members, which must come before the data members themselves, aren't known at this point. &lt;/p&gt;
&lt;h3 id="elf_add_symtab"&gt;&lt;code&gt;elf_add_symtab&lt;/code&gt;&lt;/h3&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span class="kt"&gt;int&lt;/span&gt;
&lt;span class="nf"&gt;elf_add_symtab&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Elf&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;ar&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Elf_Arsym&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;ars&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;size_t&lt;/span&gt; &lt;span class="n"&gt;nentries&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This API would add the symbol table &lt;em&gt;ars&lt;/em&gt; to the archive. The &lt;em&gt;as_off&lt;/em&gt; members for entries will be adjusted at the time the archive is written out to compensate for the size of the symbol table itself and for the archive string table. &lt;/p&gt;
&lt;h3 id="elf_flagarhdr"&gt;&lt;code&gt;elf_flagarhdr&lt;/code&gt;&lt;/h3&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span class="kt"&gt;unsigned&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;
&lt;span class="nf"&gt;elf_flagarhdr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Elf_Arhdr&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Elf_Cmd&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;unsigned&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;flags&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Marks an &lt;code&gt;Elf_Arhdr&lt;/code&gt; structure as "dirty" for subsequent updation using &lt;code&gt;elf_update()&lt;/code&gt;. &lt;/p&gt;
&lt;h3 id="other-changes"&gt;Other changes&lt;/h3&gt;
&lt;p&gt;In addition to the above, &lt;code&gt;elf_update()&lt;/code&gt; would be augmented to deal with &lt;code&gt;ar(1)&lt;/code&gt; archives. &lt;/p&gt;
&lt;h2 id="using-the-extension"&gt;Using the extension&lt;/h2&gt;
&lt;p&gt;With this API extension, the program flow to create an AR archive would be: &lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;   &lt;span class="n"&gt;fd&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;/path/to/archive&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;O_WRONLY&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
   &lt;span class="n"&gt;ar&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;elf_begin&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fd&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ELF_C_WRITE&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;NULL&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
   &lt;span class="n"&gt;elf_flagelf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ar&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ELF_C_SET&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ELF_F_ARCHIVE&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="cm"&gt;/* creating an archive */&lt;/span&gt;

   &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="p"&gt;(...&lt;/span&gt;&lt;span class="n"&gt;there&lt;/span&gt; &lt;span class="n"&gt;are&lt;/span&gt; &lt;span class="n"&gt;more&lt;/span&gt; &lt;span class="n"&gt;members&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="n"&gt;add&lt;/span&gt;&lt;span class="p"&gt;...)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
         &lt;span class="n"&gt;e&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt; &lt;span class="n"&gt;get&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="n"&gt;pointer&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="n"&gt;raw&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="p"&gt;...;&lt;/span&gt;
         &lt;span class="n"&gt;arhdr&lt;/span&gt;  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt; &lt;span class="n"&gt;fill&lt;/span&gt; &lt;span class="n"&gt;up&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;archive&lt;/span&gt; &lt;span class="n"&gt;header&lt;/span&gt; &lt;span class="p"&gt;...;&lt;/span&gt;
         &lt;span class="n"&gt;off&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;elf_add_member&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ar&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;arhdr&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
         &lt;span class="p"&gt;...&lt;/span&gt; &lt;span class="n"&gt;fill&lt;/span&gt; &lt;span class="n"&gt;up&lt;/span&gt; &lt;span class="n"&gt;members&lt;/span&gt; &lt;span class="n"&gt;of&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;arsym&lt;/span&gt; &lt;span class="n"&gt;array&lt;/span&gt; &lt;span class="n"&gt;with&lt;/span&gt; &lt;span class="n"&gt;this&lt;/span&gt; &lt;span class="n"&gt;tentative&lt;/span&gt;
             &lt;span class="n"&gt;offset&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt; &lt;span class="p"&gt;..&lt;/span&gt;
   &lt;span class="p"&gt;}&lt;/span&gt;

   &lt;span class="n"&gt;elf_add_arsym&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ar&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;arsym&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;nentries&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="cm"&gt;/* add symbol table */&lt;/span&gt;
   &lt;span class="n"&gt;elf_update&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ar&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ELF_C_WRITE&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="cm"&gt;/* and write it out */&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Joseph Koshy</dc:creator><pubDate>Wed, 25 Dec 2013 07:30:23 -0000</pubDate><guid>https://sourceforge.net18693daaff02de7834cc4e6a39de15a8f41bc6c0</guid></item></channel></rss>