<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Please add a "always replace file" option ("rcL") when concatenating archives"
   href="https://bugs.llvm.org/show_bug.cgi?id=52197">52197</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Please add a "always replace file" option ("rcL") when concatenating archives
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>tools
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Windows NT
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>llvm-ar
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>jujjyl@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>If one wants to create a new .a library file with .o files, one can use

  llvm-ar rc lib.a 1.o 2.o

command, and llvm-ar will delete the old file lib.a if it exists, and place 1.o
and 2.o into it.

If one wants to append files to an existing .a file without deleting the old
file, one can use command

  llvm-ar qc lib.a 1.o 2.o

That works nice and symmetric.

However sometimes when linking, one wants to link the file lib.a to a
yetAnotherLib.a file. If one uses either of the above commands to do this, e.g.

  llvm-ar rc yetAnotherLib.a lib.a 3.o 4.o

the archiver will place the file lib.a nested inside yetAnotherLib.a file, i.e.
in a form

yetAnotherLib.a:
  3.o
  4.o
  lib.a:
    1.o
    2.o

Sometimes this is undesirable, but one would instead want to concatenate/append
the contents without nesting, i.e. to have the following flattened result:

yetAnotherLib.a:
  1.o
  2.o
  3.o
  4.o

Llvm-ar does have an option to achieve this exactly, namely

  [L] - add archive's contents

so one could attempt to do

  llvm-ar rcL yetAnotherLib.a lib.a 3.o 4.o

to get the flattened output. But llvm-ar will complain

  llvm-ar.exe: error: the 'L' modifier is only applicable to the 'q' operation

Fair enough, then trying

  llvm-ar qcL yetAnotherLib.a lib.a 3.o 4.o

will cause the desired flat output to be generated.

However if one blindly changes the 'r' command to a 'q' command, it will
introduce a subtle but critical bug to a build system using it. Namely, the 'q'
command will concatenate files to an existing library, so if yetAnotherLib.a
already existed on disk from a previous build, it will accumulate more files
into it, keeping the old files around.

To get the desired "rcL" behavior, one will need to run two commands:

  rm yetAnotherLib.a
  llvm-ar qcL yetAnotherLib.a lib.a 3.o 4.o

to erase any old contents. This can be a bit tricky for some build systems to
implement that aren't e.g. based on shell expansions.

Would it be possible to add support for a "llvm-ar rcL" combination of flags,
which would always create a new archive, while still concatenating all input .a
files to the build, instead of adding them in a nested form?</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>