[CDRIVER-2681] bson_context_get_default optimized out when compiling with LTO Created: 02/Jun/18 Updated: 28/Oct/23 Resolved: 07/Jun/18 |
|
| Status: | Closed |
| Project: | C Driver |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | 1.11.0 |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Kevin Albertson | Assignee: | Kevin Albertson |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||||||||||
| Description |
|
Drew noticed when we compile the C driver with link time optimization our tests fail. Repro:
fails with a segfault. It looks like some function definitions are getting optimized out when they shouldn't be. It's a little difficult to debug since -flto removes debug info, but after some printf debugging, it became clear that bson_context_get_default was not getting called. Using nm you can also see there's no symbol in the binary:
comes up with nothing. Here's the definition of
BSON_GNUC_CONST is defined as _attribute_ ((const)) for gcc/clang. The gcc function attributes docs give this explanation for the const attribute:
But bson_context_get_default does read from global variables (PTHREAD_ONCE_INIT}} and gContextDefault. Since const functions shouldn't have side effects, the linker thinks it can optimize it out. Sure enough, removing the const attribute results in this test passing. There are other functions marked as const that probably shouldn't be, e.g. mongoc_ssl_opt_get_default, which returns a global.
|
| Comments |
| Comment by Githook User [ 07/Jun/18 ] |
|
Author: {'username': 'kevinAlbs', 'name': 'Kevin Albertson', 'email': 'kevin.albertson@10gen.com'}Message: |