OSDN Git Service

Make x86 __ehhandler comdat if parent function is
authorDave Lee <davelee.com@gmail.com>
Fri, 20 Oct 2017 17:04:43 +0000 (17:04 +0000)
committerDave Lee <davelee.com@gmail.com>
Fri, 20 Oct 2017 17:04:43 +0000 (17:04 +0000)
commit585416691f8b508b83223a8c0f2a6595b7aa4be6
tree8631f8f06d1e5a9ca3e39bf5f78fde15d750a1f3
parentb99a8bcc2b50f7bb879129ce18e144fbc1111a1a
Make x86 __ehhandler comdat if parent function is

Summary:
This change comes from using lld for i686-windows-msvc. Before this change, lld
emits an error of:

    error: relocation against symbol in discarded section: .xdata

It's possible that this could be addressed in lld, but I think this change is
reasonable on its own.

At a high level, this is being generated:

    A (.text comdat) -> B (.text) -> C (.xdata comdat)

Where A is a C++ inline function, which references B, an exception handler
thunk, which references C, the exception handling info.

With this structure, lld will error when applying relocations to B if the C it
references has been discarded (some other C has been selected).

This change checks if A is comdat, and if so places the exception registration
thunk (B) in the comdata group of A (and B).

It appears that MSVC makes the __ehhandler function comdat.

Is it possible that duplicate thunks are being emitted into the final binary
with other linkers, or are they stripping the unused thunks?

Reviewers: rnk, majnemer, compnerd, smeenai

Reviewed By: rnk, compnerd

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D38940

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@316219 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Target/X86/X86WinEHState.cpp
test/CodeGen/WinEH/wineh-comdat.ll [new file with mode: 0644]