Skip to content

[Cygwin] Export global symbols, template instantiations, RTTI and VTable are exported correctly #138773

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clang/lib/CodeGen/CodeGenModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1685,7 +1685,7 @@ static bool shouldAssumeDSOLocal(const CodeGenModule &CGM,

const llvm::Triple &TT = CGM.getTriple();
const auto &CGOpts = CGM.getCodeGenOpts();
if (TT.isWindowsGNUEnvironment()) {
if (TT.isOSCygMing()) {
// In MinGW, variables without DLLImport can still be automatically
// imported from a DLL by the linker; don't mark variables that
// potentially could come from another DLL as DSO local.
Expand Down
7 changes: 2 additions & 5 deletions clang/lib/CodeGen/ItaniumCXXABI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3754,7 +3754,7 @@ static bool ShouldUseExternalRTTIDescriptor(CodeGenModule &CGM,
bool IsDLLImport = RD->hasAttr<DLLImportAttr>();

// Don't import the RTTI but emit it locally.
if (CGM.getTriple().isWindowsGNUEnvironment())
if (CGM.getTriple().isOSCygMing())
return false;

if (CGM.getVTables().isVTableExternal(RD)) {
Expand Down Expand Up @@ -4041,10 +4041,7 @@ static llvm::GlobalVariable::LinkageTypes getTypeInfoLinkage(CodeGenModule &CGM,
return llvm::GlobalValue::ExternalLinkage;
// MinGW always uses LinkOnceODRLinkage for type info.
if (RD->isDynamicClass() &&
!CGM.getContext()
.getTargetInfo()
.getTriple()
.isWindowsGNUEnvironment())
!CGM.getContext().getTargetInfo().getTriple().isOSCygMing())
return CGM.getVTableLinkage(RD);
}

Expand Down
4 changes: 2 additions & 2 deletions clang/lib/Sema/SemaDeclCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6274,7 +6274,7 @@ static void ReferenceDllExportedMembers(Sema &S, CXXRecordDecl *Class) {
}
} MarkingDllexportedContext(S, Class, ClassAttr->getLocation());

if (S.Context.getTargetInfo().getTriple().isWindowsGNUEnvironment())
if (S.Context.getTargetInfo().getTriple().isOSCygMing())
S.MarkVTableUsed(Class->getLocation(), Class, true);

for (Decl *Member : Class->decls()) {
Expand Down Expand Up @@ -6576,7 +6576,7 @@ void Sema::checkClassLevelDLLAttribute(CXXRecordDecl *Class) {
// declarations, except in MinGW mode.
if (ClassExported && !ClassAttr->isInherited() &&
TSK == TSK_ExplicitInstantiationDeclaration &&
!Context.getTargetInfo().getTriple().isWindowsGNUEnvironment()) {
!Context.getTargetInfo().getTriple().isOSCygMing()) {
Class->dropAttr<DLLExportAttr>();
return;
}
Expand Down
9 changes: 4 additions & 5 deletions clang/lib/Sema/SemaTemplate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8938,8 +8938,7 @@ Sema::CheckSpecializationInstantiationRedecl(SourceLocation NewLoc,
// The declaration itself has not actually been instantiated, so it is
// still okay to specialize it.
StripImplicitInstantiation(
PrevDecl,
Context.getTargetInfo().getTriple().isWindowsGNUEnvironment());
PrevDecl, Context.getTargetInfo().getTriple().isOSCygMing());
return false;
}
// Fall through
Expand Down Expand Up @@ -9806,7 +9805,7 @@ DeclResult Sema::ActOnExplicitInstantiation(
: TSK_ExplicitInstantiationDeclaration;

if (TSK == TSK_ExplicitInstantiationDeclaration &&
!Context.getTargetInfo().getTriple().isWindowsGNUEnvironment()) {
!Context.getTargetInfo().getTriple().isOSCygMing()) {
// Check for dllexport class template instantiation declarations,
// except for MinGW mode.
for (const ParsedAttr &AL : Attr) {
Expand Down Expand Up @@ -9871,7 +9870,7 @@ DeclResult Sema::ActOnExplicitInstantiation(
= PrevDecl ? PrevDecl->getTemplateSpecializationKind() : TSK_Undeclared;

if (TSK == TSK_ExplicitInstantiationDefinition && PrevDecl != nullptr &&
Context.getTargetInfo().getTriple().isWindowsGNUEnvironment()) {
Context.getTargetInfo().getTriple().isOSCygMing()) {
// Check for dllexport class template instantiation definitions in MinGW
// mode, if a previous declaration of the instantiation was seen.
for (const ParsedAttr &AL : Attr) {
Expand Down Expand Up @@ -10039,7 +10038,7 @@ DeclResult Sema::ActOnExplicitInstantiation(
// In MinGW mode, export the template instantiation if the declaration
// was marked dllexport.
if (PrevDecl_TSK == TSK_ExplicitInstantiationDeclaration &&
Context.getTargetInfo().getTriple().isWindowsGNUEnvironment() &&
Context.getTargetInfo().getTriple().isOSCygMing() &&
PrevDecl->hasAttr<DLLExportAttr>()) {
dllExportImportClassTemplateSpecialization(*this, Def);
}
Expand Down
2 changes: 2 additions & 0 deletions clang/test/CodeGen/dllexport.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// RUN: %clang_cc1 -triple x86_64-windows-msvc -fms-extensions -emit-llvm -std=c11 -O0 -o - %s | FileCheck %s
// RUN: %clang_cc1 -triple i686-windows-gnu -fms-extensions -emit-llvm -std=c11 -O0 -o - %s | FileCheck %s
// RUN: %clang_cc1 -triple x86_64-windows-gnu -fms-extensions -emit-llvm -std=c11 -O0 -o - %s | FileCheck %s
// RUN: %clang_cc1 -triple i686-pc-cygwin -fms-extensions -emit-llvm -std=c11 -O0 -o - %s | FileCheck %s
// RUN: %clang_cc1 -triple x86_64-pc-cygwin -fms-extensions -emit-llvm -std=c11 -O0 -o - %s | FileCheck %s



Expand Down
3 changes: 3 additions & 0 deletions clang/test/CodeGen/dllimport.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
// RUN: %clang_cc1 -triple x86_64-windows-msvc -fms-extensions -emit-llvm -std=c11 -O0 -o - %s | FileCheck --check-prefix=CHECK --check-prefix=MS %s
// RUN: %clang_cc1 -triple i686-windows-gnu -fms-extensions -emit-llvm -std=c11 -O0 -o - %s | FileCheck --check-prefix=CHECK --check-prefix=GNU %s
// RUN: %clang_cc1 -triple x86_64-windows-gnu -fms-extensions -emit-llvm -std=c11 -O0 -o - %s | FileCheck --check-prefix=CHECK --check-prefix=GNU %s
// RUN: %clang_cc1 -triple i686-pc-cygwin -fms-extensions -emit-llvm -std=c11 -O0 -o - %s | FileCheck --check-prefix=CHECK --check-prefix=GNU %s
// RUN: %clang_cc1 -triple x86_64-pc-cygwin -fms-extensions -emit-llvm -std=c11 -O0 -o - %s | FileCheck --check-prefix=CHECK --check-prefix=GNU %s
// RUN: %clang_cc1 -triple i686-windows-msvc -fms-extensions -emit-llvm -std=c11 -O1 -fno-inline -o - %s | FileCheck --check-prefix=O1 --check-prefix=MO1 %s
// RUN: %clang_cc1 -triple i686-windows-gnu -fms-extensions -emit-llvm -std=c11 -O1 -fno-inline -o - %s | FileCheck --check-prefix=O1 --check-prefix=GO1 %s
// RUN: %clang_cc1 -triple i686-pc-cygwin -fms-extensions -emit-llvm -std=c11 -O1 -fno-inline -o - %s | FileCheck --check-prefix=O1 --check-prefix=GO1 %s

#define JOIN2(x, y) x##y
#define JOIN(x, y) JOIN2(x, y)
Expand Down
3 changes: 3 additions & 0 deletions clang/test/CodeGen/dso-local-executable.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
// RUN: %clang_cc1 -triple x86_64-w64-mingw32 -emit-llvm %s -o - | FileCheck --check-prefixes=MINGW,MINGW-NATIVE_TLS,MINGW-AUTO-IMPORT %s
// RUN: %clang_cc1 -triple x86_64-w64-mingw32 -emit-llvm %s -o - -fno-auto-import | FileCheck --check-prefixes=MINGW,MINGW-NATIVE_TLS,MINGW-NO-AUTO-IMPORT %s
// RUN: %clang_cc1 -triple x86_64-w64-mingw32 -emit-llvm %s -o - -femulated-tls | FileCheck --check-prefixes=MINGW,MINGW-EMUTLS,MINGW-AUTO-IMPORT %s
// RUN: %clang_cc1 -triple x86_64-pc-cygwin -emit-llvm %s -o - | FileCheck --check-prefixes=MINGW,MINGW-NATIVE_TLS,MINGW-AUTO-IMPORT %s
// RUN: %clang_cc1 -triple x86_64-pc-cygwin -emit-llvm %s -o - -fno-auto-import | FileCheck --check-prefixes=MINGW,MINGW-NATIVE_TLS,MINGW-NO-AUTO-IMPORT %s
// RUN: %clang_cc1 -triple x86_64-pc-cygwin -emit-llvm %s -o - -femulated-tls | FileCheck --check-prefixes=MINGW,MINGW-EMUTLS,MINGW-AUTO-IMPORT %s
// MINGW: @baz = dso_local global i32 42
// MINGW-NEXT: @import_var = external dllimport global i32
// MINGW-NEXT: @weak_bar = extern_weak global i32
Expand Down
Loading