Skip to content

[libclang][Cygwin] Use __declspec(dllexport) for libclang on Cygwin #147122

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

Merged
merged 1 commit into from
Jul 7, 2025

Conversation

kikairoya
Copy link
Contributor

This is needed for Cygwin build without -DLLVM_LINK_LLVM_DYLIB=ON, otherwise causes a linker error 'export ordinal too large'.

This is needed for Cygwin build without LLVM_LINK_LLVM_DYLIB, otherwise
causes a linker error 'export ordinal too large'.
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:as-a-library libclang and C++ API labels Jul 5, 2025
@llvmbot
Copy link
Member

llvmbot commented Jul 5, 2025

@llvm/pr-subscribers-clang

Author: Tomohiro Kashiwada (kikairoya)

Changes

This is needed for Cygwin build without -DLLVM_LINK_LLVM_DYLIB=ON, otherwise causes a linker error 'export ordinal too large'.


Full diff: https://github.com/llvm/llvm-project/pull/147122.diff

1 Files Affected:

  • (modified) clang/include/clang-c/Platform.h (+1-1)
diff --git a/clang/include/clang-c/Platform.h b/clang/include/clang-c/Platform.h
index 67c1fff8ff783..8d341ddd6f8eb 100644
--- a/clang/include/clang-c/Platform.h
+++ b/clang/include/clang-c/Platform.h
@@ -22,7 +22,7 @@ LLVM_CLANG_C_EXTERN_C_BEGIN
 #ifndef CINDEX_NO_EXPORTS
   #define CINDEX_EXPORTS
 #endif
-#ifdef _WIN32
+#if defined(_WIN32) || defined(__CYGWIN__)
   #ifdef CINDEX_EXPORTS
     #ifdef _CINDEX_LIB_
       #define CINDEX_LINKAGE __declspec(dllexport)

@kikairoya
Copy link
Contributor Author

Before merge this, requires #147108

Copy link

github-actions bot commented Jul 5, 2025

⚠️ C/C++ code formatter, clang-format found issues in your code. ⚠️

You can test this locally with the following command:
git-clang-format --diff HEAD~1 HEAD --extensions h -- clang/include/clang-c/Platform.h
View the diff from clang-format here.
diff --git a/clang/include/clang-c/Platform.h b/clang/include/clang-c/Platform.h
index 8d341ddd6..1c28ccf81 100644
--- a/clang/include/clang-c/Platform.h
+++ b/clang/include/clang-c/Platform.h
@@ -23,13 +23,13 @@ LLVM_CLANG_C_EXTERN_C_BEGIN
   #define CINDEX_EXPORTS
 #endif
 #if defined(_WIN32) || defined(__CYGWIN__)
-  #ifdef CINDEX_EXPORTS
-    #ifdef _CINDEX_LIB_
-      #define CINDEX_LINKAGE __declspec(dllexport)
-    #else
-      #define CINDEX_LINKAGE __declspec(dllimport)
-    #endif
-  #endif
+#ifdef CINDEX_EXPORTS
+#ifdef _CINDEX_LIB_
+#define CINDEX_LINKAGE __declspec(dllexport)
+#else
+#define CINDEX_LINKAGE __declspec(dllimport)
+#endif
+#endif
 #elif defined(CINDEX_EXPORTS) && defined(__GNUC__)
   #define CINDEX_LINKAGE __attribute__((visibility("default")))
 #endif

@kikairoya
Copy link
Contributor Author

git clang-format makes reformat below, should it be applied?

diff --git a/clang/include/clang-c/Platform.h b/clang/include/clang-c/Platform.h
index 8d341ddd6f8e..1c28ccf81981 100644
--- a/clang/include/clang-c/Platform.h
+++ b/clang/include/clang-c/Platform.h
@@ -23,13 +23,13 @@ LLVM_CLANG_C_EXTERN_C_BEGIN
   #define CINDEX_EXPORTS
 #endif
 #if defined(_WIN32) || defined(__CYGWIN__)
