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

[release/8.0] va_start/va_end compile time errors with clang 18 + libstdc++ 14 #99825

Closed
omajid opened this issue Mar 15, 2024 · 7 comments
Closed

Comments

@omajid
Copy link
Member

omajid commented Mar 15, 2024

I am trying to build runtime release/8.0 with clang 18 after these changes:

diff --git a/eng/common/native/init-compiler.sh b/eng/common/native/init-compiler.sh
index f5c1ec7eafe..2d5660642b8 100644
--- a/eng/common/native/init-compiler.sh
+++ b/eng/common/native/init-compiler.sh
@@ -63,7 +63,7 @@ if [ -z "$CLR_CC" ]; then
     # Set default versions
     if [ -z "$majorVersion" ]; then
         # note: gcc (all versions) and clang versions higher than 6 do not have minor version in file name, if it is zero.
-        if [ "$compiler" = "clang" ]; then versions="17 16 15 14 13 12 11 10 9 8 7 6.0 5.0 4.0 3.9 3.8 3.7 3.6 3.5"
+        if [ "$compiler" = "clang" ]; then versions="18 17 16 15 14 13 12 11 10 9 8 7 6.0 5.0 4.0 3.9 3.8 3.7 3.6 3.5"
         elif [ "$compiler" = "gcc" ]; then versions="13 12 11 10 9 8 7 6 5 4.9"; fi
 
         for version in $versions; do
diff --git a/eng/native/configurecompiler.cmake b/eng/native/configurecompiler.cmake
index 18381101853..0e6ee88b245 100644
--- a/eng/native/configurecompiler.cmake
+++ b/eng/native/configurecompiler.cmake
@@ -590,6 +590,9 @@ if (CLR_CMAKE_HOST_UNIX)
     # other clang 16.0 suppressions
     add_compile_options(-Wno-single-bit-bitfield-constant-conversion)
     add_compile_options(-Wno-cast-function-type-strict)
+
+    # clang 18.1 supressions
+    add_compile_options(-Wno-switch-default)
   else()
     add_compile_options(-Wno-uninitialized)
     add_compile_options(-Wno-strict-aliasing)

However, this fails with the following errors:

  /home/omajid/runtime/src/coreclr/pal/src/cruntime/filecrt.cpp:89:9: error: use of undeclared identifier 'va_start'
     89 |         va_start(ap, nFlags);
        |         ^
  /home/omajid/runtime/src/coreclr/pal/src/cruntime/filecrt.cpp:91:9: error: use of undeclared identifier 'va_end'
     91 |         va_end(ap);
        |         ^
  /home/omajid/runtime/src/coreclr/pal/src/cruntime/filecrt.cpp:126:9: error: use of undeclared identifier 'va_start'
    126 |         va_start(ap, nFlags);
        |         ^
  /home/omajid/runtime/src/coreclr/pal/src/cruntime/filecrt.cpp:128:9: error: use of undeclared identifier 'va_end'
    128 |         va_end(ap);
        |         ^
  4 errors generated.

Taking a page from pal/src/cruntime/misc.cpp and making this change to the files that show the error does not help:

diff --git a/src/coreclr/pal/src/cruntime/printfcpp.cpp b/src/coreclr/pal/src/cruntime/printfcpp.cpp
index b9c1c92b9bc..e5f715fa419 100644
--- a/src/coreclr/pal/src/cruntime/printfcpp.cpp
+++ b/src/coreclr/pal/src/cruntime/printfcpp.cpp
@@ -29,6 +29,9 @@ Revision History:
 #include "pal/cruntime.h"
 
 #include <errno.h>
+/* <stdarg.h> needs to be included after "palinternal.h" to avoid name
+   collision for va_start and va_end */
+#include <stdarg.h>
 
 SET_DEFAULT_DEBUG_CHANNEL(CRT);
 
@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label Mar 15, 2024
@omajid
Copy link
Member Author

omajid commented Mar 15, 2024

Any idea how to debug this, @janvorli ?

@janvorli
Copy link
Member

@omajid, cmake generated makefiles can be used to produce preprocessed file for any compiled source (a file that contains all the includes inlined and all defines handled). That is usually useful to figure out why some symbol is not visible at some point.
So for your case, you'd do (the stuff below assuming debug build, but it works for any)

cd artifacts/obj/coreclr/linux.x64.Debug/pal/src
make cruntime/filecrt.cpp.i

@janvorli
Copy link
Member

It will print out a relative path to the produced file

@mateusrodrigues
Copy link
Member

I did the steps described above in two different environments (clang17 and clang18):

clang17:

    ...
    if (nFlags & 0100)
    {
        __builtin_va_start(ap, nFlags);
        mode = __builtin_va_arg(ap, int);
        __builtin_va_end(ap);
    }
    ...

clang18:

    ...
    if (nFlags & 0100)
    {
        va_start(ap, nFlags);
        mode = __builtin_va_arg(ap, int);
        va_end(ap);
    }
    ...

Notice how va_arg gets handled to __builtin_va_arg, but va_start and va_end remain on clang18.

@mateusrodrigues
Copy link
Member

@omajid looks like a fix has already been commited to main and made it to 9.0: #94782

This probably needs backporting to release/8.0?

@omajid
Copy link
Member Author

omajid commented Mar 25, 2024

Thank you! I opened #100258

@omajid
Copy link
Member Author

omajid commented Apr 5, 2024

Fixed by #100258

@omajid omajid closed this as completed Apr 5, 2024
@dotnet-policy-service dotnet-policy-service bot removed the untriaged New issue has not been triaged by the area owner label Apr 5, 2024
@github-actions github-actions bot locked and limited conversation to collaborators May 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants