[SERVER-44372] Shim declarations on same line in different TUs can lead to linker errors Created: 01/Nov/19 Updated: 29/Oct/23 Resolved: 07/Nov/19 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Build |
| Affects Version/s: | None |
| Fix Version/s: | 4.3.1 |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Andrew Morrow (Inactive) | Assignee: | Billy Donahue |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Backwards Compatibility: | Fully Compatible |
| Operating System: | ALL |
| Sprint: | Dev Tools 2019-11-18 |
| Participants: |
| Description |
|
The MONGO_DECLARE_SHIM macro uses token pasting to attach the current line number to the internal class it defines: https://github.com/mongodb/mongo/blob/8010c51d3f1cc1020959f8b351f8242d141d42a3/src/mongo/base/shim.h#L136-L139 If two files declare shims within the same namespace on the same line, that will be an ODR violation:
The DECLARE_SHIM and related macros must find a way to generate names which cannot collide like this, probably by folding some of the file name into the generated name, or by requiring a stringy argument to the macro to disambiguate. |
| Comments |
| Comment by Githook User [ 07/Nov/19 ] | |||||||||||||
|
Author: {'name': 'Billy Donahue', 'username': 'BillyDonahue', 'email': 'billy.donahue@mongodb.com'}Message: | |||||||||||||
| Comment by Githook User [ 07/Nov/19 ] | |||||||||||||
|
Author: {'username': 'BillyDonahue', 'email': 'billy.donahue@mongodb.com', 'name': 'Billy Donahue'}Message: | |||||||||||||
| Comment by Billy Donahue [ 05/Nov/19 ] | |||||||||||||
|
Enterprise CR: https://mongodbcr.appspot.com/524640017 | |||||||||||||
| Comment by Billy Donahue [ 05/Nov/19 ] | |||||||||||||
|
After an hour or so, I could not figure out how to safely replace the line numbers with better identifiers. The shim.h macros are a very difficult implementation of a pretty basic idea of having a function registry to disassociate function providers from function callers in the link graph. The better course of action here is to replace the extremely complex meta-programming thing with a conventional C++ based mechanism, based on a string-keyed map of type erased generalized function pointers, and dynamic_cast. The 13 or so functions that are being changed out with the shim framework are never performance critical. They are registering factory functions for the most part, or they are at the frequency of once per operation. | |||||||||||||
| Comment by Billy Donahue [ 04/Nov/19 ] | |||||||||||||
|
Good news is that there are only 13 instances of MONGO_DECLARE_SHIM in the codebase.
|