<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 --- - can't debug lto'd windows executables (invalid dwarf2 offset)"
   href="http://llvm.org/bugs/show_bug.cgi?id=22567">22567</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>can't debug lto'd windows executables (invalid dwarf2 offset)
          </td>
        </tr>

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

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

        <tr>
          <th>Reporter</th>
          <td>t.poechtrager@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>I have skipped error checking and so on to keep this as small as possible.

### Compile the "link time optimizer": ###

$ cat lto.c
#include <llvm-c/lto.h>
#include <stdio.h>

int main()
{
    const char *object;
    lto_code_gen_t codegen = lto_codegen_create();
    lto_codegen_add_module(codegen, lto_module_create("a.bc"));
    lto_codegen_add_module(codegen, lto_module_create("b.bc"));
    lto_codegen_set_debug_model(codegen, LTO_DEBUG_MODEL_DWARF);
    lto_codegen_add_must_preserve_symbol(codegen, "_main");
    lto_codegen_compile_to_file(codegen, &object);
    printf("%s", object);
    return 0;
}

$ clang lto.c `llvm-config --cflags --ldflags` -lLTO -o lto

### Generate two bitcode files for testing: ###

$ cat a.c
int x = 10;

int test()
{
    return ++x;
}

$ cat b.c
extern int test();

int main()
{
    return test();
}

$ clang -target i686-w64-mingw32 a.c -g -flto -c -o a.bc
$ clang -target i686-w64-mingw32 b.c -g -flto -c -o b.bc

$ file *.bc
a.bc: LLVM IR bitcode
b.bc: LLVM IR bitcode

### Generate the LTO'd executable: ###

i686-w64-mingw32-gcc `./lto` -o test.exe

$ file test.exe
test.exe: PE32 executable (console) Intel 80386, for MS Windows

### Load the LTO'd excutable with GDB: ###

$ i686-w64-mingw32-gdb test.exe
GNU gdb (GDB) 7.7.1
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <<a href="http://gnu.org/licenses/gpl.html">http://gnu.org/licenses/gpl.html</a>>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=x86_64-linux-gnu --target=i686-w64-mingw32".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<<a href="http://www.gnu.org/software/gdb/bugs/">http://www.gnu.org/software/gdb/bugs/</a>>.
Find the GDB manual and other documentation resources online at:
<<a href="http://www.gnu.org/software/gdb/documentation/">http://www.gnu.org/software/gdb/documentation/</a>>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from test.exe...done.
invalid dwarf2 offset 4252634

Now GDB complains about an invalid dwarf2 offset and therefore it's
not possible to debug the resulting executable.

This also happens on a native Windows machine.

The resulting executable works the way it should though:

$ wine test.exe ; echo $?
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>