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

Unable to build v29.3 with clang-cl #19975

Open
Neumann-A opened this issue Jan 13, 2025 · 4 comments
Open

Unable to build v29.3 with clang-cl #19975

Neumann-A opened this issue Jan 13, 2025 · 4 comments
Assignees

Comments

@Neumann-A
Copy link
Contributor

What version of protobuf and what language are you using?
Version: v29.3
Language: C++

What operating system (Linux, Windows, ...) and version?
Windows 11

What runtime / compiler are you using (e.g., python version or gcc version)
clang-cl 19.1.6

What did you do?
Setup toolchain with clang-cl
Build protobuf (via vcpkg)

What did you expect to see
Successful build

What did you see instead?

[10/243] D:\vcpkg_folders\no_msvc\installed\x64-win-llvm\compiler-llvm\bin\clang-cl.exe   -TP -DABSL_CONSUME_DLL -DGOOGLE_PROTOBUF_CMAKE_BUILD -DLIBPROTOBUF_EXPORTS -DPROTOBUF_USE_DLLS -Dlibprotobuf_EXPORTS -ID:\vcpkg_folders\no_msvc\buildtrees\protobuf\x64-win-llvm-dbg -ID:\vcpkg_folders\no_msvc\buildtrees\protobuf\src\v5.29.3-a9486c2d3e.clean -ID:\vcpkg_folders\no_msvc\buildtrees\protobuf\x64-win-llvm-dbg\src -ID:\vcpkg_folders\no_msvc\buildtrees\protobuf\src\v5.29.3-a9486c2d3e.clean\src -imsvcD:\vcpkg_folders\no_msvc\installed\x64-win-llvm\VS\VC\Tools\MSVC\14.42.34433\include -imsvcD:\vcpkg_folders\no_msvc\installed\x64-win-llvm\VS\VC\Tools\MSVC\14.42.34433\ATLMFC\include -imsvcD:\vcpkg_folders\no_msvc\installed\x64-win-llvm\VS\VC\Auxiliary\VS\include -imsvc"D:\vcpkg_folders\no_msvc\installed\x64-win-llvm\WinSDK\Windows Kits\10\include\10.0.26100.0\ucrt" -imsvc"D:\vcpkg_folders\no_msvc\installed\x64-win-llvm\WinSDK\Windows Kits\10\include\10.0.26100.0\um" -imsvc"D:\vcpkg_folders\no_msvc\installed\x64-win-llvm\WinSDK\Windows Kits\10\include\10.0.26100.0\shared" -imsvc"D:\vcpkg_folders\no_msvc\installed\x64-win-llvm\WinSDK\Windows Kits\10\include\10.0.26100.0\winrt" -imsvc"D:\vcpkg_folders\no_msvc\installed\x64-win-llvm\WinSDK\Windows Kits\10\include\10.0.26100.0\cppwinrt" -imsvc"D:\vcpkg_folders\no_msvc\installed\x64-win-llvm\WinSDK\Windows Kits\NETFXSDK\4.8.1\include\um" -imsvcD:\vcpkg_folders\no_msvc\installed\x64-win-llvm\include /nologo /DWIN32 /D_WINDOWS -Wno-implicit-function-declaration /utf-8 -msse4.2 -m64 /GR /EHsc  /D_DEBUG /MDd /Z7 /Ob0 /Od /RTC1  -MDd /MP /utf-8 /wd4065 /wd4146 /wd4244 /wd4251 /wd4267 /wd4305 /wd4307 /wd4309 /wd4334 /wd4355 /wd4506 /wd4800 /wd4996 /bigobj /showIncludes /FoCMakeFiles\libprotobuf.dir\src\google\protobuf\dynamic_message.cc.obj /FdCMakeFiles\libprotobuf.dir\ -c -- D:\vcpkg_folders\no_msvc\buildtrees\protobuf\src\v5.29.3-a9486c2d3e.clean\src\google\protobuf\dynamic_message.cc
FAILED: CMakeFiles/libprotobuf.dir/src/google/protobuf/dynamic_message.cc.obj 
D:\vcpkg_folders\no_msvc\installed\x64-win-llvm\compiler-llvm\bin\clang-cl.exe   -TP -DABSL_CONSUME_DLL -DGOOGLE_PROTOBUF_CMAKE_BUILD -DLIBPROTOBUF_EXPORTS -DPROTOBUF_USE_DLLS -Dlibprotobuf_EXPORTS -ID:\vcpkg_folders\no_msvc\buildtrees\protobuf\x64-win-llvm-dbg -ID:\vcpkg_folders\no_msvc\buildtrees\protobuf\src\v5.29.3-a9486c2d3e.clean -ID:\vcpkg_folders\no_msvc\buildtrees\protobuf\x64-win-llvm-dbg\src -ID:\vcpkg_folders\no_msvc\buildtrees\protobuf\src\v5.29.3-a9486c2d3e.clean\src -imsvcD:\vcpkg_folders\no_msvc\installed\x64-win-llvm\VS\VC\Tools\MSVC\14.42.34433\include -imsvcD:\vcpkg_folders\no_msvc\installed\x64-win-llvm\VS\VC\Tools\MSVC\14.42.34433\ATLMFC\include -imsvcD:\vcpkg_folders\no_msvc\installed\x64-win-llvm\VS\VC\Auxiliary\VS\include -imsvc"D:\vcpkg_folders\no_msvc\installed\x64-win-llvm\WinSDK\Windows Kits\10\include\10.0.26100.0\ucrt" -imsvc"D:\vcpkg_folders\no_msvc\installed\x64-win-llvm\WinSDK\Windows Kits\10\include\10.0.26100.0\um" -imsvc"D:\vcpkg_folders\no_msvc\installed\x64-win-llvm\WinSDK\Windows Kits\10\include\10.0.26100.0\shared" -imsvc"D:\vcpkg_folders\no_msvc\installed\x64-win-llvm\WinSDK\Windows Kits\10\include\10.0.26100.0\winrt" -imsvc"D:\vcpkg_folders\no_msvc\installed\x64-win-llvm\WinSDK\Windows Kits\10\include\10.0.26100.0\cppwinrt" -imsvc"D:\vcpkg_folders\no_msvc\installed\x64-win-llvm\WinSDK\Windows Kits\NETFXSDK\4.8.1\include\um" -imsvcD:\vcpkg_folders\no_msvc\installed\x64-win-llvm\include /nologo /DWIN32 /D_WINDOWS -Wno-implicit-function-declaration /utf-8 -msse4.2 -m64 /GR /EHsc  /D_DEBUG /MDd /Z7 /Ob0 /Od /RTC1  -MDd /MP /utf-8 /wd4065 /wd4146 /wd4244 /wd4251 /wd4267 /wd4305 /wd4307 /wd4309 /wd4334 /wd4355 /wd4506 /wd4800 /wd4996 /bigobj /showIncludes /FoCMakeFiles\libprotobuf.dir\src\google\protobuf\dynamic_message.cc.obj /FdCMakeFiles\libprotobuf.dir\ -c -- D:\vcpkg_folders\no_msvc\buildtrees\protobuf\src\v5.29.3-a9486c2d3e.clean\src\google\protobuf\dynamic_message.cc
clang-cl: warning: argument unused during compilation: '/MP' [-Wunused-command-line-argument]
In file included from D:\vcpkg_folders\no_msvc\buildtrees\protobuf\src\v5.29.3-a9486c2d3e.clean\src\google\protobuf\dynamic_message.cc:42:
In file included from D:\vcpkg_folders\no_msvc\buildtrees\protobuf\src\v5.29.3-a9486c2d3e.clean\src\google/protobuf/dynamic_message.h:28:
In file included from D:\vcpkg_folders\no_msvc\buildtrees\protobuf\src\v5.29.3-a9486c2d3e.clean\src\google/protobuf/message.h:110:
D:\vcpkg_folders\no_msvc\buildtrees\protobuf\src\v5.29.3-a9486c2d3e.clean\src\google/protobuf/map.h(1324,50): error: invalid application of 'alignof' to an incomplete type 'mapped_type' (aka 'google::protobuf::MapValueRef')
 1324 |     static_assert(alignof(internal::NodeBase) >= alignof(mapped_type),
      |                                                  ^~~~~~~~~~~~~~~~~~~~
D:\vcpkg_folders\no_msvc\buildtrees\protobuf\src\v5.29.3-a9486c2d3e.clean\src\google/protobuf/map.h(1262,37): note: in instantiation of member function 'google::protobuf::Map<google::protobuf::MapKey, google::protobuf::MapValueRef>::StaticValidityCheck' requested here
 1262 |   constexpr Map() : Base(nullptr) { StaticValidityCheck(); }
      |                                     ^
D:\vcpkg_folders\no_msvc\buildtrees\protobuf\src\v5.29.3-a9486c2d3e.clean\src\google/protobuf/map_field.h(566,31): note: in instantiation of member function 'google::protobuf::Map<google::protobuf::MapKey, google::protobuf::MapValueRef>::Map' requested here
  566 |       : MapFieldBase(vtable), map_() {
      |                               ^
D:\vcpkg_folders\no_msvc\buildtrees\protobuf\src\v5.29.3-a9486c2d3e.clean\src\google/protobuf/map_field.h(563,7): note: in instantiation of member function 'google::protobuf::internal::TypeDefinedMapFieldBase<google::protobuf::MapKey, google::protobuf::MapValueRef>::TypeDefinedMapFieldBase' requested here
  563 | class TypeDefinedMapFieldBase : public MapFieldBase {
      |       ^
D:\vcpkg_folders\no_msvc\buildtrees\protobuf\src\v5.29.3-a9486c2d3e.clean\src\google/protobuf/map_field.h(695,7): note: due to 'TypeDefinedMapFieldBase<google::protobuf::MapKey, google::protobuf::MapValueRef>' being dllexported
  695 | class PROTOBUF_EXPORT DynamicMapField final
      |       ^
D:\vcpkg_folders\no_msvc\buildtrees\protobuf\src\v5.29.3-a9486c2d3e.clean\src\google/protobuf/port_def.inc(326,38): note: expanded from macro 'PROTOBUF_EXPORT'
  326 | #  define PROTOBUF_EXPORT __declspec(dllexport)
      |                                      ^
D:\vcpkg_folders\no_msvc\buildtrees\protobuf\src\v5.29.3-a9486c2d3e.clean\src\google/protobuf/generated_message_reflection.h(40,7): note: forward declaration of 'google::protobuf::MapValueRef'
   40 | class MapValueRef;
      |       ^
1 error generated.

Anything else we should know about your project / environment
One solution:

  • remove PROTOBUF_EXPORT from DynamicMapField since it lives in internal namespace any way and should probably not exported

next error after that is:

D:\vcpkg_folders\no_msvc\buildtrees\protobuf\src\v5.29.3-a9486c2d3e\src\google\protobuf\compiler\java\java_features.pb.cc(208,65): error: variable does not have a constant initializer
  208 | const ::google::protobuf::internal::ClassDataFull JavaFeatures::_class_data_ = {
      |                                                                 ^              ~
  209 |     ::google::protobuf::internal::ClassData{
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  210 |         &_JavaFeatures_default_instance_._instance,
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  211 |         &_table_.header,
      |         ~~~~~~~~~~~~~~~~
  212 |         nullptr,  // OnDemandRegisterArenaDtor
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  213 |         nullptr,  // IsInitialized
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~
  214 |         &JavaFeatures::MergeImpl,
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~
  215 |         ::google::protobuf::Message::GetNewImpl<JavaFeatures>(),
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  216 | #if defined(PROTOBUF_CUSTOM_VTABLE)
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  217 |         &JavaFeatures::SharedDtor,
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~
  218 |         ::google::protobuf::Message::GetClearImpl<JavaFeatures>(), &JavaFeatures::ByteSizeLong,
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  219 |             &JavaFeatures::_InternalSerialize,
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  220 | #endif  // PROTOBUF_CUSTOM_VTABLE
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  221 |         PROTOBUF_FIELD_OFFSET(JavaFeatures, _impl_._cached_size_),
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  222 |         false,
      |         ~~~~~~
  223 |     },
      |     ~~

Removing && !defined(__clang__) from

#if defined(_MSC_VER) && !defined(__clang__)

fixes the build

@Neumann-A Neumann-A added the untriaged auto added to all issues by default when created. label Jan 13, 2025
@esrauchg
Copy link

Thanks for the report! Unfortunately clang-cl is best effort support (not part of the official Google C++ support matrix), but we do intend for this to work.

I believe the first issue has already been corrected at tip of main.

The second issue looks more odd, and the proposed fix is unlikely to be the right one (it is explicitly commented that its for a case exactly like this to intentionally fall back to the clang path instead of the msvc one). Can you paste more of the error message to see what the right fix might be?

@Neumann-A
Copy link
Contributor Author

I believe the first issue has already been corrected at tip of main.

Yes it has.

These are the errors about constinit with current main:

[128/243] D:\vcpkg_folders\no_msvc\installed\x64-win-llvm\compiler-llvm\bin\clang-cl.exe   -TP -DABSL_CONSUME_DLL -DLIBPROTOC_EXPORTS -DPROTOBUF_USE_DLLS -Dlibprotoc_EXPORTS -ID:\vcpkg_folders\no_msvc\buildtrees\protobuf\x64-win-llvm-dbg -ID:\vcpkg_folders\no_msvc\buildtrees\protobuf\src\head\385c6b8262-c125545ad7 -ID:\vcpkg_folders\no_msvc\buildtrees\protobuf\x64-win-llvm-dbg\src -ID:\vcpkg_folders\no_msvc\buildtrees\protobuf\src\head\385c6b8262-c125545ad7\src -imsvcD:\vcpkg_folders\no_msvc\installed\x64-win-llvm\VS\VC\Tools\MSVC\14.42.34433\include -imsvcD:\vcpkg_folders\no_msvc\installed\x64-win-llvm\VS\VC\Tools\MSVC\14.42.34433\ATLMFC\include -imsvcD:\vcpkg_folders\no_msvc\installed\x64-win-llvm\VS\VC\Auxiliary\VS\include -imsvc"D:\vcpkg_folders\no_msvc\installed\x64-win-llvm\WinSDK\Windows Kits\10\include\10.0.26100.0\ucrt" -imsvc"D:\vcpkg_folders\no_msvc\installed\x64-win-llvm\WinSDK\Windows Kits\10\include\10.0.26100.0\um" -imsvc"D:\vcpkg_folders\no_msvc\installed\x64-win-llvm\WinSDK\Windows Kits\10\include\10.0.26100.0\shared" -imsvc"D:\vcpkg_folders\no_msvc\installed\x64-win-llvm\WinSDK\Windows Kits\10\include\10.0.26100.0\winrt" -imsvc"D:\vcpkg_folders\no_msvc\installed\x64-win-llvm\WinSDK\Windows Kits\10\include\10.0.26100.0\cppwinrt" -imsvc"D:\vcpkg_folders\no_msvc\installed\x64-win-llvm\WinSDK\Windows Kits\NETFXSDK\4.8.1\include\um" -imsvcD:\vcpkg_folders\no_msvc\installed\x64-win-llvm\include /nologo /DWIN32 /D_WINDOWS -Wno-implicit-function-declaration /utf-8 -msse4.2 -m64 -std:c++17 /GR /EHsc  /D_DEBUG /MDd /Z7 /Ob0 /Od /RTC1  -MDd /MP /utf-8 /wd4065 /wd4146 /wd4244 /wd4251 /wd4267 /wd4305 /wd4307 /wd4309 /wd4334 /wd4355 /wd4506 /wd4800 /wd4996 /bigobj /showIncludes /FoCMakeFiles\libprotoc.dir\src\google\protobuf\compiler\java\java_features.pb.cc.obj /FdCMakeFiles\libprotoc.dir\ -c -- D:\vcpkg_folders\no_msvc\buildtrees\protobuf\src\head\385c6b8262-c125545ad7\src\google\protobuf\compiler\java\java_features.pb.cc
FAILED: CMakeFiles/libprotoc.dir/src/google/protobuf/compiler/java/java_features.pb.cc.obj 
D:\vcpkg_folders\no_msvc\installed\x64-win-llvm\compiler-llvm\bin\clang-cl.exe   -TP -DABSL_CONSUME_DLL -DLIBPROTOC_EXPORTS -DPROTOBUF_USE_DLLS -Dlibprotoc_EXPORTS -ID:\vcpkg_folders\no_msvc\buildtrees\protobuf\x64-win-llvm-dbg -ID:\vcpkg_folders\no_msvc\buildtrees\protobuf\src\head\385c6b8262-c125545ad7 -ID:\vcpkg_folders\no_msvc\buildtrees\protobuf\x64-win-llvm-dbg\src -ID:\vcpkg_folders\no_msvc\buildtrees\protobuf\src\head\385c6b8262-c125545ad7\src -imsvcD:\vcpkg_folders\no_msvc\installed\x64-win-llvm\VS\VC\Tools\MSVC\14.42.34433\include -imsvcD:\vcpkg_folders\no_msvc\installed\x64-win-llvm\VS\VC\Tools\MSVC\14.42.34433\ATLMFC\include -imsvcD:\vcpkg_folders\no_msvc\installed\x64-win-llvm\VS\VC\Auxiliary\VS\include -imsvc"D:\vcpkg_folders\no_msvc\installed\x64-win-llvm\WinSDK\Windows Kits\10\include\10.0.26100.0\ucrt" -imsvc"D:\vcpkg_folders\no_msvc\installed\x64-win-llvm\WinSDK\Windows Kits\10\include\10.0.26100.0\um" -imsvc"D:\vcpkg_folders\no_msvc\installed\x64-win-llvm\WinSDK\Windows Kits\10\include\10.0.26100.0\shared" -imsvc"D:\vcpkg_folders\no_msvc\installed\x64-win-llvm\WinSDK\Windows Kits\10\include\10.0.26100.0\winrt" -imsvc"D:\vcpkg_folders\no_msvc\installed\x64-win-llvm\WinSDK\Windows Kits\10\include\10.0.26100.0\cppwinrt" -imsvc"D:\vcpkg_folders\no_msvc\installed\x64-win-llvm\WinSDK\Windows Kits\NETFXSDK\4.8.1\include\um" -imsvcD:\vcpkg_folders\no_msvc\installed\x64-win-llvm\include /nologo /DWIN32 /D_WINDOWS -Wno-implicit-function-declaration /utf-8 -msse4.2 -m64 -std:c++17 /GR /EHsc  /D_DEBUG /MDd /Z7 /Ob0 /Od /RTC1  -MDd /MP /utf-8 /wd4065 /wd4146 /wd4244 /wd4251 /wd4267 /wd4305 /wd4307 /wd4309 /wd4334 /wd4355 /wd4506 /wd4800 /wd4996 /bigobj /showIncludes /FoCMakeFiles\libprotoc.dir\src\google\protobuf\compiler\java\java_features.pb.cc.obj /FdCMakeFiles\libprotoc.dir\ -c -- D:\vcpkg_folders\no_msvc\buildtrees\protobuf\src\head\385c6b8262-c125545ad7\src\google\protobuf\compiler\java\java_features.pb.cc
clang-cl: warning: argument unused during compilation: '/MP' [-Wunused-command-line-argument]
D:\vcpkg_folders\no_msvc\buildtrees\protobuf\src\head\385c6b8262-c125545ad7\src\google\protobuf\compiler\java\java_features.pb.cc(229,9): error: variable does not have a constant initializer
  229 |         JavaFeatures_class_data_ =
      |         ^
  230 |             JavaFeatures::InternalGenerateClassData_();
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
D:\vcpkg_folders\no_msvc\buildtrees\protobuf\src\head\385c6b8262-c125545ad7\src\google\protobuf\compiler\java\java_features.pb.cc(227,1): note: required by 'require_constant_initialization' attribute here
  227 | PROTOBUF_CONSTINIT PROTOC_EXPORT
      | ^~~~~~~~~~~~~~~~~~
D:\vcpkg_folders\no_msvc\buildtrees\protobuf\src\head\385c6b8262-c125545ad7\src\google/protobuf/port_def.inc(441,32): note: expanded from macro 'PROTOBUF_CONSTINIT'
  441 | #  define PROTOBUF_CONSTINIT [[clang::require_constant_initialization]]
      |                                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
D:\vcpkg_folders\no_msvc\buildtrees\protobuf\src\head\385c6b8262-c125545ad7\src\google\protobuf\compiler\java\java_features.pb.cc(258,51): warning: offset of on non-standard-layout type 'JavaFeatures' [-Winvalid-offsetof]
  258 |     {::_pbi::TcParser::SingularVarintNoZag1<bool, offsetof(JavaFeatures, _impl_.use_old_outer_classname_default_), 2>(),
      |                                                   ^                      ~~~~~~
D:\vcpkg_folders\no_msvc\installed\x64-win-llvm\compiler-llvm\lib\clang\19\include\__stddef_offsetof.h(16,24): note: expanded from macro 'offsetof'
   16 | #define offsetof(t, d) __builtin_offsetof(t, d)
      |                        ^                     ~
D:\vcpkg_folders\no_msvc\buildtrees\protobuf\src\head\385c6b8262-c125545ad7\src\google\protobuf\compiler\java\java_features.pb.cc(261,51): warning: offset of on non-standard-layout type 'JavaFeatures' [-Winvalid-offsetof]
  261 |     {::_pbi::TcParser::SingularVarintNoZag1<bool, offsetof(JavaFeatures, _impl_.legacy_closed_enum_), 1>(),
      |                                                   ^                      ~~~~~~
D:\vcpkg_folders\no_msvc\installed\x64-win-llvm\compiler-llvm\lib\clang\19\include\__stddef_offsetof.h(16,24): note: expanded from macro 'offsetof'
   16 | #define offsetof(t, d) __builtin_offsetof(t, d)
      |                        ^                     ~
D:\vcpkg_folders\no_msvc\buildtrees\protobuf\src\head\385c6b8262-c125545ad7\src\google\protobuf\compiler\java\java_features.pb.cc(239,15): error: variable does not have a constant initializer
  239 | JavaFeatures::_table_ = {
      |               ^         ~
  240 |   {
      |   ~
  241 |     PROTOBUF_FIELD_OFFSET(JavaFeatures, _impl_._has_bits_),
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  242 |     0, // no _extensions_
      |     ~~~~~~~~~~~~~~~~~~~~~
  243 |     4, 24,  // max_field_number, fast_idx_mask
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  244 |     offsetof(decltype(_table_), field_lookup_table),
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  245 |     4294967284,  // skipmap
      |     ~~~~~~~~~~~~~~~~~~~~~~~
  246 |     offsetof(decltype(_table_), field_entries),
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  247 |     3,  // num_field_entries
      |     ~~~~~~~~~~~~~~~~~~~~~~~~
  248 |     1,  // num_aux_entries
      |     ~~~~~~~~~~~~~~~~~~~~~~
  249 |     offsetof(decltype(_table_), aux_entries),
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  250 |     JavaFeatures_class_data_.base(),
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  251 |     nullptr,  // post_loop_handler
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  252 |     ::_pbi::TcParser::GenericFallback,  // fallback
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  253 |     #ifdef PROTOBUF_PREFETCH_PARSE_TABLE
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  254 |     ::_pbi::TcParser::GetTable<::pb::JavaFeatures>(),  // to_prefetch
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
D:\vcpkg_folders\no_msvc\buildtrees\protobuf\src\head\385c6b8262-c125545ad7\src\google\protobuf\compiler\java\java_features.pb.cc(237,1): note: required by 'require_constant_initialization' attribute here
  237 | PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1
      | ^~~~~~~~~~~~~~~~~~
D:\vcpkg_folders\no_msvc\buildtrees\protobuf\src\head\385c6b8262-c125545ad7\src\google/protobuf/port_def.inc(441,32): note: expanded from macro 'PROTOBUF_CONSTINIT'
  441 | #  define PROTOBUF_CONSTINIT [[clang::require_constant_initialization]]
      |                                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2 warnings and 2 errors generated.

The second issue looks more odd, and the proposed fix is unlikely to be the right one (it is explicitly commented that its for a case exactly like this to intentionally fall back to the clang path instead of the msvc one).

I am not sure if it is meant to use the clang path for clang-cl on windows. It could simple always use the MSVC path.

@esrauchg esrauchg removed the untriaged auto added to all issues by default when created. label Jan 13, 2025
@sbenzaquen
Copy link
Contributor

We could relax the requirement there.
In theory, it should be able to use constant initialization portably, but MSVC has had bugs with this in the past.
constinit is not necessarily a correctness requirement, but it guarantees better code size and runtime costs.

We have clients using clang for windows that would see dynamic initialization there as a regression, so having the constinit is useful for us.

It is unfortunate that it doesn't give more details as to why it "does not have a constant initializer".
If I had to guess, it might be related to DLL incompatibilities with constexpr. When DLLs are involved, addresses that come from different libraries might not be constant evaluated by the compiler.
If this is the case, then maybe we can turn off constinit when DLLs are involved.

Maybe we can change that first branch as:

#if defined(_MSC_VER) && (!defined(__clang__) || defined(PROTOBUF_USE_DLLS))

That way we drop the constinit if DLLs are turned on, even when using clang.
Is this something you can test?

@Neumann-A
Copy link
Contributor Author

When DLLs are involved, addresses that come from different libraries might not be constant evaluated by the compiler.

They are not constant (at least due to /DYNAMICBASE being the default).

Currently having problems building Release since I run into:

[233/243] C:\WINDOWS\system32\cmd.exe /C "C:\WINDOWS\system32\cmd.exe /C "E:\vcpkg_cache\downloads\tools\cmake-3.31.0-windows\cmake-3.31.0-windows-i386\bin\cmake.exe -E __create_def D:\vcpkg_folders\no_msvc\buildtrees\protobuf\x64-win-llvm-rel\CMakeFiles\libprotoc.dir\.\exports.def D:\vcpkg_folders\no_msvc\buildtrees\protobuf\x64-win-llvm-rel\CMakeFiles\libprotoc.dir\.\exports.def.objs --nm=D:\vcpkg_folders\no_msvc\installed\x64-win-llvm\compiler-llvm\bin\llvm-nm.exe && cd D:\vcpkg_folders\no_msvc\buildtrees\protobuf\x64-win-llvm-rel" && E:\vcpkg_cache\downloads\tools\cmake-3.31.0-windows\cmake-3.31.0-windows-i386\bin\cmake.exe -E vs_link_dll --msvc-ver=1942 --intdir=CMakeFiles\libprotoc.dir --rc=rc.exe --mt="D:\vcpkg_folders\no_msvc\installed\x64-win-llvm\WinSDK\Windows Kits\10\bin\10.0.26100.0\x64\mt.exe" --manifests  -- D:\vcpkg_folders\no_msvc\installed\x64-win-llvm\compiler-llvm\bin\lld-link.exe  @CMakeFiles\libprotoc.rsp  /out:bin\libprotoc.dll /implib:bin\libprotoc.lib /pdb:bin\libprotoc.pdb /dll /version:29.3 /machine:x64 /nologo /DEBUG /INCREMENTAL:NO /OPT:REF /OPT:ICF    /DEF:CMakeFiles\libprotoc.dir\.\exports.def && cd ."
FAILED: bin/libprotoc.dll bin/libprotoc.lib 
C:\WINDOWS\system32\cmd.exe /C "C:\WINDOWS\system32\cmd.exe /C "E:\vcpkg_cache\downloads\tools\cmake-3.31.0-windows\cmake-3.31.0-windows-i386\bin\cmake.exe -E __create_def D:\vcpkg_folders\no_msvc\buildtrees\protobuf\x64-win-llvm-rel\CMakeFiles\libprotoc.dir\.\exports.def D:\vcpkg_folders\no_msvc\buildtrees\protobuf\x64-win-llvm-rel\CMakeFiles\libprotoc.dir\.\exports.def.objs --nm=D:\vcpkg_folders\no_msvc\installed\x64-win-llvm\compiler-llvm\bin\llvm-nm.exe && cd D:\vcpkg_folders\no_msvc\buildtrees\protobuf\x64-win-llvm-rel" && E:\vcpkg_cache\downloads\tools\cmake-3.31.0-windows\cmake-3.31.0-windows-i386\bin\cmake.exe -E vs_link_dll --msvc-ver=1942 --intdir=CMakeFiles\libprotoc.dir --rc=rc.exe --mt="D:\vcpkg_folders\no_msvc\installed\x64-win-llvm\WinSDK\Windows Kits\10\bin\10.0.26100.0\x64\mt.exe" --manifests  -- D:\vcpkg_folders\no_msvc\installed\x64-win-llvm\compiler-llvm\bin\lld-link.exe  @CMakeFiles\libprotoc.rsp  /out:bin\libprotoc.dll /implib:bin\libprotoc.lib /pdb:bin\libprotoc.pdb /dll /version:29.3 /machine:x64 /nologo /DEBUG /INCREMENTAL:NO /OPT:REF /OPT:ICF    /DEF:CMakeFiles\libprotoc.dir\.\exports.def && cd ."
LINK: command "D:\vcpkg_folders\no_msvc\installed\x64-win-llvm\compiler-llvm\bin\lld-link.exe @CMakeFiles\libprotoc.rsp /out:bin\libprotoc.dll /implib:bin\libprotoc.lib /pdb:bin\libprotoc.pdb /dll /version:29.3 /machine:x64 /nologo /DEBUG /INCREMENTAL:NO /OPT:REF /OPT:ICF /DEF:CMakeFiles\libprotoc.dir\.\exports.def /MANIFEST:EMBED,ID=2" failed (exit code 1) with the following output:
lld-link: error: undefined symbol: class google::protobuf::UnknownFieldSet const `public: static class google::protobuf::UnknownFieldSet const & __cdecl google::protobuf::UnknownFieldSet::default_instance(void)'::`2'::instance
>>> referenced by D:\vcpkg_folders\no_msvc\buildtrees\protobuf\src\v5.29.3-0e5117892e\src\google\protobuf\compiler\plugin.pb.h:156
>>>               CMakeFiles\libprotoc.dir\src\google\protobuf\compiler\code_generator.cc.obj:(public: class google::protobuf::UnknownFieldSet const & __cdecl google::protobuf::compiler::Version::unknown_fields(void) const)
>>> referenced by D:\vcpkg_folders\no_msvc\buildtrees\protobuf\src\v5.29.3-0e5117892e\src\google\protobuf\compiler\plugin.pb.h:393
>>>               CMakeFiles\libprotoc.dir\src\google\protobuf\compiler\code_generator.cc.obj:(public: class google::protobuf::UnknownFieldSet const & __cdecl google::protobuf::compiler::CodeGeneratorResponse_File::unknown_fields(void) const)
>>> referenced by D:\vcpkg_folders\no_msvc\buildtrees\protobuf\src\v5.29.3-0e5117892e\src\google\protobuf\compiler\plugin.pb.h:646

>>>               CMakeFiles\libprotoc.dir\src\google\protobuf\compiler\code_generator.cc.obj:(public: class google::protobuf::UnknownFieldSet const & __cdecl google::protobuf::compiler::CodeGeneratorResponse::unknown_fields(void) const)

>>> referenced 2 more times

I declared __declspec(noinline) for google::protobuf::UnknownFieldSet::default_instance which makes it work, so clang somehow thinks it is ok to remove that symbol with optimizations enabled.

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

3 participants