<html>
    <head>
      <base href="http://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 --- - powerpc64 -fPIC missing required nop"
   href="http://llvm.org/bugs/show_bug.cgi?id=17354">17354</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>powerpc64 -fPIC missing required nop
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </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>Backend: PowerPC
          </td>
        </tr>

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

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

        <tr>
          <th>CC</th>
          <td>hfinkel@anl.gov, llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Repro with "clang -target powerpc64-pc-linux-gnu test.ii -fPIC -S -o -",
testcase:

  struct CS {
    int a_;
  };

  CS func();

  static CS glb[1] = {
    func()
  };

  CS func() {
    CS cs;
    cs.a_ = 0;
    return cs;
  }

Clang generates the same assembly with and without -fPIC. GCC adds a 'nop'
after the call to func. Clang's asm does this:

[...]
        .cfi_def_cfa_register r31
        addis 3, 2, _ZL3glb@toc@ha
        addi 3, 3, _ZL3glb@toc@l
        bl _Z4funcv
        addi 1, 1, 128
        ld 0, 16(1)
        ld 31, -8(1)
        mtlr 0
        blr
[...]

while GCC -fPIC emits:

[...]
        cmpw 7,10,9
        bne 7,.L3
        addis 9,2,_ZL3glb@toc@ha
        addi 9,9,_ZL3glb@toc@l
        mr 3,9
        bl _Z4funcv
        nop
.L3:
        addi 1,31,128
        .cfi_def_cfa 1, 0
        ld 0,16(1)
[...]

The linker (binutils gold 2.23.52.20130305) complains "other.cc:4: error: call
lacks nop, can't restore toc; recompile with -fPIC" when trying to link a final
program, after having built the code in the testcase into a .so.</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>