[Lldb-commits] [lldb] r279994 - Remove std::atomic from lldb::Address.

Zachary Turner via lldb-commits lldb-commits at lists.llvm.org
Mon Aug 29 12:30:26 PDT 2016


Author: zturner
Date: Mon Aug 29 14:30:26 2016
New Revision: 279994

URL: http://llvm.org/viewvc/llvm-project?rev=279994&view=rev
Log:
Remove std::atomic from lldb::Address.

std::atomic<uint64_t> requires 64-bit alignment in order to
guarantee atomicity.  Normally the compiler is pretty good about
aligning types, but an exception to this is when the type is
passed by value as a function parameter.  In this case, if your
stack is 4-byte aligned, most modern compilers (including clang
as of LLVM 4.0) fail to align the type, rendering the atomicity
ineffective.

A deeper investigation of the class's implementation suggests
that the use of atomic was in vain anyway, because if the class
were to be shared amongst multiple threads, there were already
other data races present, and that the proper way to ensure
thread-safe access to this data would be to use a mutex from a
higher level.

Since the std::atomic was not serving its intended purpose anyway,
and since the presence of it generates compiler errors on some
platforms that cannot be workaround, we remove std::atomic from
Address here.  Although unlikely, if data races do resurface
the proper fix should involve a mutex from a higher level, or an
attempt to limit the Address's access to a single thread.

Modified:
    lldb/trunk/include/lldb/Core/Address.h
    lldb/trunk/source/Core/Address.cpp

Modified: lldb/trunk/include/lldb/Core/Address.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/Address.h?rev=279994&r1=279993&r2=279994&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/Address.h (original)
+++ lldb/trunk/include/lldb/Core/Address.h Mon Aug 29 14:30:26 2016
@@ -12,7 +12,6 @@
 
 // C Includes
 // C++ Includes
-#include <atomic>
 
 // Other libraries and framework includes
 // Project includes
@@ -119,7 +118,7 @@ public:
     //------------------------------------------------------------------
     Address (const Address& rhs) :
         m_section_wp (rhs.m_section_wp),
-        m_offset(rhs.m_offset.load())
+        m_offset(rhs.m_offset)
     {
     }
 
@@ -556,7 +555,7 @@ protected:
     // Member variables.
     //------------------------------------------------------------------
     lldb::SectionWP m_section_wp;   ///< The section for the address, can be NULL.
-    std::atomic<lldb::addr_t> m_offset;      ///< Offset into section if \a m_section_wp is valid...
+    lldb::addr_t m_offset;          ///< Offset into section if \a m_section_wp is valid...
     
     //------------------------------------------------------------------
     // Returns true if the m_section_wp once had a reference to a valid

Modified: lldb/trunk/source/Core/Address.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Address.cpp?rev=279994&r1=279993&r2=279994&view=diff
==============================================================================
--- lldb/trunk/source/Core/Address.cpp (original)
+++ lldb/trunk/source/Core/Address.cpp Mon Aug 29 14:30:26 2016
@@ -235,7 +235,7 @@ Address::operator= (const Address& rhs)
     if (this != &rhs)
     {
         m_section_wp = rhs.m_section_wp;
-        m_offset = rhs.m_offset.load();
+        m_offset = rhs.m_offset;
     }
     return *this;
 }
@@ -429,7 +429,7 @@ Address::Dump (Stream *s, ExecutionConte
         if (section_sp)
         {
             section_sp->DumpName(s);
-            s->Printf (" + %" PRIu64, m_offset.load());
+            s->Printf (" + %" PRIu64, m_offset);
         }
         else
         {




More information about the lldb-commits mailing list