<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 --- - --start-lib/--end-lib broken with LTO"
   href="https://llvm.org/bugs/show_bug.cgi?id=26674">26674</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>--start-lib/--end-lib broken with LTO
          </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>Linker
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>eugeni.stepanov@gmail.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>$ cat bin.cc 
int main() {}

$ cat 1.cc
__attribute__((constructor(0))) void ctor() {}

$ ./bin/clang++ -flto bin.cc -c
$ ./bin/clang++ -flto 1.cc -c
$ ./bin/clang++ -fuse-ld=gold -flto  bin.o -Wl,--start-lib 1.o -Wl,--end-lib
/tmp/lto-llvm-2af7ce.o(.init_array.0+0x0): error: undefined reference to
'ctor()'
clang-3.9: error: linker command failed with exit code 1 (use -v to see
invocation)

With -Wl,-plugin-opt,save-temps the merged IR (before link time optimizations)
looks like this:

[...]
@llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void
()*, i8* } { i32 0, void ()* @_Z4ctorv, i8* null }]

; Function Attrs: norecurse nounwind uwtable
define i32 @main() #0 {
entry:
  ret i32 0
}

; Function Attrs: nounwind uwtable
declare void @_Z4ctorv() #1
[...]


$ /usr/bin/ld.gold --version
GNU gold (GNU Binutils for Ubuntu 2.24) 1.11</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>