-  #ifdef CINDEX_EXPORTS
-    #ifdef _CINDEX_LIB_
-      #define CINDEX_LINKAGE __declspec(dllexport)
-    #else
-      #define CINDEX_LINKAGE __declspec(dllimport)
-    #endif
-  #endif
+#ifdef CINDEX_EXPORTS
+#ifdef _CINDEX_LIB_
+#define CINDEX_LINKAGE __declspec(dllexport)
+#else
+#define CINDEX_LINKAGE __declspec(dllimport)
+#endif
+#endif
 #elif defined(CINDEX_EXPORTS) && defined(__GNUC__)
   #define CINDEX_LINKAGE __attribute__((visibility("default")))
 #endif

@mstorsjo
Copy link
Member

mstorsjo commented Jul 5, 2025

Before merge this, requires #147108

Can you elaborate on why this is needed - what happens without it - wouldn't that issue be happening already now in regular win32 builds so far?

@kikairoya
Copy link
Contributor Author

Before merge this, requires #147108

Can you elaborate on why this is needed - what happens without it - wouldn't that issue be happening already now in regular win32 builds so far?

The linker reports undefined reference to clang_install_aborting_llvm_fatal_error_handler, and cannot run testsuite.

FAILED: tools/clang/unittests/libclang/CrashTests/libclangCrashTests.exe
: && /usr/bin/g++.exe  -pipe -Wa,-mbig-obj -Werror=date-time -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wno-maybe-uninitialized -Wno-nonnull -Wno-class-memaccess -Wno-redundant-move -Wno-pessimizing-move -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wno-misleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -fno-common -Woverloaded-virtual -O2 -DNDEBUG -Wl,--enable-auto-import -Wl,--stack,16777216    -Wl,--gc-sections tools/clang/unittests/libclang/CrashTests/CMakeFiles/libclangCrashTests.dir/LibclangCrashTest.cpp.o -o tools/clang/unittests/libclang/CrashTests/libclangCrashTests.exe -Wl,--out-implib,tools/clang/unittests/libclang/CrashTests/liblibclangCrashTests.dll.a -Wl,--major-image-version,0,--minor-image-version,0  lib/libLLVMSupport.a  lib/libllvm_gtest_main.a  lib/libllvm_gtest.a  lib/libclang.dll.a  lib/libLLVMSupport.a  -lrt  -ldl  -lm  /usr/lib/libz.dll.a  /usr/lib/libzstd.dll.a  lib/libLLVMDemangle.a  -lpthread && :
/usr/lib/gcc/x86_64-pc-cygwin/15/../../../../x86_64-pc-cygwin/bin/ld: tools/clang/unittests/libclang/CrashTests/CMakeFiles/libclangCrashTests.dir/LibclangCrashTest.cpp.o:LibclangCrashTest.cpp:(.text+0x21d): undefined reference to `clang_install_aborting_llvm_fatal_error_handler'
/usr/lib/gcc/x86_64-pc-cygwin/15/../../../../x86_64-pc-cygwin/bin/ld: tools/clang/unittests/libclang/CrashTests/CMakeFiles/libclangCrashTests.dir/LibclangCrashTest.cpp.o:LibclangCrashTest.cpp:(.text+0x61f): undefined reference to `clang_install_aborting_llvm_fatal_error_handler'
/usr/lib/gcc/x86_64-pc-cygwin/15/../../../../x86_64-pc-cygwin/bin/ld: tools/clang/unittests/libclang/CrashTests/CMakeFiles/libclangCrashTests.dir/LibclangCrashTest.cpp.o:LibclangCrashTest.cpp:(.text+0x624): undefined reference to `clang_uninstall_llvm_fatal_error_handler'
collect2: エラー: ld はステータス 1 で終了しました

For regular Win32 targets, this unittest is disabled.

# FIXME: libclang unit tests are disabled on Windows due
# to failures, mostly in libclang.VirtualFileOverlay_*.
if(NOT WIN32 AND CLANG_TOOL_LIBCLANG_BUILD)
add_subdirectory(libclang)
endif()

@mstorsjo
Copy link
Member

mstorsjo commented Jul 6, 2025

Before merge this, requires #147108

Can you elaborate on why this is needed - what happens without it - wouldn't that issue be happening already now in regular win32 builds so far?

The linker reports undefined reference to clang_install_aborting_llvm_fatal_error_handler, and cannot run testsuite.

FAILED: tools/clang/unittests/libclang/CrashTests/libclangCrashTests.exe
: && /usr/bin/g++.exe  -pipe -Wa,-mbig-obj -Werror=date-time -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wno-maybe-uninitialized -Wno-nonnull -Wno-class-memaccess -Wno-redundant-move -Wno-pessimizing-move -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wno-misleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -fno-common -Woverloaded-virtual -O2 -DNDEBUG -Wl,--enable-auto-import -Wl,--stack,16777216    -Wl,--gc-sections tools/clang/unittests/libclang/CrashTests/CMakeFiles/libclangCrashTests.dir/LibclangCrashTest.cpp.o -o tools/clang/unittests/libclang/CrashTests/libclangCrashTests.exe -Wl,--out-implib,tools/clang/unittests/libclang/CrashTests/liblibclangCrashTests.dll.a -Wl,--major-image-version,0,--minor-image-version,0  lib/libLLVMSupport.a  lib/libllvm_gtest_main.a  lib/libllvm_gtest.a  lib/libclang.dll.a  lib/libLLVMSupport.a  -lrt  -ldl  -lm  /usr/lib/libz.dll.a  /usr/lib/libzstd.dll.a  lib/libLLVMDemangle.a  -lpthread && :
/usr/lib/gcc/x86_64-pc-cygwin/15/../../../../x86_64-pc-cygwin/bin/ld: tools/clang/unittests/libclang/CrashTests/CMakeFiles/libclangCrashTests.dir/LibclangCrashTest.cpp.o:LibclangCrashTest.cpp:(.text+0x21d): undefined reference to `clang_install_aborting_llvm_fatal_error_handler'
/usr/lib/gcc/x86_64-pc-cygwin/15/../../../../x86_64-pc-cygwin/bin/ld: tools/clang/unittests/libclang/CrashTests/CMakeFiles/libclangCrashTests.dir/LibclangCrashTest.cpp.o:LibclangCrashTest.cpp:(.text+0x61f): undefined reference to `clang_install_aborting_llvm_fatal_error_handler'
/usr/lib/gcc/x86_64-pc-cygwin/15/../../../../x86_64-pc-cygwin/bin/ld: tools/clang/unittests/libclang/CrashTests/CMakeFiles/libclangCrashTests.dir/LibclangCrashTest.cpp.o:LibclangCrashTest.cpp:(.text+0x624): undefined reference to `clang_uninstall_llvm_fatal_error_handler'
collect2: エラー: ld はステータス 1 で終了しました

For regular Win32 targets, this unittest is disabled.

# FIXME: libclang unit tests are disabled on Windows due
# to failures, mostly in libclang.VirtualFileOverlay_*.
if(NOT WIN32 AND CLANG_TOOL_LIBCLANG_BUILD)
add_subdirectory(libclang)
endif()

Thanks, that explains why this hasn't been noticed before!

Copy link
Member

@mstorsjo mstorsjo left a comment

Choose a reason for hiding this comment

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

LGTM, thanks.

But we should wait for #147108 to land first before merging this.

@mstorsjo mstorsjo merged commit 122afae into llvm:main Jul 7, 2025
11 of 12 checks passed
@kikairoya kikairoya deleted the cygwin-libclang-dllexport branch July 7, 2025 21:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:as-a-library libclang and C++ API clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants