[CDRIVER-596] Figure out what to do about bson_t alignment restrictions Created: 27/Mar/15 Updated: 06/Sep/18 Resolved: 24/Apr/15 |
|
| Status: | Closed |
| Project: | C Driver |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | 1.2-beta0 |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Mira Carey | Assignee: | Unassigned |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||||||||||||||||||||||
| Description |
|
We set alignment attributes for bson_t's, but we set them at 128 byte alignment (theoretically to align them for cache lines on the stack). The problem is that we malloc and return them that way. While malloc is guaranteed to return something as aligned as the most aligned scalar type, that isn't generally 128 byte alignment. That makes tools scream constantly about the misalignment. It also shows up in cases where bson_malloc has been shimmed if the memory allocater doesn't go wide enough (specifically showing up in zend_emalloc, only 8 byte alignment), which causes memcpy to screw up (it looked at the types going in and generated aggressive code assuming it could use vectorized intrinsincs, when it could not) |
| Comments |
| Comment by A. Jesse Jiryu Davis [ 21/Mar/16 ] |
|
It's an ABI break, so we're waiting for libbson and libmongoc 2.0, when semantic versioning allows backwards-incompatible changes. |
| Comment by Petr Pisar [ 21/Mar/16 ] |
|
Default BSON_EXTRA_ALIGN is still 1. If this generates broken code, isn't time to disable it by default? |
| Comment by Githook User [ 07/Oct/15 ] |
|
Author: {u'username': u'hanumantmk', u'name': u'Jason Carey (hanumantmk)', u'email': u'jcarey@argv.me'}Message: Add BSON_EXTRA_ALIGN, which when set to 0, disables extra alignment of Using this flag will break ABI Added --enable-extra-align configure flag which controls this. It's |
| Comment by A. Jesse Jiryu Davis [ 24/Apr/15 ] |
|
Fixed on 1.2.0-dev branch: https://github.com/mongodb/libbson/commit/6e8eca8d044e73db0fd7b8a26824312e79cc3bf7 |
| Comment by Mira Carey [ 27/Mar/15 ] |
|
I think for now I'm just going to ignore fixing the real problem and offer a patch workaround. It's definitely true that some compilers take advantage of the alignment specifier to generate different code for 8 byte versus 16 byte aligned types. So we'll definitely break ABI if we get rid of the aligned requirements bson_t. For now that means making this an off by default configure switch and moving on with our lives. |
| Comment by Mira Carey [ 27/Mar/15 ] |