Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Clang][Cygwin] Disable shared libs on Cygwin by default #138119

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
May 2, 2025

Conversation

mati865
Copy link
Contributor

@mati865 mati865 commented May 1, 2025

This change follows MinGW decisions, otherwise build with GCC fail with:

FAILED: bin/msys-clang-cpp-21.0git.dll lib/libclang-cpp.dll.a
...
/usr/lib/gcc/x86_64-pc-msys/13.3.0/../../../../x86_64-pc-msys/bin/ld: error: export ordinal too large: 92250

Split out from #134494

This change follows MinGW decisions, otherwise build with GCC fail with:
```
FAILED: bin/msys-clang-cpp-21.0git.dll lib/libclang-cpp.dll.a
...
/usr/lib/gcc/x86_64-pc-msys/13.3.0/../../../../x86_64-pc-msys/bin/ld: error: export ordinal too large: 92250
```

Co-authored-by: jeremyd2019 <[email protected]>
@mstorsjo mstorsjo marked this pull request as ready for review May 1, 2025 12:35
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:as-a-library libclang and C++ API labels May 1, 2025
@llvmbot
Copy link
Member

llvmbot commented May 1, 2025

@llvm/pr-subscribers-clang

Author: Mateusz Mikuła (mati865)

Changes

This change follows MinGW decisions, otherwise build with GCC fail with:

FAILED: bin/msys-clang-cpp-21.0git.dll lib/libclang-cpp.dll.a
...
/usr/lib/gcc/x86_64-pc-msys/13.3.0/../../../../x86_64-pc-msys/bin/ld: error: export ordinal too large: 92250

Split out from #134494


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

2 Files Affected:

  • (modified) clang/tools/CMakeLists.txt (+3-2)
  • (modified) clang/tools/libclang/CMakeLists.txt (+2-1)
diff --git a/clang/tools/CMakeLists.txt b/clang/tools/CMakeLists.txt
index 9634eb12080c8..50e3d694236ac 100644
--- a/clang/tools/CMakeLists.txt
+++ b/clang/tools/CMakeLists.txt
@@ -26,9 +26,10 @@ endif()
 add_clang_subdirectory(c-index-test)
 
 add_clang_subdirectory(clang-refactor)
-# For MinGW we only enable shared library if LLVM_LINK_LLVM_DYLIB=ON.
+# For MinGW/Cygwin we only enable shared library if LLVM_LINK_LLVM_DYLIB=ON.
 # Without that option resulting library is too close to 2^16 DLL exports limit.
-if(UNIX OR (MSVC AND LLVM_BUILD_LLVM_DYLIB_VIS) OR (MINGW AND LLVM_LINK_LLVM_DYLIB))
+if((UNIX AND NOT CYGWIN) OR (MSVC AND LLVM_BUILD_LLVM_DYLIB_VIS) OR
+  ((MINGW OR CYGWIN) AND LLVM_LINK_LLVM_DYLIB))
   add_clang_subdirectory(clang-shlib)
 endif()
 
diff --git a/clang/tools/libclang/CMakeLists.txt b/clang/tools/libclang/CMakeLists.txt
index 299c14660f3d4..37a939ffcada7 100644
--- a/clang/tools/libclang/CMakeLists.txt
+++ b/clang/tools/libclang/CMakeLists.txt
@@ -106,7 +106,8 @@ if (LLVM_EXPORTED_SYMBOL_FILE)
                      DEPENDS ${LIBCLANG_VERSION_SCRIPT_FILE})
 endif()
 
-if(LLVM_ENABLE_PIC OR (WIN32 AND NOT LIBCLANG_BUILD_STATIC))
+if((NOT (WIN32 OR CYGWIN) AND LLVM_ENABLE_PIC) OR
+  ((WIN32 OR CYGWIN) AND NOT LIBCLANG_BUILD_STATIC))
   set(ENABLE_SHARED SHARED)
 endif()
 

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

@@ -106,7 +106,8 @@ if (LLVM_EXPORTED_SYMBOL_FILE)
DEPENDS ${LIBCLANG_VERSION_SCRIPT_FILE})
endif()

if(LLVM_ENABLE_PIC OR (WIN32 AND NOT LIBCLANG_BUILD_STATIC))
if((NOT (WIN32 OR CYGWIN) AND LLVM_ENABLE_PIC) OR
((WIN32 OR CYGWIN) AND NOT LIBCLANG_BUILD_STATIC))
Copy link
Member

Choose a reason for hiding this comment

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

This bit here is quite unintuitive to read, but I don't have any specific preference for any better way of doing it either...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed, that's unfortunate and has always been a problem.
LLVM_ENABLE_PIC defaults to ON on Windows, so that condition never worked unless you explicitly disabled LLVM_ENABLE_PIC as found out by @jeremyd2019.

Copy link
Contributor

Choose a reason for hiding this comment

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

