This is an archive of the discontinued LLVM Phabricator instance.

i686 mingw-w64 comdat functions use wrong .text section name
ClosedPublic

Authored by rnk on Nov 20 2018, 9:41 AM.

Details

Summary

Fix for bug 39218

This patch seems to fix this issue. However, from a code standpoint, I'm not sure it is up to standards. I am submitting this to see if it is directionally correct, and seeking feedback for a better way to accomplish this.

Questions I have:

  1. Are the modifications to the test correct? The code seems to function (it passes check-llvm, check-clang, and manual testing of the example with GCC). I am not very familiar with comdats or COFF, and therefore I am not 100% confident in the test case.
  2. Is GO->getComdat()->getName() the correct place to get the name, or is it a coincidence that it contains the right data?

Any feedback is welcome, and I am happy to submit another patch incorporating any suggested changes.

Diff Detail

Repository
rL LLVM

Event Timeline

herman6067 created this revision.Nov 20 2018, 9:41 AM
rnk added inline comments.Nov 21 2018, 1:11 PM
llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
1318–1324 ↗(On Diff #174803)

I think this needs a bit of massaging. I don't think we want to check for isArch32Bit, we should just always use the name of the comdat if it's available. However, GO->getComdat() may return null, and this code should fall back to getting the IR name of the global in that case. I'll try to put something together for this later today.

mstorsjo added inline comments.
llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
1318–1324 ↗(On Diff #174803)

Also, when it comes to "weird name mangling" on windows, the differentiator isn't usually whether it is 32 bit, but i386 alone has got the weird cases, 32 bit arm is just as simple/straightforward as x86_64 and arm64 when it comes to name mangling.

rnk commandeered this revision.Nov 21 2018, 1:44 PM
rnk edited reviewers, added: herman6067; removed: rnk.

Let me grab this to post the updated patch...

rnk updated this revision to Diff 174977.Nov 21 2018, 1:45 PM
  • generalize things slightly
rnk added inline comments.
llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
1318–1324 ↗(On Diff #174803)

Does this seem correct, @mstorsjo?

mstorsjo accepted this revision.Nov 21 2018, 1:55 PM

LGTM - this looks sensible to me. I haven't verified the original issue and whether this fixes it, but the change itself looks good.

This revision is now accepted and ready to land.Nov 21 2018, 1:55 PM
This revision was automatically updated to reflect the committed changes.
rnk added a comment.Nov 21 2018, 2:05 PM

LGTM - this looks sensible to me. I haven't verified the original issue and whether this fixes it, but the change itself looks good.

I never could reproduce the linker error either. =/ I can easily check the section name that GCC uses, but using the wrong section names doesn't seem to cause any problems, so I didn't prioritize fixing this. Anyway, better to match behavior when it's otherwise inconsequential.

In D54762#1305765, @rnk wrote:

I never could reproduce the linker error either. =/ I can easily check the section name that GCC uses, but using the wrong section names doesn't seem to cause any problems, so I didn't prioritize fixing this. Anyway, better to match behavior when it's otherwise inconsequential.

I was able to create the linker error using gcc 8.1.0 from mingw-builds.org. I've rebuilt clang with these changes and it seems to be working well now. Thank you very much!