[SERVER-30955] dynamically linked mongod fails to start on OS X Created: 05/Sep/17  Updated: 14/Feb/22  Resolved: 27/Aug/21

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

Type: Bug Priority: Major - P3
Reporter: Geert Bosch Assignee: Benety Goh
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
depends on SERVER-29908 Libraries db/s/sharding and db/query/... Closed
depends on SERVER-30815 Migrate library dependencies to LIBDE... Closed
is depended on by SERVER-53417 Reenable macOS dynamical builders Closed
Duplicate
duplicates SERVER-59118 fix macos dyld limit Closed
Problem/Incident
Related
related to SERVER-63616 Fail early on OSX when > 512 dylibs Closed
related to SERVER-59118 fix macos dyld limit Closed
Operating System: ALL
Steps To Reproduce:

Build on OS X with --link-model=dynamic.

Sprint: Execution Team 2021-09-06
Participants:
Linked BF Score: 38

 Description   

$ ./mongod
dyld: malformed mach-o: load commands size (35872) > 32768
Abort trap: 6

The output of dyldinfo -dylibs ./mongod is about 32 K, supporting the notion that we may have too many libraries, or libraries with path names that are too long, to produce a valid executable.



 Comments   
Comment by Githook User [ 17/Dec/20 ]

Author:

{'name': 'A. Jesse Jiryu Davis', 'email': 'jesse@mongodb.com', 'username': 'ajdavis'}

Message: SERVER-30955 Disable macOS dynamic builds
Branch: master
https://github.com/mongodb/mongo/commit/859b72ae51e1c1cce996a4afe86ee3951500e55d

Comment by A. Jesse Jiryu Davis [ 16/Dec/20 ]

I propose we disable the failing builders until this is fixed, to save people the effort of investigating the failure and discovering this ticket over and over.

Comment by Andrew Morrow (Inactive) [ 12/Jul/20 ]

Another wrinkle for this ticket: it appears that the load commands size of 32768 is only one constraint we must satisfy. Interstingly, hygienic builds has moved us in the right direction on this, however, there is another constraint, as revealed by running on master:

./build/install/bin/mongod
dyld: Library not loaded: @rpath/libmongod_initializers.dylib
  Referenced from: build/install/lib/libmongod_main.dylib
  Reason: no suitable image found.  Did find:
	build/install/lib/../lib/libmongod_initializers.dylib: too many dependent dylibs in build/install/lib/../lib/libmongod_initializers.dylib
	build/install/lib/../lib/libmongod_initializers.dylib: stat() failed with errno=1
	build/install/bin/../lib/libmongod_initializers.dylib: too many dependent dylibs in build/install/bin/../lib/libmongod_initializers.dylib
[1]    29234 abort      ./build/install/bin/mongod

It appears that there is hard-coded upper bound of 512 dynamic dependencies. Look for too many dependent dylibs in https://opensource.apple.com/source/dyld/dyld-733.6/src/ImageLoader.cpp.auto.html.

If we look at libmongod_initializers.dylib we see that we currently have 530:

$ otool -l /build/install/lib/../lib/libmongod_initializers.dylib | grep cmdsize | wc -l
530

So, we may not actually be able to solve this problem until we simplify the link graph, or are able to move many more libraries to LIBDEPS_PRIVATE.

Comment by Andrew Morrow (Inactive) [ 11/Jul/20 ]

I wasn't sure before how to get an accurate measure of the load commands, but I came up with one today:

$ python3 buildscripts/scons.py --variables-files=etc/scons/xcode_macosx.vars --link-model=dynamic --build-fast-and-loose --implicit-cache --opt=on --dbg=on --cache ./mongod --install-mode=legacy
$ otool -l mongod | grep cmdsize | awk '{ sum+=$2} END { print sum }'
44640
$ ./mongod
dyld: malformed mach-o: load commands size (44640) > 32768
[1]    7244 abort      ./mongod

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