[PATCH] [LLD] Prevent race condition by making lastOrdinal atomic.

Lang Hames lhames at gmail.com
Wed May 20 16:43:16 PDT 2015


Hi ruiu, kledzik,

While running the nightly test suite with lld on Darwin, I came across the following crash:

Atoms with Same Ordinal!
UNREACHABLE executed at /Users/lhames/Projects/lld/lld-git-dev/llvm/tools/lld/lib/ReaderWriter/MachO/LayoutPass.cpp:245!

The root cause is that SimpleDefinedAtom assigns ordinals from a non-atomic static local variable "lastOrdinal" in the constructor. Two threads were reading this concurrently, leading the atomics to be assigned the same ordinal.

This patch fixes the issue by making lastOrdinal atomic.

REPOSITORY
  rL LLVM

http://reviews.llvm.org/D9901

Files:
  include/lld/Core/Simple.h

Index: include/lld/Core/Simple.h
===================================================================
--- include/lld/Core/Simple.h
+++ include/lld/Core/Simple.h
@@ -23,6 +23,7 @@
 #include "lld/Core/UndefinedAtom.h"
 #include "llvm/ADT/ilist.h"
 #include "llvm/ADT/ilist_node.h"
+#include <atomic>
 
 namespace lld {
 
@@ -206,7 +207,7 @@
 class SimpleDefinedAtom : public DefinedAtom {
 public:
   explicit SimpleDefinedAtom(const File &f) : _file(f) {
-    static uint32_t lastOrdinal = 0;
+    static std::atomic<uint32_t> lastOrdinal(0);
     _ordinal = lastOrdinal++;
     _references.setAllocator(&f.allocator());
   }

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D9901.26196.patch
Type: text/x-patch
Size: 625 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150520/98fe3b8b/attachment.bin>


More information about the llvm-commits mailing list