Skip to content

Commit

Permalink
[ELF] Do not use std::has_single_bit
Browse files Browse the repository at this point in the history
It looks like some stdlib implementations do not provide that function.

Fixes #308
  • Loading branch information
rui314 committed Jan 31, 2022
1 parent 8465438 commit 7aa35d1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion elf/cmdline.cc
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ void parse_nonpositional_args(Context<E> &ctx,
ctx.arg.z_execstack = true;
} else if (read_z_arg(ctx, args, arg, "max-page-size")) {
ctx.page_size = parse_number(ctx, "-z max-page-size", arg);
if (!std::has_single_bit<u64>(ctx.page_size))
if (std::popcount<u64>(ctx.page_size) != 1)
Fatal(ctx) << "-z max-page-size " << arg << ": value must be a power of 2";
} else if (read_z_flag(args, "noexecstack")) {
ctx.arg.z_execstack = false;
Expand Down
6 changes: 3 additions & 3 deletions mold.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,12 @@ class Warn {
inline u64 align_to(u64 val, u64 align) {
if (align == 0)
return val;
assert(std::has_single_bit(align));
assert(std::popcount(align) == 1);
return (val + align - 1) & ~(align - 1);
}

inline u64 align_down(u64 val, u64 align) {
assert(std::has_single_bit(align));
assert(std::popcount(align) == 1);
return val & ~(align - 1);
}

Expand Down Expand Up @@ -309,7 +309,7 @@ class ConcurrentMap {
if (!keys)
return {nullptr, false};

assert(std::has_single_bit<u64>(nbuckets));
assert(std::popcount<u64>(nbuckets) == 1);
i64 idx = hash & (nbuckets - 1);
i64 retry = 0;

Expand Down

0 comments on commit 7aa35d1

Please sign in to comment.