<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 - llvm-ar 'Replace' option adds duplicate files to thin archives"
   href="https://bugs.llvm.org/show_bug.cgi?id=38542">38542</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>llvm-ar 'Replace' option adds duplicate files to thin archives
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>6.0
          </td>
        </tr>

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

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

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

        <tr>
          <th>Severity</th>
          <td>normal
          </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>wdelgenio@ocient.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>When creating thin archives, the 'Replace' option is buggy and will allow for
multiple copies of the same object file within the archive iff the object file
is not in the current directory.

Steps to reproduce:
mkdir foo
clang -c -x c /dev/null -o foo/test.o
llvm-ar Trcs test.a foo/test.o
llvm-ar Trcs test.a foo/test.o
llvm-ar t test.a

Output:
/foo/test.o
/foo/test.o

The bug appears to be in computerInsertAction() in llvm-ar.cpp:

  auto MI = find_if(Members, [Name](StringRef Path) {
    return Name == sys::path::filename(Path);
  });

The objects files are stored with the full path in the thin archive format, but
sys::path::filename will throw out the path, making the find_if function fail
every time unless the object file is in the current directory.  Ie in the
example above Name = "/foo/test.o" and sys::path::filename(Path) = "test.o".

I think the fix is to check if it's a thin archive, and if so, compare Name and
Path without the call to filename().

Will that work?</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>