This is an archive of the discontinued LLVM Phabricator instance.

Upstream Cygwin Clang patches
Needs ReviewPublic

Authored by xu-chiheng on Jun 29 2023, 7:35 AM.

Details

Reviewers
jdoerfert
Summary

Upstream Cygwin Clang/LLVM patches from

  1. https://cygwin.com/git-cygwin-packages/
  2. https://cygwin.com/git-cygwin-packages/?p=git/cygwin-packages/clang.git;a=summary
  3. git://cygwin.com/git/cygwin-packages/clang.git
  4. https://cygwin.com/git-cygwin-packages/?p=git/cygwin-packages/llvm.git;a=summary
  5. git://cygwin.com/git/cygwin-packages/llvm.git

3 patches are applied:
7.0.1-cygwin-basic.patch
7.0.1-cygwin-driver.patch
8.0.1-cmodel-medium.patch

Note : I am not the author the patches, I just rebase the patches to revision 993a923a09ec8ea4e895b4ea2331da99cc23d1a4

The patched Clang compiler can build GCC on Cygwin, but can't build Clang itself, there are error like below, I don't know how to fix.

make[2]: * No rule to make target 'tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/Attributes.cpp.o', needed by 'bin/cygclangBasic-17git.dll'. Stop.
make[1]:
* [CMakeFiles/Makefile2:32924: tools/clang/lib/Basic/CMakeFiles/clangBasic.dir/all] Error 2
make[1]: * Waiting for unfinished jobs....
[ 33%] Built target DllOptionsTableGen
[ 33%] Built target WebAssemblyCommonTableGen
make:
* [Makefile:156: all] Error 2

cd /cygdrive/e/Note/Tool/llvm-release-build/tools/clang/lib/Basic && /cygdrive/d/cygwin64-packages/clang/bin/clang++.exe -DGTEST_HAS_RTTI=0 -DSTDC_CONSTANT_MACROS -DSTDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/cygdrive/e/Note/Tool/llvm-release-build/tools/clang/lib/Basic -I/cygdrive/e/Note/Tool/llvm/clang/lib/Basic -I/cygdrive/e/Note/Tool/llvm/clang/include -I/cygdrive/e/Note/Tool/llvm-release-build/tools/clang/include -I/cygdrive/e/Note/Tool/llvm-release-build/include -I/cygdrive/e/Note/Tool/llvm/llvm/include -O2 -march=x86-64 -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fno-common -Woverloaded-virtual -Wno-nested-anon-types -O3 -DNDEBUG -fno-exceptions -funwind-tables -fno-rtti -std=gnu++17 -MD -MT tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/Attributes.cpp.o -MF CMakeFiles/obj.clangBasic.dir/Attributes.cpp.o.d -o CMakeFiles/obj.clangBasic.dir/Attributes.cpp.o -c /cygdrive/e/Note/Tool/llvm/clang/lib/Basic/Attributes.cpp

$ ls -lha tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/
total 5.3M
drwxr-xr-x+ 1 Administrator None 0 Jun 29 18:06 .
drwxr-xr-x+ 1 Administrator None 0 Jun 29 17:35 ..
-rw-r--r--+ 1 Administrator None 0 Jun 29 17:37 Attributes.cpp-2b221e1d.o.tmp
-rw-r--r--+ 1 Administrator None 0 Jun 29 18:03 Attributes.cpp-65749625.o.tmp
-rw-r--r--+ 1 Administrator None 0 Jun 29 18:06 Attributes.cpp-7e1889df.o.tmp
-rw-r--r--+ 1 Administrator None 0 Jun 29 18:00 Attributes.cpp-fd50fae7.o.tmp
-rw-r--r--+ 1 Administrator None 153K Jun 29 17:35 build.make
-rw-r--r--+ 1 Administrator None 135K Jun 29 17:37 Builtins.cpp.o
-rw-r--r--+ 1 Administrator None 19K Jun 29 17:37 Builtins.cpp.o.d
-rw-r--r--+ 1 Administrator None 1.1K Jun 29 17:37 CharInfo.cpp.o
-rw-r--r--+ 1 Administrator None 12K Jun 29 17:37 CharInfo.cpp.o.d
-rw-r--r--+ 1 Administrator None 559 Jun 29 17:37 CLWarnings.cpp.o
-rw-r--r--+ 1 Administrator None 2.4K Jun 29 17:37 CLWarnings.cpp.o.d

Diff Detail

Event Timeline

xu-chiheng created this revision.Jun 29 2023, 7:35 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 29 2023, 7:35 AM
xu-chiheng requested review of this revision.Jun 29 2023, 7:35 AM
Herald added a project: Restricted Project. · View Herald Transcript

This really needs to be submitted as three separate patches: one for for the clang/lib/Basic changes, one for the X86TargetMachine changes, and one for the clang driver. And the changes need to update the corresponding regression tests (in clang/test/ and llvm/test/) to verify for cygwin-specific behavior. (Let me know if you can't find the relevant regression tests.)

there are error like below, I don't know how to fix.

Is clang crashing? Usually when clang crashes it prints some indication of that to stderr, but I guess the crash handler might be broken on cygwin. Have you tried attaching a debugger?

On Fri, Jun 30, 2023 at 1:53 AM Eli Friedman via Phabricator
<reviews@reviews.llvm.org> wrote:

This really needs to be submitted as three separate patches: one for for the clang/lib/Basic changes, one for the X86TargetMachine changes, and one for the clang driver. And the changes need to update the corresponding regression tests (in clang/test/ and llvm/test/) to verify for cygwin-specific behavior. (Let me know if you can't find the relevant regression tests.)

It is easy to split to 3 patches, the code is simple. The patches were
written by a Cygwin Clang maintainer. Setting up a testing environment
on Cygwin and Windows in general is not simple, I suspect that it has
never been done yet. I have used the patched Clang to build Cross
GCC on Cygwin successfully. It builds GMP, MPFR, MPC, Binutils, GCC
correctly. and the then built target libgcc is also working. But
using the patched Clang to build Clang itself, choke at
clang/lib/Basic/Attributes.cpp, that file includes tablegened files,
I don't know very much about tablegened files.

there are error like below, I don't know how to fix.

Is clang crashing? Usually when clang crashes it prints some indication of that to stderr, but I guess the crash handler might be broken on cygwin. Have you tried attaching a debugger?

It does not crash, it just produce no .o file from .cpp file, leaving
several temp files:

-rw-r--r--+ 1 Administrator None 0 Jun 29 17:37 Attributes.cpp-2b221e1d.o.tmp
-rw-r--r--+ 1 Administrator None 0 Jun 29 18:03 Attributes.cpp-65749625.o.tmp
-rw-r--r--+ 1 Administrator None 0 Jun 29 18:06 Attributes.cpp-7e1889df.o.tmp
-rw-r--r--+ 1 Administrator None 0 Jun 29 18:00 Attributes.cpp-fd50fae7.o.tmp

It does not crash

How do you know? (Just because there isn't any output, doesn't mean it isn't crashing.)

As Eli said, we need some tests. Also see https://maskray.me/blog/2021-08-08-toolchain-testing#i-dont-know-whether-a-test-is-needed
For other contributors who may improve or refactor the code, without the code they can't know whether their changes will break your functionality.

"I don't know where to add a test" may be relevant. If you don't know where to add a test, comment out some code and run ninja check-llvm check-clang to identify test locations.