<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </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 --- - LLD fails to devirtualize the code that Gold plugin does"
   href="https://llvm.org/bugs/show_bug.cgi?id=28554">28554</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>LLD fails to devirtualize the code that Gold plugin does
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>lld
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </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>ELF
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>krasin@google.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=16742" name="attach_16742" title="devirt.cc">attachment 16742</a> <a href="attachment.cgi?id=16742&action=edit" title="devirt.cc">[details]</a></span>
devirt.cc

Consider the attached program, devirt.cc. With Gold and LLVM Gold plugin we
get:

$ clang++ -O2 -fuse-ld=gold -o lala -fvisibility=hidden devirt.cc -std=c++11
-flto -fwhole-program-vtables  -Wl,-plugin-opt,-pass-remarks=wholeprogramdevirt
-Wl,-plugin-opt,O1 -Wl,-plugin-opt,-function-sections
-Wl,-plugin-opt,save-temps
LLVM gold plugin: <unknown>:0:0: devirtualized call
LLVM gold plugin: <unknown>:0:0: devirtualized call
LLVM gold plugin: <unknown>:0:0: devirtualized call
$

In the bitcode (lala.opt.bc) we see the call was devirtualized:
  %vfn = getelementptr inbounds i1 (%class.Base*, i32)*, i1 (%class.Base*,
i32)** %vtable, i64 2
  %10 = load i1 (%class.Base*, i32)*, i1 (%class.Base*, i32)** %vfn, align 8
  %11 = icmp ne i8* %9, getelementptr (i8, i8* bitcast ([6 x i8*]* @_ZTV1A to
i8*), i64 16)
  %conv = zext i1 %11 to i32
  %call19 = tail call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x
i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %conv)

If we link with lld, nothing happens:
$ clang++ -fuse-ld=lld -o lala devirt.cc -std=c++11 -flto -fvisibility=hidden
-fwhole-program-vtables  -Wl,-mllvm,-pass-remarks=wholeprogramdevirt
-Wl,--lto-O1  -Wl,-save-temps  
$

And the bitcode shows that we still have a virtual call:

  %vfn = getelementptr inbounds i1 (%class.Base*, i32)*, i1 (%class.Base*,
i32)** %vtable, i64 2
  %19 = load i1 (%class.Base*, i32)*, i1 (%class.Base*, i32)** %vfn, align 8
  %call17 = invoke zeroext i1 %19(%class.Base* %call15, i32 1)
          to label %invoke.cont16 unwind label %lpad

invoke.cont16:                                    ; preds = %sw.epilog
  %conv = zext i1 %call17 to i32
  %call19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8],
[4 x i8]* @.str.1, i32 0, i32 0), i32 %conv)

This prevents lld from being deployed in Chromium as the default linker on
Linux.</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>