<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 - LTO ignores -fPIC/-fPIE when building a non PIE executable"
   href="https://bugs.llvm.org/show_bug.cgi?id=38676">38676</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>LTO ignores -fPIC/-fPIE when building a non PIE executable
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>new-bugs
          </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>enhancement
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>new bugs
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>mh+llvm@glandium.org
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>$ cat hello.c 
#include <stdio.h>

int main() {
  printf("Hello, world\n");
  return 0;
}

$ clang-7 -o hello hello.c -O3 -fPIC -flto=thin # same result with -flto
$ objdump -d hello
(...)
0000000000401130 <main>:
  401130:       50                      push   %rax
  401131:       bf 04 20 40 00          mov    $0x402004,%edi
  401136:       e8 f5 fe ff ff          callq  401030 <puts@plt>
  40113b:       31 c0                   xor    %eax,%eax
  40113d:       59                      pop    %rcx
  40113e:       c3                      retq   
  40113f:       90                      nop
(...)

Note how the string is loaded with an absolute address, compared to:

$ clang-7 -o hello hello.c -O3 -fPIC
$ objdump -d hello
(...)
0000000000401130 <main>:
  401130:       50                      push   %rax
  401131:       48 8d 3d cc 0e 00 00    lea    0xecc(%rip),%rdi        # 402004
<_IO_stdin_used+0x4>
  401138:       e8 f3 fe ff ff          callq  401030 <puts@plt>
  40113d:       31 c0                   xor    %eax,%eax
  40113f:       59                      pop    %rcx
  401140:       c3                      retq   
  401141:       66 2e 0f 1f 84 00 00    nopw   %cs:0x0(%rax,%rax,1)
  401148:       00 00 00 
  40114b:       0f 1f 44 00 00          nopl   0x0(%rax,%rax,1)
(...)

FWIW, GCC does respect -fPIC/-fPIE on LTOed non-PIE executables.</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>