this stops libclang.dll from building on (non-mingw) windows when we specify LLVM_ENABLE_PIC, can we revert that part of this change?

Copy link
Member

Choose a reason for hiding this comment

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

Right, so in order not to change the behaviour for other windows platforms, this should probably be if ((NOT CYGWIN AND LLVM_ENABLE_PIC) OR ((WIN32 OR CYGWIN) AND NOT LIBCLANG_BUILD_STATIC)), i.e. removing the WIN32 OR part from the first part of the conditional?

Copy link
Contributor

@jeremyd2019 jeremyd2019 May 2, 2025

Choose a reason for hiding this comment

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

I'm confused now, the condition before had WIN32 AND NOT LIBCLANG_BUILD_STATIC but that branch was never hit because LLVM_ENABLE_PIC was defaulted ON on Windows. What exactly is LIBCLANG_BUILD_STATIC supposed to do, if not switch from building a shared libclang to building a static one?

Oh, the docs on the option does say "in addition to a shared one"

Copy link
Contributor

Choose a reason for hiding this comment

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

As I recall, the libclang.dll did build successfully so I think that could be reverted. Perhaps I/we just misunderstood what that option was supposed to do

Copy link
Contributor

@jeremyd2019 jeremyd2019 May 2, 2025

Choose a reason for hiding this comment

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

as in,

if(LLVM_ENABLE_PIC OR ((WIN32 OR CYGWIN) AND NOT LIBCLANG_BUILD_STATIC))

Although I'm still not clear on what the WIN32 AND NOT LIBCLANG_BUILD_STATIC case is supposed to be doing, it's pretty clear that Cygwin is like WIN32 in regards to its shared/static libraries

Copy link
Contributor

Choose a reason for hiding this comment

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

sent out #138343

@mstorsjo mstorsjo merged commit 9bc20fb into llvm:main May 2, 2025
18 checks passed
@mati865 mati865 deleted the push-nmkxtzmqmnzs branch May 2, 2025 09:00
jeremyd2019 added a commit to jeremyd2019/llvm-project that referenced this pull request May 2, 2025
This change follows MinGW decisions, otherwise build with GCC fail with:
```
FAILED: bin/msys-clang-cpp-21.0git.dll lib/libclang-cpp.dll.a
...
/usr/lib/gcc/x86_64-pc-msys/13.3.0/../../../../x86_64-pc-msys/bin/ld: error: export ordinal too large: 92250
```

Co-authored-by: jeremyd2019 <[email protected]>
jeremyd2019 added a commit to jeremyd2019/llvm-project that referenced this pull request May 2, 2025
This change follows MinGW decisions, otherwise build with GCC fail with:
```
FAILED: bin/msys-clang-cpp-21.0git.dll lib/libclang-cpp.dll.a
...
/usr/lib/gcc/x86_64-pc-msys/13.3.0/../../../../x86_64-pc-msys/bin/ld: error: export ordinal too large: 92250
```

Co-authored-by: jeremyd2019 <[email protected]>
mati865 added a commit to mati865/llvm-project that referenced this pull request May 2, 2025
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
This change follows MinGW decisions, otherwise build with GCC fail with:
```
FAILED: bin/msys-clang-cpp-21.0git.dll lib/libclang-cpp.dll.a
...
/usr/lib/gcc/x86_64-pc-msys/13.3.0/../../../../x86_64-pc-msys/bin/ld: error: export ordinal too large: 92250
```

Co-authored-by: jeremyd2019 <[email protected]>
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
This change follows MinGW decisions, otherwise build with GCC fail with:
```
FAILED: bin/msys-clang-cpp-21.0git.dll lib/libclang-cpp.dll.a
...
/usr/lib/gcc/x86_64-pc-msys/13.3.0/../../../../x86_64-pc-msys/bin/ld: error: export ordinal too large: 92250
```

Co-authored-by: jeremyd2019 <[email protected]>
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
This change follows MinGW decisions, otherwise build with GCC fail with:
```
FAILED: bin/msys-clang-cpp-21.0git.dll lib/libclang-cpp.dll.a
...
/usr/lib/gcc/x86_64-pc-msys/13.3.0/../../../../x86_64-pc-msys/bin/ld: error: export ordinal too large: 92250
```

Co-authored-by: jeremyd2019 <[email protected]>
GeorgeARM pushed a commit to GeorgeARM/llvm-project that referenced this pull request May 7, 2025
This change follows MinGW decisions, otherwise build with GCC fail with:
```
FAILED: bin/msys-clang-cpp-21.0git.dll lib/libclang-cpp.dll.a
...
/usr/lib/gcc/x86_64-pc-msys/13.3.0/../../../../x86_64-pc-msys/bin/ld: error: export ordinal too large: 92250
```

Co-authored-by: jeremyd2019 <[email protected]>
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.

5 participants