Skip to content

Build failure on Elbrus architecture (e2k) with LCC compiler in zstd/lib/common/bitstream.h (DEBUG_STATIC_ASSERT) #324

Description

@dmitry-lipetsk

Environment

  • OS: ALT Linux (e2k / Elbrus)
  • Compiler: LCC (e2k-alt-linux-gcc)
  • Package version: 1.5.7.2+ (with vendored zstd sources)

Problem description

When installing the package via pip on the Elbrus (e2k) architecture, the compilation fails due to a false positive trigger in the compile-time static assert macro. The LCC compiler throws an error stating that the array size must be greater than zero during the size comparison of bitContainer and U32.

Error Log

lcc: "zstd/lib/common/debug.h", line 39: error #94: the size of an array must be greater than zero
  #define DEBUG_STATIC_ASSERT(c) (void)sizeof(char[(c) ? 1 : -1])
                                                   ^
 in expansion of macro "DEBUG_STATIC_ASSERT" at line 168 of
           "zstd/lib/common/bitstream.h"
      DEBUG_STATIC_ASSERT(sizeof(bitContainer) == sizeof(U32));

1 error detected in the compilation of "zstd/lib/common/entropy_common.c".
error: command '/usr/bin/e2k-alt-linux-gcc' failed with exit code 1

Suggested Solution

To prevent breaking compatibility with mainstream compilers (GCC, Clang, MSVC) on x86/ARM while enabling successful builds on Elbrus, we can conditionally bypass or adapt this macro when the __LCC__ compiler flag is detected.

Modifying zstd/lib/common/debug.h as follows resolves the issue:

#if defined(__LCC__)
#  if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
#    define DEBUG_STATIC_ASSERT(c) _Static_assert((c), #c)
#  else
#    define DEBUG_STATIC_ASSERT(c) ((void)0)
#  endif
#else
#  define DEBUG_STATIC_ASSERT(c) (void)sizeof(char[(c) ? 1 : -1])
#endif

Could you please consider adding this or a similar fix in the next release? Thank you!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions