By default, our scons script will include all debug symbols when building MongoDB. Our packaging script strips them out for the prebuilt binaries by using “objcopy --strip-debug”.
scons does not have a --strip-debug parameter. I suggest using the objcopy command to strip the binaries after building them, by passing the --strip-debug flag to it: objcopy --strip-debug <the mongod binary>
For MongoDB v4.4 and later, you can use the --separate-debug flag to automatically invoke objcopy to separate the debug symbols at build time. When you use this flag, new targets are enabled: along with the install-core target there will be an install-core-debug target which will install the separated debug files.
So I think your Command2 should more or less work. I think the compilation error you received with that command is due to the --spider-monkey-dbg=on flag, which you should not use. You also don’t need the --install-mode=hygienic flag since it is the default in v4.4
So, my recommended command line for you would be something like:
That will create archive files containing the runtime and debug symbols, respectively, which are packaged with the path /opt/IBM/mongo-distro (note the change from DESTDIR to PREFIX).
Hi @Andrew_Morrow Thanks for the detailed explanation.
I was able to use --separate-debug alone for the version 4.4.12 and it reduced the size of binaries as well.
command for 4.4.12
But this procedure did not reduce the size of the binary. I tried to debug and found that for 4.2.18 version, I must enable the SpiderMonkey flag as well.
python3 buildscripts/scons.py --help | grep debug
--separate-debug=[on|off] Produce separate debug files (only effective in
Enable SpiderMonkey debug mode
src/third_party/mozjs-60/extract/js/src/jit/VMFunctions.h:310:42: error: 'const struct js::jit::VMFunction' has no member named 'name_'
310 | MOZ_ASSERT(strcmp(f1->name_, f2->name_) == 0);
| ^~~~~
scons: building terminated because of errors.
build/opt/third_party/mozjs-60/extract/js/src/frontend/Parser.o failed: Error 1
The --separate-debug and --install-mode=hygienic features should not be used with v4.2. They are only fully supported on v4.4 and later. For your v4.2 build, you will need to manually use objcopy to separate (or strip to strip) the debug information.
@Rahul_Arora1 - That’s great, I’m happy to hear we were able to get it working.
One subtle thing that I did want to point out. You are using DESTDIR but not PREFIX. By using DESTDIR like that, you are basically requiring that your /opt/IBM/mongo-distro path be writeable by the build. That may not always be what you want. Instead, you should be able to do:
scons ... PREFIX=/opt/IBM/mongo-distro
That will create a tree within the mongodb source clone like build/install/opt/IBM/mongo-distro, without needing write permissions to the real /opt/IBM/mongo-distro, and ensure that targets like archive-core build archives that contain the prefix path opt/IBM/mongo-distro so that if you unpack them in / (presumably with sudo) they populate the directory you want.
So, that may be something to play with if you are interested.