[SERVER-3992] Windows executables should not export symbols Created: 01/Oct/11  Updated: 11/Jul/16  Resolved: 01/Oct/11

Status: Closed
Project: Core Server
Component/s: Build
Affects Version/s: 2.0.0
Fix Version/s: 2.1.0

Type: Bug Priority: Trivial - P5
Reporter: Tad Marshall Assignee: Eliot Horowitz (Inactive)
Resolution: Done Votes: 0
Labels: Windows
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Windows


Operating System: Windows
Participants:

 Description   

In Windows, Dynamic Link Libraries can contain an Export Address Table that enables the program loader component of Windows to find the addresses of routines that are "published" by the DLL. This enables a program (EXE) or one of its DLLs to call those routines. These "exports" are only useful in DLLs and should not be present in EXE files. Routines to be "exported" (listed in the Export Address Table) can be specified to the linker directly, or can be flagged in the source files by attaching the Microsoft-specific __declspec(dllexport) to a declaration.
Several of the executables in the Windows version of MongoDB are exporting symbols. This is basically harmless, but it makes the EXE files a tiny bit larger and is generally poor form. This actually got a whole lot better in 2.0 as the number of (bogus) exported functions dropped in mongod.exe (x64) from 571 in v1.8.3 to 106 in v2.0.0. The symbols that were removed between 1.8.3 and 2.0.0 were all from SpiderMonkey (JavaScript engine). The symbols that remain are all from PCRE (Perl Compatible Regular Expressions). I am able to get rid of these symbols in my Visual Studio build by setting PRCECPP_STATIC in preprocessor symbols in MSVC for the affected projects. We are already managing to set PCRE_STATIC, but we have also hacked on the source code a bit. PCRE 7.4 in our build is almost exactly the published source code except for some hacking at the ever-annoying __declspec() stuff.
The affected EXE files built by "scons all" for 2.1.0-pre- are: bsondump, mongod, mongodump, mongoexport, mongofiles, mongoimport, mongooplog, mongorestore, mongos, mongostat and mongotop. Every one of these files is exporting the same set of 106 PCRE functions. Setting PCRECPP_STATIC in the compile step should fix all of them. You can see how you are doing on eliminating exports by using the Microsoft program depends.exe (Dependency Walker), which can be downloaded for free if you don't already have a copy. When looking at the top of the tree for an EXE, there should be no symbols listed in the first two boxes in the upper right ... nothing imported, nothing exported.



 Comments   
Comment by Tad Marshall [ 01/Oct/11 ]

Eliot's fix looks perfect on my machine. Zero exports from MongoDB's Windows EXE files. Built with 'scons all', tested with the same copy of Dependency Walker, I checked every EXE. Fixed.

Comment by auto [ 01/Oct/11 ]

Author:

{u'login': u'erh', u'name': u'Eliot Horowitz', u'email': u'eliot@10gen.com'}

Message: use PCRECPP_STATIC SERVER-3992
Branch: master
https://github.com/mongodb/mongo/commit/8ce081f169a5f75d9cdc52bb14b0ba49c9ec2763

Comment by Tad Marshall [ 01/Oct/11 ]

Ugh. I misspelled PCRECPP_STATIC the first time I typed it in the bug report, reversing the second and third letters.

Comment by Tad Marshall [ 01/Oct/11 ]

The last sentence in my bug report is a little off. The two listboxes in the upper right should be empty when the selection in the treeview on the left is on the EXE itself, but the pair of listboxes are not imports and exports. The top box lists symbols exported from the selected module that are being imported by the module above it in the tree. This box will always be empty when the treeview selection is the topmost element, regardless of whether it is an EXE or a DLL and regardless of what it is exporting. The lower box shows the list of symbols that are being exported, regardless of whether there is a module above it in the tree that is using them. So, an EXE should show both boxes empty when it is selected in the treeview and a DLL should (usually) show entries in the lower box when it is selected. I found this issue by running Dependency Walker to see what DLLs and functions MongoDB was using.

Generated at Thu Feb 08 03:04:38 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.