Skip to content
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

Various windows fixes #181

Merged
merged 26 commits into from
Jan 20, 2024
Merged

Various windows fixes #181

merged 26 commits into from
Jan 20, 2024

Conversation

fsfod
Copy link
Contributor

@fsfod fsfod commented Jan 15, 2024

Fix some of the windows build errors, It still won't fully build with just these changes, but it gets it much closer.
I don't know much of the llvm internal API, but i did switched from some Linux specific function that were failing to build on windows with llvm API like SearchForAddressOfSymbol and real_path.

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

clang-tidy made some suggestions

@@ -1084,7 +1084,7 @@ namespace Cpp {
auto GD = GlobalDecl(VD);
std::string mangledName;
compat::maybeMangleDeclName(GD, mangledName);
auto address = dlsym(/*whole_process=*/0, mangledName.c_str());
auto address = llvm::sys::DynamicLibrary::SearchForAddressOfSymbol(mangledName.c_str());
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: 'auto address' can be declared as 'auto *address' [llvm-qualified-auto]

Suggested change
auto address = llvm::sys::DynamicLibrary::SearchForAddressOfSymbol(mangledName.c_str());
auto *address = llvm::sys::DynamicLibrary::SearchForAddressOfSymbol(mangledName.c_str());

lib/Interpreter/Paths.cpp Outdated Show resolved Hide resolved
lib/Interpreter/Paths.cpp Outdated Show resolved Hide resolved
lib/Interpreter/Paths.cpp Outdated Show resolved Hide resolved
lib/Interpreter/Paths.cpp Outdated Show resolved Hide resolved
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

clang-tidy made some suggestions

lib/Interpreter/DynamicLibraryManager.h Show resolved Hide resolved
lib/Interpreter/Paths.cpp Outdated Show resolved Hide resolved
lib/Interpreter/Paths.cpp Outdated Show resolved Hide resolved
Copy link

codecov bot commented Jan 16, 2024

Codecov Report

Attention: 13 lines in your changes are missing coverage. Please review.

Comparison is base (aa3521b) 78.68% compared to head (cc2dfc4) 78.67%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #181      +/-   ##
==========================================
- Coverage   78.68%   78.67%   -0.02%     
==========================================
  Files           8        8              
  Lines        3050     3053       +3     
==========================================
+ Hits         2400     2402       +2     
- Misses        650      651       +1     
Files Coverage Δ
include/clang/Interpreter/CppInterOp.h 100.00% <ø> (ø)
lib/Interpreter/Compatibility.h 93.63% <ø> (ø)
lib/Interpreter/DynamicLibraryManager.cpp 75.12% <100.00%> (+0.12%) ⬆️
lib/Interpreter/DynamicLibraryManager.h 92.85% <ø> (ø)
lib/Interpreter/DynamicLibraryManagerSymbol.cpp 68.81% <ø> (-0.34%) ⬇️
lib/Interpreter/CppInterOp.cpp 86.31% <50.00%> (ø)
lib/Interpreter/Paths.cpp 35.40% <80.64%> (+0.89%) ⬆️
Files Coverage Δ
include/clang/Interpreter/CppInterOp.h 100.00% <ø> (ø)
lib/Interpreter/Compatibility.h 93.63% <ø> (ø)
lib/Interpreter/DynamicLibraryManager.cpp 75.12% <100.00%> (+0.12%) ⬆️
lib/Interpreter/DynamicLibraryManager.h 92.85% <ø> (ø)
lib/Interpreter/DynamicLibraryManagerSymbol.cpp 68.81% <ø> (-0.34%) ⬇️
lib/Interpreter/CppInterOp.cpp 86.31% <50.00%> (ø)
lib/Interpreter/Paths.cpp 35.40% <80.64%> (+0.89%) ⬆️

mcbarton added a commit to mcbarton/CppInterOp that referenced this pull request Jan 17, 2024
Codebase changes to be made in compiler-research#181 to allow Windows CI to pass
@vgvassilev
Copy link
Contributor

Can you rebase this PR?

@mcbarton
Copy link
Collaborator

@fsfod In one of your future commits can you fix a mistake I made in the readme build instructions in my last PR. The following line
https://github.com/fsfod/CppInterOp/blob/50a7565a9c10deea39735ff02a2e0912e53ce874/README.md?plain=1#L82
should say

git apply -v ../patches/llvm/clang17-*.patch

In my haste I copied from the ci and forgot to change it.

@fsfod
Copy link
Contributor Author

fsfod commented Jan 17, 2024

sure

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

clang-tidy made some suggestions

lib/Interpreter/Paths.cpp Outdated Show resolved Hide resolved
@mcbarton mcbarton mentioned this pull request Jan 18, 2024
@fsfod
Copy link
Contributor Author

fsfod commented Jan 18, 2024

Its now just failing to find google test libs.

@mcbarton
Copy link
Collaborator

@fsfod I also see this error in the CI. LINK : fatal error LNK1104: cannot open file 'pthread.lib' . pthreads seem to be unix only, so this also needs to be solved.

@vgvassilev
Copy link
Contributor

Its now just failing to find google test libs.

Probably here we need to fix the library extensions:

set(_gtest_byproducts
${_gtest_byproduct_binary_dir}/lib/libgtest.a
${_gtest_byproduct_binary_dir}/lib/libgtest_main.a
${_gtest_byproduct_binary_dir}/lib/libgmock.a
${_gtest_byproduct_binary_dir}/lib/libgmock_main.a

@fsfod
Copy link
Contributor Author

fsfod commented Jan 18, 2024

Where does the lib path come from for linking thoses libs because it doesn't match that list.
Locally it fails with fatal error LNK1104: cannot open file '..\googletest-prefix\src\googletest-build\lib\\gtest.lib'

@vgvassilev
Copy link
Contributor

Where does the lib path come from for linking thoses libs because it doesn't match that list. Locally it fails with fatal error LNK1104: cannot open file '..\googletest-prefix\src\googletest-build\lib\\gtest.lib'

It is probably in \Debug|Release\lib?

@mcbarton
Copy link
Collaborator

@fsfod I also see this error in the CI. LINK : fatal error LNK1104: cannot open file 'pthread.lib' . pthreads seem to be unix only, so this also needs to be solved.

The pthread library issue appears to be here https://github.com/fsfod/CppInterOp/blob/b59af225385cda1bf1936507eea8be07e2d71240/unittests/CMakeLists.txt#L27C1-L27C79

@mcbarton
Copy link
Collaborator

mcbarton commented Jan 18, 2024

Where does the lib path come from for linking thoses libs because it doesn't match that list. Locally it fails with fatal error LNK1104: cannot open file '..\googletest-prefix\src\googletest-build\lib\\gtest.lib'

I believe the gtest library location is being set here on Windows. We are using the MSVC compiler in the CI, so I believe this is where the library path is being set. I'm not 100% certain though.

https://github.com/fsfod/CppInterOp/blob/b59af225385cda1bf1936507eea8be07e2d71240/cmake/modules/GoogleTest.cmake#L10C1-L17C74

@vgvassilev
Copy link
Contributor

Where does the lib path come from for linking thoses libs because it doesn't match that list. Locally it fails with fatal error LNK1104: cannot open file '..\googletest-prefix\src\googletest-build\lib\\gtest.lib'

It is probably in \Debug|Release\lib?

Maybe something like: ${_gtest_byproduct_binary_dir}/${CMAKE_CFG_INTDIR}/lib/

@fsfod
Copy link
Contributor Author

fsfod commented Jan 18, 2024

Where does the lib path come from for linking thoses libs because it doesn't match that list. Locally it fails with fatal error LNK1104: cannot open file '..\googletest-prefix\src\googletest-build\lib\\gtest.lib'

I believe the gtest library location is being set here on Windows. We are using the MSVC compiler in the CI, so I believe this is where the library path is being set. I'm not 100% certain though.

fsfod/CppInterOp@b59af22/cmake/modules/GoogleTest.cmake#L10C1-L17C74

All those paths for point to CppInterOp/build/Clang-Release/downloads/googletest-prefix/src/googletest-build/lib/ where the libs are for me.

@mcbarton
Copy link
Collaborator

The cling build of CppInterOp is now getting a large number of 'unresolved external symbol' errors after the last commit. Its not clear to me what may be causing it.

@mcbarton
Copy link
Collaborator

mcbarton commented Jan 18, 2024

All the gtest import paths are being set here.
https://github.com/fsfod/CppInterOp/blob/b59af225385cda1bf1936507eea8be07e2d71240/cmake/modules/GoogleTest.cmake#L81C1-L81C1

Maybe try changing in all the 4 paths
${_G_LIBRARY_PATH}
to
${_gtest_byproduct_binary_dir}

This suggestion is working under the assumption that ${CMAKE_STATIC_LIBRARY_PREFIX} = lib/

I have to admit this is all kind of guess work on my part.

@fsfod
Copy link
Contributor Author

fsfod commented Jan 18, 2024

I just figured that out, also ${CMAKE_STATIC_LIBRARY_PREFIX} is empty for windows

@fsfod
Copy link
Contributor Author

fsfod commented Jan 18, 2024

I don't get any of those linker errors locally that there failing with now. Are the tests relying on symbol visibility for shared libraries being public? because for windows it private default and class or functions need to be explicitly annotated __declspec(dllexport) or the linker has to be passed file of mangled symbol names to be exported.

@vgvassilev
Copy link
Contributor

Yes. LLVM has export_executable_symbols() but I think that’s mostly for executables.

@vgvassilev
Copy link
Contributor

How is the symbol export solved for the llvm libraries on windows?

@fsfod
Copy link
Contributor Author

fsfod commented Jan 18, 2024

I'm not really sure its fully solved for shared library builds https://discourse.llvm.org/t/supporting-llvm-build-llvm-dylib-on-windows/58891

fsfod added 23 commits January 20, 2024 08:49
Change clang::SmallVector to llvm::SmallVector and just set the smaller buffer size directly to 256 instead using platform defines
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

clang-tidy made some suggestions

lib/Interpreter/Paths.cpp Show resolved Hide resolved
lib/Interpreter/Paths.cpp Show resolved Hide resolved
lib/Interpreter/Paths.cpp Show resolved Hide resolved
lib/Interpreter/Paths.cpp Show resolved Hide resolved
lib/Interpreter/Paths.cpp Show resolved Hide resolved
lib/Interpreter/Paths.cpp Show resolved Hide resolved
lib/Interpreter/Paths.cpp Show resolved Hide resolved
@vgvassilev
Copy link
Contributor

I wonder target triple the tests default to in the windows CI build.

I don't know but we could add a -v to the interpreter arguments and will be probably print it out.

@mcbarton
Copy link
Collaborator

Probably not the best place to put this message, but sometime later today I will put in a PR to fix a few typos and mistakes in the README.md .

@vgvassilev
Copy link
Contributor

I wonder target triple the tests default to in the windows CI build.

I don't know but we could add a -v to the interpreter arguments and will be probably print it out.

Yes, let's merge this PR because it started to hit the cache limits in github and will be slow to make progress since it will start evicting caches for the builds...

@vgvassilev vgvassilev merged commit bf29fcd into compiler-research:main Jan 20, 2024
15 of 19 checks passed
@fsfod fsfod deleted the win_fixes branch February 7, 2024 01:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants