This is an archive of the discontinued LLVM Phabricator instance.

[ItaniumCXXABI] Always use linkonce_odr linkage for RTTI data on MinGW
ClosedPublic

Authored by mstorsjo on Aug 28 2017, 3:21 AM.

Details

Summary

This fixes cases where dynamic classes produced RTTI data with external linkage, producing linker errors about duplicate symbols.

This touches code close to what was changed in SVN r244266, but this change doesn't break the tests added in that revision.

I have to admit that I have little clue about what I'm doing here and I'm not sure if the exact fix is correct (it feels very heavy handed).

Hopefully the testcase shows what this fixes at least; this fixes linker errors with pretty trivial setups, where one object file contains the definition of a class with a virtual method (making the class dynamic, which previously meant that the typeinfo was emitted with external linkage) and another object file references typeid(ThatClass) (which produced a linkonce_odr version of that class' typeinfo).

Diff Detail

Repository
rL LLVM

Event Timeline

mstorsjo created this revision.Aug 28 2017, 3:21 AM
mstorsjo updated this revision to Diff 113309.Aug 30 2017, 1:56 PM

The previous diff lacked the extra context around the diff - fixed.

This revision is now accepted and ready to land.Aug 30 2017, 2:03 PM
mstorsjo added inline comments.Aug 30 2017, 2:11 PM
lib/CodeGen/ItaniumCXXABI.cpp
2994 ↗(On Diff #113309)

Thanks for having a look at this!

When giving this a second thought now, should we perhaps skip the check for Environment == GNU altogether? Or should xxx-windows-itanium be different by restricting this behaviour strictly to GNU (does it matter)?

And given the existing test case that you added with the previous form of this code, and the new test I'm adding here, are there any other odd corner cases I should check?

mstorsjo added inline comments.Aug 30 2017, 2:16 PM
lib/CodeGen/ItaniumCXXABI.cpp
2994 ↗(On Diff #113309)

To rephrase; previously, the comment talked about mingw specifically, but the code only checked for the dllimport attribute. So perhaps I should drop the check for GNU and just check for windows?

compnerd added inline comments.Aug 30 2017, 7:14 PM
lib/CodeGen/ItaniumCXXABI.cpp
2990–2993 ↗(On Diff #113309)

This is equivalent to: CGM.getContext().getTargetInfo().getTripleInfo().isWindowsGNUEnvironment()

2994 ↗(On Diff #113309)

Im not 100% certain off the top of my head, but I believe that windows-itanium should actually import the typename, so this should be okay.

mstorsjo added inline comments.Aug 30 2017, 10:14 PM
lib/CodeGen/ItaniumCXXABI.cpp
2990–2993 ↗(On Diff #113309)

Oh, indeed. Will change that before pushing. Thanks!

2994 ↗(On Diff #113309)

Ok then, keeping it specific to MinGW..

This revision was automatically updated to reflect the committed changes.