Skip to content

[LLVM][Clang][Cygwin] Fix Cygwin builds #134458

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 4 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/include/clang/Support/Compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
#define CLANG_EXPORT_TEMPLATE
#endif
#elif defined(__ELF__) || defined(__MINGW32__) || defined(_AIX) || \
defined(__MVS__)
defined(__MVS__) || defined(__CYGWIN__)
#define CLANG_ABI LLVM_ATTRIBUTE_VISIBILITY_DEFAULT
#define CLANG_TEMPLATE_ABI LLVM_ATTRIBUTE_VISIBILITY_DEFAULT
#define CLANG_EXPORT_TEMPLATE
Expand Down
3 changes: 1 addition & 2 deletions clang/lib/AST/ItaniumCXXABI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,7 @@ class ItaniumCXXABI : public CXXABI {

CallingConv getDefaultMethodCallConv(bool isVariadic) const override {
const llvm::Triple &T = Context.getTargetInfo().getTriple();
if (!isVariadic && T.isWindowsGNUEnvironment() &&
T.getArch() == llvm::Triple::x86)
if (!isVariadic && T.isOSCygMing() && T.getArch() == llvm::Triple::x86)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this PR is closed, but for the record: this particular change appears to be wrong: on i686 cygwin with this change calls to libstdc++ basic_string::_M_assign crashed, but with this change backed out it's much happier.

return CC_X86ThisCall;
return Context.getTargetInfo().getDefaultCallingConv();
}
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/AST/RecordLayoutBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1950,7 +1950,7 @@ void ItaniumRecordLayoutBuilder::LayoutField(const FieldDecl *D,
// silently there. For other targets that have ms_struct enabled
// (most probably via a pragma or attribute), trigger a diagnostic
// that defaults to an error.
if (!Context.getTargetInfo().getTriple().isWindowsGNUEnvironment())
if (!Context.getTargetInfo().getTriple().isOSCygMing())
Diag(D->getLocation(), diag::warn_npot_ms_struct);
}
if (TypeSize > FieldAlign &&
Expand Down
1 change: 0 additions & 1 deletion clang/lib/Basic/Targets/X86.h
Original file line number Diff line number Diff line change
Expand Up @@ -948,7 +948,6 @@ class LLVM_LIBRARY_VISIBILITY CygwinX86_64TargetInfo : public X86_64TargetInfo {
CygwinX86_64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
: X86_64TargetInfo(Triple, Opts) {
this->WCharType = TargetInfo::UnsignedShort;
TLSSupported = false;
}

void getTargetDefines(const LangOptions &Opts,
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/CodeGen/CodeGenModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1680,7 +1680,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 @@ -3757,7 +3757,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 @@ -4044,10 +4044,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
2 changes: 1 addition & 1 deletion clang/lib/CodeGen/Targets/X86.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1391,7 +1391,7 @@ class WinX86_64ABIInfo : public ABIInfo {
public:
WinX86_64ABIInfo(CodeGen::CodeGenTypes &CGT, X86AVXABILevel AVXLevel)
: ABIInfo(CGT), AVXLevel(AVXLevel),
IsMingw64(getTarget().getTriple().isWindowsGNUEnvironment()) {}
IsMingw64(getTarget().getTriple().isOSCygMing()) {}

void computeInfo(CGFunctionInfo &FI) const override;

Expand Down
4 changes: 1 addition & 3 deletions clang/lib/Driver/ToolChain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -744,9 +744,7 @@ std::string ToolChain::buildCompilerRTBasename(const llvm::opt::ArgList &Args,
Suffix = IsITANMSVCWindows ? ".lib" : ".a";
break;
case ToolChain::FT_Shared:
Suffix = TT.isOSWindows()
? (TT.isWindowsGNUEnvironment() ? ".dll.a" : ".lib")
: ".so";
Suffix = TT.isOSWindows() ? (TT.isOSCygMing() ? ".dll.a" : ".lib") : ".so";
break;
}

Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Sema/SemaDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12536,7 +12536,7 @@ static bool isDefaultStdCall(FunctionDecl *FD, Sema &S) {

// Default calling convention for MinGW is __cdecl
const llvm::Triple &T = S.Context.getTargetInfo().getTriple();
if (T.isWindowsGNUEnvironment())
if (T.isOSCygMing())
return false;

// Default calling convention for WinMain, wWinMain and DllMain
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 @@ -6272,7 +6272,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 @@ -6574,7 +6574,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 @@ -8889,8 +8889,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 @@ -9758,7 +9757,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 @@ -9823,7 +9822,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 @@ -9991,7 +9990,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: 1 addition & 1 deletion llvm/cmake/modules/AddLLVM.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ function(llvm_add_library name)
# When building shared objects for each target there are some internal APIs
# that are used across shared objects which we can't hide.
if (LLVM_BUILD_LLVM_DYLIB_VIS AND NOT BUILD_SHARED_LIBS AND NOT APPLE AND
(NOT (WIN32 OR CYGWIN) OR (MINGW AND CMAKE_CXX_COMPILER_ID MATCHES "Clang")) AND
(NOT (WIN32 OR CYGWIN) OR ((MINGW OR CYGWIN) AND CMAKE_CXX_COMPILER_ID MATCHES "Clang")) AND
NOT (${CMAKE_SYSTEM_NAME} MATCHES "AIX") AND
NOT DEFINED CMAKE_CXX_VISIBILITY_PRESET)

Expand Down
4 changes: 2 additions & 2 deletions llvm/include/llvm/Support/Compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
#endif

#if (!(defined(_WIN32) || defined(__CYGWIN__)) || \
(defined(__MINGW32__) && defined(__clang__)))
((defined(__MINGW32__) || defined(__CYGWIN__)) && defined(__clang__)))
#define LLVM_LIBRARY_VISIBILITY LLVM_ATTRIBUTE_VISIBILITY_HIDDEN
// Clang compilers older then 15 do not support gnu style attributes on
// namespaces.
Expand Down Expand Up @@ -198,7 +198,7 @@
#endif
#define LLVM_ABI_EXPORT __declspec(dllexport)
#elif defined(__ELF__) || defined(__MINGW32__) || defined(_AIX) || \
defined(__MVS__)
defined(__MVS__) || defined(__CYGWIN__)
#define LLVM_ABI LLVM_ATTRIBUTE_VISIBILITY_DEFAULT
#define LLVM_TEMPLATE_ABI LLVM_ATTRIBUTE_VISIBILITY_DEFAULT
#define LLVM_EXPORT_TEMPLATE
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ add_llvm_component_library(LLVMTarget
# When building shared objects for each target there are some internal APIs
# that are used across shared objects which we can't hide.
if (NOT BUILD_SHARED_LIBS AND NOT APPLE AND
(NOT (WIN32 OR CYGWIN) OR (MINGW AND CMAKE_CXX_COMPILER_ID MATCHES "Clang")) AND
(NOT (WIN32 OR CYGWIN) OR ((MINGW OR CYGWIN) AND CMAKE_CXX_COMPILER_ID MATCHES "Clang")) AND
NOT (${CMAKE_SYSTEM_NAME} MATCHES "AIX") AND
NOT DEFINED CMAKE_CXX_VISIBILITY_PRESET)
# Set default visibility to hidden, so we don't export all the Target classes
Expand Down
4 changes: 2 additions & 2 deletions llvm/tools/llvm-shlib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ if(LLVM_BUILD_LLVM_DYLIB)
else()
# GNU ld doesn't resolve symbols in the version script.
set(LIB_NAMES -Wl,--whole-archive ${LIB_NAMES} -Wl,--no-whole-archive)
if (NOT LLVM_LINKER_IS_SOLARISLD AND NOT MINGW)
if (NOT LLVM_LINKER_IS_SOLARISLD AND NOT (MINGW OR CYGWIN))
# Solaris ld does not accept global: *; so there is no way to version *all* global symbols
set(LIB_NAMES -Wl,--version-script,${LLVM_LIBRARY_DIR}/tools/llvm-shlib/simple_version_script.map ${LIB_NAMES})
endif()
if (NOT MINGW AND NOT LLVM_LINKER_IS_SOLARISLD_ILLUMOS)
if (NOT (MINGW OR CYGWIN) AND NOT LLVM_LINKER_IS_SOLARISLD_ILLUMOS)
# Optimize function calls for default visibility definitions to avoid PLT and
# reduce dynamic relocations.
# Note: for -fno-pic default, the address of a function may be different from
Expand Down
Loading