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

has_single_bit requires #include <bit> #308

Closed
dilyn-corner opened this issue Jan 26, 2022 · 9 comments · Fixed by #309
Closed

has_single_bit requires #include <bit> #308

dilyn-corner opened this issue Jan 26, 2022 · 9 comments · Fixed by #309

Comments

@dilyn-corner
Copy link

mold/mold.h

Line 163 in 0d542fb

assert(std::has_single_bit(align));

Introduced by 6c9bb0d

Building on musl with LLVM/Clang/lld/libc++.

Adding #include <bit> to mold.h resolves the below build time error:

mkdir -p out/elf
touch out/elf/.keep
mkdir -p out/macho
touch out/macho/.keep
c++ -std=c++20 -fno-exceptions -fno-unwind-tables -fno-asynchronous-unwind-tables -DMOLD_VERSION=\"1.0.2\" -DLIBDIR="\"/usr/local/lib\"" -Ithird-party/mimalloc/include -Ithird-party/tbb/include -Ithird-party/xxhash  -MT out/compress.o -MMD -MP -MF out/compress.d -O2 -c -o out/compress.o compress.cc
In file included from compress.cc:15:
./mold.h:163:15: error: no member named 'has_single_bit' in namespace 'std'
  assert(std::has_single_bit(align));
         ~~~~~^
/usr/include/assert.h:8:28: note: expanded from macro 'assert'
#define assert(x) ((void)((x) || (__assert_fail(#x, __FILE__, __LINE__, __func__),0)))
                           ^
In file included from compress.cc:15:
./mold.h:168:15: error: no member named 'has_single_bit' in namespace 'std'
  assert(std::has_single_bit(align));
         ~~~~~^
/usr/include/assert.h:8:28: note: expanded from macro 'assert'
#define assert(x) ((void)((x) || (__assert_fail(#x, __FILE__, __LINE__, __func__),0)))
                           ^
In file included from compress.cc:15:
./mold.h:299:49: error: no member named 'bit_ceil' in namespace 'std'
    nbuckets = std::max<i64>(MIN_NBUCKETS, std::bit_ceil<u64>(nbuckets));
                                           ~~~~~^
./mold.h:299:58: error: unexpected type name 'u64': expected expression
    nbuckets = std::max<i64>(MIN_NBUCKETS, std::bit_ceil<u64>(nbuckets));
                                                         ^
./mold.h:311:17: error: no member named 'has_single_bit' in namespace 'std'
    assert(std::has_single_bit<u64>(nbuckets));
           ~~~~~^
/usr/include/assert.h:8:28: note: expanded from macro 'assert'
#define assert(x) ((void)((x) || (__assert_fail(#x, __FILE__, __LINE__, __func__),0)))
                           ^
In file included from compress.cc:15:
./mold.h:311:32: error: unexpected type name 'u64': expected expression
    assert(std::has_single_bit<u64>(nbuckets));
                               ^
./mold.h:429:57: error: no member named 'countl_zero' in namespace 'std'
    update_maximum(buckets[hash & (NBUCKETS - 1)], std::countl_zero(hash) + 1);
                                                   ~~~~~^
7 errors generated.
gmake: *** [Makefile:140: out/compress.o] Error 1
sicherha added a commit to sicherha/mold that referenced this issue Jan 26, 2022
Fixes rui314#308.

Signed-off-by: Christoph Erhardt <github@sicherha.de>
@truboxl
Copy link

truboxl commented Jan 29, 2022

Anyone know which version of Clang support this? Adding <bit> doesn't seem to fix it for me. I think I am using Clang 12 (Android NDK)...

@dilyn-corner
Copy link
Author

dilyn-corner commented Jan 29, 2022

This was with Clang 13 (AFAIK Clang 12 did not support many (any?) features of C++20). which should be supported by libc++ 12; does Android NDK use the whole LLVM toolchain? For instance, I don't think GCC's libstdc++ supports it.

@rui314
Copy link
Owner

rui314 commented Jan 29, 2022

@truboxl Does reverting 6c9bb0d (you can do that by git revert 6c9bb0d7ff5e863775e50f5a80fe64cefff34a23) fix your problem? If so, I'm happy to do that.

@truboxl
Copy link

truboxl commented Jan 31, 2022

Sorry for the late reply

@rui314
Yes that works

For reference, the latest NDK r23 includes this bit header file which seems to be missing has_single_bit...
https://android.googlesource.com/toolchain/prebuilts/ndk/r23/+/refs/heads/master/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1/bit

I haven't check out NDK r24 beta which should be using Clang 14...

There's no activity here so I assume r24 is pretty much the same? I think C++20 on Android is barely getting started...
https://android.googlesource.com/platform/prebuilts/ndk/+/refs/heads/master/current/sources/cxx-stl/llvm-libc++/include/bit

@rui314 rui314 reopened this Jan 31, 2022
@rui314 rui314 closed this as completed in 7aa35d1 Jan 31, 2022
@rui314
Copy link
Owner

rui314 commented Jan 31, 2022

I submitted a change to remove the uses of std::has_single_bit from our codebase. Please verify if you have time.

@truboxl
Copy link

truboxl commented Jan 31, 2022

Oops forgot to mention std::bit_ceil 😅

elf/output-chunks.cc:1285:22: error: no member named 'bit_ceil' in namespace 'std'
    num_bloom = std::bit_ceil<u64>(num_bits / ELFCLASS_BITS);
                ~~~~~^
elf/output-chunks.cc:1285:31: error: unexpected type name 'u64': expected expression
    num_bloom = std::bit_ceil<u64>(num_bits / ELFCLASS_BITS);
                              ^
2 errors generated.

macho/../mold.h:300:49: error: no member named 'bit_ceil' in namespace 'std'
    nbuckets = std::max<i64>(MIN_NBUCKETS, std::bit_ceil<u64>(nbuckets));
                                           ~~~~~^
macho/../mold.h:300:58: error: unexpected type name 'u64': expected expression
    nbuckets = std::max<i64>(MIN_NBUCKETS, std::bit_ceil<u64>(nbuckets));
                                                         ^
2 errors generated.

@rui314 rui314 reopened this Jan 31, 2022
@rui314 rui314 closed this as completed in c6b34c2 Jan 31, 2022
@rui314
Copy link
Owner

rui314 commented Jan 31, 2022

I removed the uses of std::bit_ceil from our codebase.

@truboxl
Copy link

truboxl commented Feb 1, 2022

I have gone ahead and log the issue as android/ndk#1664 to see what NDK folks think about this. Maybe they will list out timeline to add support for this.

@rui314
Copy link
Owner

rui314 commented Feb 1, 2022

Thanks. I don't know if Android NDK officially supports C++20, but if it does, then it's clearly a bug.

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

Successfully merging a pull request may close this issue.

3 participants