Skip to content

Update our AZLinux 3.0 .NET 9 images to build a custom standard library toolchain #1025

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 18 commits into from
May 6, 2024

Conversation

jkoritzinsky
Copy link
Member

Update our docker images to build a toolchain with a static libc++ that uses the target-provided libstdc++ for the C++ Itanium ABI.

This scenario has some limitations (we're limited to API features that don't use any ABI features exposed since 2016), but it works fine for our C++11 code in dotnet/runtime.

The sanitizer instrumentation in libc++ isn't compatible with this old of a libstdc++ though, so this PR provides a separate image for that scenario. That image provides a statically linked libc++ that includes libc++abi. Additionally, it instruments libc++ and libc++abi directly with ASAN so our ASAN testing can have a fully instrumented toolchain.

This isn't required for ASAN, but is required for other sanitizers we may consider adding validation with in the future.

@jkoritzinsky jkoritzinsky requested a review from a team as a code owner April 26, 2024 18:40
@jkoritzinsky jkoritzinsky requested a review from sbomer April 26, 2024 18:40
@ghost ghost added the untriaged label Apr 26, 2024
Copy link
Member

@sbomer sbomer left a comment

Choose a reason for hiding this comment

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

Looking good! Some questions mostly for my own understanding.

# Don't search for tools in the sysroot as we're cross-compiling
-DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM="NEVER" \
-DLLVM_USE_LINKER=lld \
# We build libcxxabi here to get the cxxabi.h header file installed in libc++'s standard include directory.
Copy link
Member

Choose a reason for hiding this comment

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

Why can't we use the cxxabi.h that comes with libstdc++? Is this for the libc++ build, or is it installing headers to be used when building dotnet/runtime with libc++?

Copy link
Member Author

Choose a reason for hiding this comment

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

We can't use the one from libstdc++ as the include directory it is in is also the directory where libstdc++ defines the standard headers.

We need this for the build of createdump, which uses __cxa_demangle to demangle symbol names.

Alternatively, we could copy the cxxabi.h file from the libstdc++ location in the rootfs into the libc++ location.

Or we could have dotnet/runtime define a header that defines the required function prototypes (instead of using the header from the ABI library).

Copy link
Member

Choose a reason for hiding this comment

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

Alternatively, we could copy the cxxabi.h file from the libstdc++ location in the rootfs into the libc++ location.

This option makes most sense to me. I think using the headers that are installed with the library we will link against is the surest way to make sure they match - but I think you have the best context to make the decision here, so I'll leave it up to you.

@@ -70,6 +70,7 @@ RUN mkdir llvm-project.src && \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_C_COMPILER=clang \
-DCMAKE_CXX_COMPILER=clang++ \
-DCLANG_RESOURCE_DIR="../lib/clang/cross" \
Copy link
Member

Choose a reason for hiding this comment

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

Will this put any non-cross-compilation resources into that directory? With the current images I see:

# clang -print-resource-dir
/usr/local/lib/clang/18
# ls /usr/local/lib/clang/18
include lib

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, this will put all assets into the cross folder (and Clang will only look in that folder, not one with the major version in the path).

Copy link
Member

Choose a reason for hiding this comment

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

In that case, as a minor nit I wouldn't name it cross since it has all of the resources (including non-cross compilations).

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll rename it to resources then (or figure out a way to get the major version of clang out of the command line).

I'm trying to reduce the number of places where we need to specify (and update later) the version of LLVM/Clang that we're building.

@sbomer
Copy link
Member

sbomer commented Apr 29, 2024

Does building libc++ also make it the default for clang on these images? Or does the runtime build need to set some flags to build against libc++?

@jkoritzinsky
Copy link
Member Author

This does make libc++ the default. We'll have to make some changes to the dotnet/runtime build to utilize these new features in the images (by default they'll use the libstdc++ that they've been using).

@jkoritzinsky
Copy link
Member Author

Waiting to merge until usage UX in dotnet/runtime#101773 is agreed upon.

@jkoritzinsky
Copy link
Member Author

Usage UX has been defined, I'll merge this in and (once the new images are built) update the PR in dotnet/runtime with the sanitizer fixes.

@jkoritzinsky jkoritzinsky merged commit 591ee26 into dotnet:main May 6, 2024
19 checks passed
@jkoritzinsky jkoritzinsky deleted the libc++-static branch May 6, 2024 17:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants