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

zmq 4.2.1 crashes with SIGBUS under 64-bit SunOS Sparc #2588

Closed
zmqsubmitter opened this issue May 31, 2017 · 5 comments
Closed

zmq 4.2.1 crashes with SIGBUS under 64-bit SunOS Sparc #2588

zmqsubmitter opened this issue May 31, 2017 · 5 comments

Comments

@zmqsubmitter
Copy link

zmqsubmitter commented May 31, 2017

SunOS 5.11 11.2 sun4v sparc
Sun C++ 5.13 SunOS_sparc

64-bit zmq build crashes with the following stack:

t@14 (l@14) terminated by signal BUS (invalid address alignment)
Current function is zmq::msg_t::init_external_storage
  139       u.zclmsg.content->size = size_;
(dbx) where -l
current thread: t@14
=>[1] libzmq.so.5.1.1:zmq::msg_t::init_external_storage(this = 0x10064ace8, content_ = 0x10064dc54, data_ = 0x10064bc56, size_ = 41U, ffn_ = 0xffffffff677bf6c0                         = &zmq::shared_message_memory_allocator::call_dec_ref(void*,void*), hint_ = 0x10064bc50), line 139 in "msg.cpp"
  [2] libzmq.so.5.1.1:zmq::msg_t::init(this = 0x10064ace8, data_ = 0x10064bc56, size_ = 41U, ffn_ = 0xffffffff677bf6c0 = &zmq::shared_message_memory_allocator::                        call_dec_ref(void*,void*), hint = 0x10064bc50, content_ = 0x10064dc54), line 73 in "msg.cpp"
  [3] libzmq.so.5.1.1:zmq::v2_decoder_t::size_ready(this = 0x10064ac70, msg_size = 41U, read_pos = 0x10064bc56 "^EREADY^KSocket-Type"), line 124 in "v2_decoder.                        cpp"
  [4] libzmq.so.5.1.1:zmq::v2_decoder_t::one_byte_size_ready(this = 0x10064ac70, read_from = 0x10064bc56 "^EREADY^KSocket-Type"), line 80 in "v2_decoder.cpp"
  [5] libzmq.so.5.1.1:zmq::decoder_base_t<zmq::v2_decoder_t,zmq::shared_message_memory_allocator>::decode(this = 0x10064aca0, data_ = 0x10064bc54 "^D)^EREADY^KS                        ocket-Type", size_ = 89U, bytes_used_ = 2U), line 147 in "decoder.hpp"
  [6] libzmq.so.5.1.1:zmq::stream_engine_t::in_event(this = 0x100636230), line 344 in "stream_engine.cpp"
  [7] libzmq.so.5.1.1:zmq::poll_t::loop(this = 0x100559410), line 169 in "poll.cpp"
  [8] libzmq.so.5.1.1:zmq::poll_t::worker_routine(arg_ = 0x100559410), line 190 in "poll.cpp"
  [9] libzmq.so.5.1.1:thread_routine(0x1005594c0, 0x0, 0x0, 0xffffffff6778f238, 0x0, 0x1), at 0xffffffff6778f418

The trouble is apparently in decoder_allocators.cpp:45 which returns non-aligned pointer. The possible workaround is the manual expansion of atomic_counter_t to make it of align-friendly size.

Index: src/atomic_counter.hpp
===================================================================
--- src/atomic_counter.hpp      (revision 141922)
+++ src/atomic_counter.hpp      (working copy)
@@ -77,7 +77,7 @@
         typedef uint32_t integer_t;

         inline atomic_counter_t (integer_t value_ = 0) :
-            value (value_)
+            value (value_), align(this)
         {
         }

@@ -212,6 +212,7 @@
         atomic_counter_t (const atomic_counter_t&);
         const atomic_counter_t& operator = (const atomic_counter_t&);
 #endif
+               void *align;
     };

 }
@bluca
Copy link
Member

bluca commented May 31, 2017

Could you please fix a bit the formatting of the backtrace and the diff? I'm afraid they are not very readable as is

@zmqsubmitter
Copy link
Author

have made a try...

@bluca
Copy link
Member

bluca commented Jun 5, 2017

Thanks, that is much clearer now.
Does that diff fix it for you?

@zmqsubmitter
Copy link
Author

zmqsubmitter commented Jun 6, 2017 via email

@bluca
Copy link
Member

bluca commented Jun 6, 2017

Thanks, sorry I misunderstood.

Would you like to send a PR to implement it?

The fix looks fine to me, it's internal code only and everywhere it checks for the actual size of the type so I don't foresee issues.

bluca added a commit to bluca/libzmq that referenced this issue Aug 11, 2017
Solution: force the compiler to make the atomic_counter_t alignment
friendly.
This will ensure that the pointers inside the buffers allocated by
shared_message_memory are aligned, at the cost of growing the memory
size of atomic_counter_t from 4 to 8 bytes on 64 bit (when not using
mutexes).
Note that although content_t contains an atomic_counter_t, the
compiler already padded the struct so there is no change in the
buffer sizes used by the engines, save for the extra 4 bytes for the
buffer's own single atomic counter.
Fixes zeromq#2588
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

No branches or pull requests

2 participants