mold: Assertion fails when compiling Rust

I am using mold to compile a Rust app. I’m using the latest unstable version of mold from the debian repository, which is: 2.34.1. This is the error I am seeing:

mold: ./src/../lib/common.h:637: std::pair<T*, bool> mold::ConcurrentMap<T>::insert(std::string_view, mold::u32, const T&) [with T = mold::SectionFragment<mold::X86_64>; std::string_view = std::basic_string_view<char>; mold::u32 = unsigned int]: Assertion `false && "ConcurrentMap is full"' failed.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 16 (8 by maintainers)

Commits related to this issue

Most upvoted comments

Ahh, that’s nice, but I cannot explain why that could fix the issue. If you have time, can you rebuild mold without that commit (i.e. build at 85be067813952409878ddd7d507855c2a017841d) to see if the problem occurs right before the last commit? I want to make sure that the problem was really fixed.

Thank you for testing with the patch. The error is mysterious – the concurrent hashmap that is reported as full is only 60% full. The error is raised if 128 consecutive hash table slots are occupied, but with 60% usage, it is extremely unlikely to occur. There are a few possible explanations:

  • Our hash function is low quality and causes too many collisions in the hash table (but it’s unlikely because we are using XXHash),
  • The symbol names of your programs causes XXHash to cause collisions (it’s very unlikely too), or
  • There’s a bug in our concurrent hash map.

I don’t know which is the case.

I made a small change to the concurrent hashmap. Can you test again with the git head?

Does this occur without multi-threading? Please try again with --no-threads linker option.

I really want to fix this issue.

Can you build mold with the following patch and share the new error message?

diff --git a/lib/common.h b/lib/common.h
index ac2b0c5c..7d679aa1 100644
--- a/lib/common.h
+++ b/lib/common.h
@@ -615,6 +615,7 @@ public:
       // If we successfully claimed the ownership of the slot,
       // copy values to it.
       if (claimed) {
+        nused++;
         new (&ent.value) T(val);
         ent.keylen = key.size();
         ent.key.store(key.data(), std::memory_order_release);
@@ -633,8 +634,11 @@ public:
         return {&ent.value, false};
     }

-    assert(false && "ConcurrentMap is full");
-    return {nullptr, false};
+    std::cerr << "ConcurrentMap is full: capacity=" << nbuckets
+              << " nused=" << nused
+              << " key=" << key
+              << "\n";
+    abort();
   }

   i64 get_idx(T *value) const {
@@ -698,6 +702,7 @@ public:

   Entry *entries = nullptr;
   i64 nbuckets = 0;
+  Atomic<i64> nused = 0;
 };

 //