<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 - Impossible to disable .eh_frame generation with PE/COFF LTO"
   href="https://bugs.llvm.org/show_bug.cgi?id=45325">45325</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Impossible to disable .eh_frame generation with PE/COFF LTO
          </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>All
          </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>COFF
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>vit9696@avp.su
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>The issue is similar to clang bug[1], so it is recommended to read it first to
understand the problem.

With LLD the .eh_frame section creation with disabled exceptions is relevant
because of LTO. When LTO is enabled LLD will generate its own functions, and
will thus use the exception model. To configure the exception model in LLD one
can use /mllvm argument (e.g. /mllvm:-exception-model=default). Unfortunately
for LLD the chosen exception model can be anything but disabled once again due
to the defaults[2].

test.c:

void entry() {
}

$ clang -g -fno-builtin -ffunction-sections -fdata-sections -fno-common
-fno-stack-protector -funsigned-char -mno-implicit-float -nostdlib -nostdlibinc
-m32 -Oz -march=i586 -target i686-unknown-windows-gnu -gcodeview
-fno-exceptions -flto -c -o test.obj test.c
$ lld-link /OUT:test.dll /NOLOGO /NODEFAULTLIB /IGNORE:4001 /OPT:REF
/OPT:ICF=10 /ALIGN:32 /FILEALIGN:32 /Machine:X86 /DLL /ENTRY:entry
/SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER /BASE:0 /DEBUG:GHASH /SAFESEH:NO /lldmap
test.obj

To reproduce the problem with currently broken clang one can use
-fseh-exceptions for compilation.

The resolution should probably introduce /mllvm:-exception-model=none argument.
I am not sure how can one implement it best. Now that I think about both bugs,
perhaps it is best to fix the ExceptionHandling enum[3]? Half through the code
None is interpreted as "Default" and gets constantly overridden with other
values coming from e.g. target default. If we rename ExceptionModel::None to
ExceptionModel::Default and introduce a real ExceptionModel::None, then we
could get rid of ugly hacks like this one[4].

I will add a backlink to this bug in #45324, but I guess it will be easier to
discuss it in one place, let's better do it in #45324.

[1] <a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Clang generates .debug_frame/.eh_frame with exceptions disabled for PE/COFF"
   href="show_bug.cgi?id=45324">https://bugs.llvm.org/show_bug.cgi?id=45324</a>
[2]
<a href="https://github.com/llvm/llvm-project/blob/ac1d23ed7de01fb3a18b340536842a419b504d86/llvm/lib/CodeGen/CommandFlags.cpp#L141-L156">https://github.com/llvm/llvm-project/blob/ac1d23ed7de01fb3a18b340536842a419b504d86/llvm/lib/CodeGen/CommandFlags.cpp#L141-L156</a>
[3]
<a href="https://github.com/llvm/llvm-project/blob/ee2c0f76d74cc03e54389926c9e626987e1408c3/llvm/include/llvm/MC/MCTargetOptions.h#L17-L24">https://github.com/llvm/llvm-project/blob/ee2c0f76d74cc03e54389926c9e626987e1408c3/llvm/include/llvm/MC/MCTargetOptions.h#L17-L24</a>
[4]
<a href="https://github.com/llvm/llvm-project/blob/b61a4aaca5f8a1e71eeaee74d93cdd6fccbef065/llvm/lib/CodeGen/LLVMTargetMachine.cpp#L70-L71">https://github.com/llvm/llvm-project/blob/b61a4aaca5f8a1e71eeaee74d93cdd6fccbef065/llvm/lib/CodeGen/LLVMTargetMachine.cpp#L70-L71</a></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>