This is an archive of the discontinued LLVM Phabricator instance.

[MinGW] Don't mark external variables as DSO local
ClosedPublic

Authored by mstorsjo on Aug 28 2018, 2:03 PM.

Details

Summary

Since MinGW supports automatically importing external variables from DLLs even without the DLLImport attribute, we shouldn't mark them as DSO local unless we actually know them to be local for sure.

Keep marking thread local variables as DSO local.

Diff Detail

Repository
rC Clang

Event Timeline

mstorsjo created this revision.Aug 28 2018, 2:03 PM
rnk added inline comments.Aug 28 2018, 2:54 PM
lib/CodeGen/CodeGenModule.cpp
737

I think this linkage and declaration check should be GV->isDeclarationForLinker(), since that will catch available_externally globals as well. Those would come from a static data member of a class template that has an explicit instantiation declaration:

template <typename T>
struct Foo {
  static const int x = 42;
};
extern template struct Foo<int>;
const int *bar() {
  return &Foo<int>::x;
}

Yep, that does it on x86_64-windows-gnu. We probably want a stub for Foo<int>::x.

Can you add a test at clang/test/CodeGenCXX/dso-local.cpp for this?

mstorsjo added inline comments.Aug 29 2018, 2:48 AM
lib/CodeGen/CodeGenModule.cpp
737

Sure, will do.

mstorsjo updated this revision to Diff 163033.Aug 29 2018, 2:49 AM

Changed the condition to GV->isDeclarationForLinker(), updated tests accordingly (weak_bar in CodeGen/dso-local-executable.c lost the dso_local flag) and added more tests in CodeGenCXX/dso-local-executable.cpp as requested.

rnk accepted this revision.Aug 29 2018, 8:39 AM

lgtm

test/CodeGen/dso-local-executable.c
14

I take it that was a side effect of the isDeclarationForLinker change? I think that's correct.

This revision is now accepted and ready to land.Aug 29 2018, 8:39 AM
mstorsjo added inline comments.Aug 29 2018, 8:50 AM
test/CodeGen/dso-local-executable.c
14

Yes, it changed due to that. It probably won't hurt at least.

This revision was automatically updated to reflect the committed changes.