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

Alignment issue with zmq_msg_t on SPARC CPU #1325

Closed
baryonix opened this issue Jan 27, 2015 · 1 comment
Closed

Alignment issue with zmq_msg_t on SPARC CPU #1325

baryonix opened this issue Jan 27, 2015 · 1 comment

Comments

@baryonix
Copy link

One of the fields of zmq::msg_t is a pointer, which in some environments (in our case, this is a SPARC CPU in 64-bit mode) requires that an instance of the class be aligned to an 8-byte boundary in memory. SPARC is very picky about alignment - you will get a SIGBUS if this is not observed. Many other RISC CPUs behave similarly.

However the zmq_msg_t type which is used as a placeholder to contain a zmq::msg_t instance in the C API, only contains a char array, which will make the compiler apply a less strict alignment requirement. This results in several test cases failing with SIGBUS.

This could be fixed by turning zmq_msg_t into a union, having a pointer as one of its fields, which will force the compiler to apply correct alignment when allocating a zmq_msg_t.

--- include/zmq.h.orig  Di. Jan 27 14:43:30 2015
+++ include/zmq.h       Di. Jan 27 14:44:29 2015
@@ -199,7 +199,7 @@
 /*  0MQ message definition.                                                   */
 /******************************************************************************/

-typedef struct zmq_msg_t {unsigned char _ [32];} zmq_msg_t;
+typedef union zmq_msg_t {unsigned char _ [32]; void *p;} zmq_msg_t;

 typedef void (zmq_free_fn) (void *data, void *hint);

@rodgert
Copy link
Contributor

rodgert commented Jan 27, 2015

Scratch my previous comment, there should be no chance of false sharing for a zmq_msg_t if used correctly.

hintjens added a commit that referenced this issue Jan 27, 2015
resolve #1325 Alignment issue with zmq_msg_t on SPARC CPU
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