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

Need the "compiler-rt" runtime for address sanitizer #3

Closed
cbuttner opened this issue Jul 7, 2024 · 7 comments
Closed

Need the "compiler-rt" runtime for address sanitizer #3

cbuttner opened this issue Jul 7, 2024 · 7 comments

Comments

@cbuttner
Copy link
Contributor

cbuttner commented Jul 7, 2024

Related to c3lang/c3c#1222

Specifically we need clang_rt.asan-x86_64.lib for address sanitizer support on windows. This library needs to be deployed next to c3c.exe so it can be linked against when --sanitize=address is enabled.

Here's the info on how to build:
https://clang.llvm.org/docs/AddressSanitizer.html#how-to-build

@cbuttner
Copy link
Contributor Author

cbuttner commented Jul 9, 2024

Looks like on Windows you have to build compiler-rt separately, after the LLVM build has finished.
So go into <root>/compiler-rt, mkdir build etc.
Configure with

-G <...>
-Thost=<...>
-DCMAKE_INSTALL_PREFIX=<...>
-DCMAKE_MSVC_RUNTIME_LIBRARY=<...>
-DCMAKE_MT=<...>
<whatever other general flags are needed...>
-DLLVM_CMAKE_DIR=<LLVM install path>

Where the LLVM install path is what is currently packaged up (contains bin, include, lib and share)

Then build and install like LLVM
cmake --build .
cmake --build . --target install (this will install into <install prefix>/lib/windows)

@lerno
Copy link
Contributor

lerno commented Jul 9, 2024

All we need is the library, so presumably a second build doing that then.

@cbuttner
Copy link
Contributor Author

I think I figured out a better way, PR coming soon.

@cbuttner
Copy link
Contributor Author

#4
I tested this, and it should build what is needed.

@cbuttner
Copy link
Contributor Author

@lerno No need to build clang!

Go into <root>/runtimes and build with the following flags

set COMPILER_RT_CMAKE_CONFIGURE_FLAGS= ^
	-G "%CMAKE_GENERATOR%%CMAKE_GENERATOR_SUFFIX%" ^
	-Thost=x64 ^
	-DCMAKE_INSTALL_PREFIX=%LLVM_RELEASE_DIR%/lib/clang/18 ^
	-DCMAKE_MSVC_RUNTIME_LIBRARY=%CMAKE_CRT% ^
	-DCMAKE_MT=mt ^
	-DCMAKE_C_COMPILER_TARGET="x86_64-pc-windows-msvc" ^
	-DLLVM_ENABLE_RUNTIMES=compiler-rt ^
	-DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON ^
	-DCOMPILER_RT_BUILD_BUILTINS=OFF

This part is also the same

cmake -B . %COMPILER_RT_CMAKE_CONFIGURE_FLAGS%
cmake --build . %CMAKE_BUILD_FLAGS%
cmake --build . --target install %CMAKE_BUILD_FLAGS%

Confirmed this actually works quite well, including the install step.

@lerno
Copy link
Contributor

lerno commented Jul 16, 2024

Can you do a pull request for a new setup?

@cbuttner
Copy link
Contributor Author

#6

@cbuttner cbuttner closed this as completed Aug 3, 2024
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

No branches or pull requests

2 participants