[SERVER-49322] Evaluate feasibility and impact of enabling -fvisibility-inlines-hidden or -fvisibility=hidden Created: 07/Jul/20  Updated: 27/Oct/23  Resolved: 27/Oct/23

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

Type: New Feature Priority: Major - P3
Reporter: Andrew Morrow (Inactive) Assignee: [DO NOT ASSIGN] Backlog - Server Development Platform Team (SDP) (Inactive)
Resolution: Won't Do Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
Related
related to SERVER-55130 Evaluate feasibility and impact of bu... Closed
is related to SERVER-68140 Expose object_check.h to query_analys... Closed
Assigned Teams:
Server Development Platform
Backwards Compatibility: Fully Compatible
Participants:

 Description   

Building with -fvisibility-inlines-hidden results in a significantly faster startup time for a dynamically linked build. It also results in a smaller text segment. However, it is not entirely without consequence: it can mean that the address of inline functions cannot be compared across DSOs. We should undertake to understand whether the consequences are acceptable in light of the performance impact.

See https://gcc.gnu.org/wiki/Visibility for more details.



 Comments   
Comment by Spencer Jackson [ 29/Sep/22 ]

andrew.morrow@mongodb.com, I described and fixed the regression in SERVER-68140, which I've linked to this ticket.

Comment by Andrew Morrow (Inactive) [ 29/Sep/22 ]

spencer.jackson@mongodb.com - Was the regression fixed? I'm interested in seeing what caused it and what the fix was.

Comment by Spencer Jackson [ 19/Jul/22 ]

I took some super informal notes on the impact of fvisibility-inlines-hidden on binary startup time, to justify whether I should to fix a recent regression which broke compilation with the flag. My notes are inlined below:

*** 2022-07-19 Tuesday
**** 13:06 Notes on mongod optimization
 
Test command : time ./build/ninja/install/bin/mongod --help
 
autoninja definition:
alias autoninja='python ./buildscripts/scons.py --opt=on --dbg=on --variables-files=etc/scons/developer_versions.vars --variables-files=etc/scons/mongodbtoolchain_v4_clang.vars --link-model=dynamic --build-tools=next --ninja generate-ninja ICECC=icecc CCACHE=/opt/mongodbtoolchain/v4/bin/ccache CCFLAGS="-Wa,--compress-debug-sections -gsplit-dwarf -fvisibility-inlines-hidden" --linker=lld LINKFLAGS="-Wl,-O2 -Wl,--icf=safe -Wl,--hash-style=gnu" VARIANT_DIR=ninja MONGO_GIT_HASH="unknown"'
 
***** Test 1 
"autoninja" plus patch
 
real    0m1.422s
user    0m1.367s
sys     0m0.036s
 
real    0m1.403s
user    0m1.346s
sys     0m0.040s
 
real    0m1.399s
user    0m1.349s
sys     0m0.032s
 
***** Test 2
"autoninja" no patch
 
```
[407/628 ( 64%) 4.691s] Linked build/ninja/mongo/db/modules/enterprise/src/fle/query_analysis/libquery_analysis.so
FAILED: build/ninja/mongo/db/modules/enterprise/src/fle/query_analysis/libquery_analysis.so
export CCACHE_NOCPP2='1';export CCACHE_PREFIX='/home/ubuntu/mongo/build/scons/icecream/ninja/run-icecc.sh';export ICECC_CLANG_REMOTE_CPP='1';export PATH='/opt/mongodbtoolchain/v4/bin:/usr/local/bin:/opt/bin:/bin:/usr/bin';/usr/bin/icerun /opt/mongodbtoolchain/v4/bin/clang++ @build/ninja/mongo/db/modules/enterprise/src/fle/query_analysis/libquery_analysis.so.rsp
ld.lld: error: undefined symbol: mongo::Validator<mongo::BSONObj>::validateLoad(char const*, unsigned long)
>>> referenced by data_type_validated.h:102 (src/mongo/base/data_type_validated.h:102)
>>>               build/ninja/mongo/db/modules/enterprise/src/fle/query_analysis/query_analysis.dyn.o:(mongo::StatusWith<mongo::Validated<mongo::BSONObj> > mongo::ConstDataRangeCursor::readAndAdvanceNoThrow<mongo::Validated<mongo::BSONObj> >())
clang-12: error: linker command failed with exit code 1 (use -v to see invocation)
[416/628 ( 66%) 4.790s] Linked build/ninja/mongo/db/repl/libtenant_migration_utils.so
```
 
***** Test 3
python ./buildscripts/scons.py --opt=on --dbg=on --variables-files=etc/scons/developer_versions.vars --variables-files=etc/scons/mongodbtoolchain_v4_clang.vars --link-model=dynamic --build-tools=next --ninja generate-ninja ICECC=icecc CCACHE=/opt/mongodbtoolchain/v4/bin/ccache CCFLAGS="-Wa,--compress-debug-sections -gsplit-dwarf" --linker=lld LINKFLAGS="-Wl,-O2 -Wl,--icf=safe -Wl,--hash-style=gnu" VARIANT_DIR=ninja MONGO_GIT_HASH="unknown"
 
real    0m1.641s
user    0m1.573s
sys     0m0.044s
 
real    0m1.664s
user    0m1.609s
sys     0m0.036s
 
real    0m1.669s
user    0m1.611s
sys     0m0.040s
 
***** Test 4
Stock.
python ./buildscripts/scons.py --opt=on --dbg=on --variables-files=etc/scons/developer_versions.vars --variables-files=etc/scons/mongodbtoolchain_v4_clang.vars --link-model=dynamic --build-tools=next --ninja generate-ninja ICECC=icecc CCACHE=/opt/mongodbtoolchain/v4/bin/ccache VARIANT_DIR=ninja MONGO_GIT_HASH="unknown"
 
real    0m1.943s
user    0m1.888s
sys     0m0.036s
 
real    0m1.978s
user    0m1.924s
sys     0m0.036s
 
real    0m1.949s
user    0m1.881s
sys     0m0.048s

Comment by Githook User [ 09/Apr/21 ]

Author:

{'name': 'Andrew Morrow', 'email': 'acm@mongodb.com', 'username': 'acmorrow'}

Message: SERVER-49322 Darwin doesn't need libunwind to use hidden visibility
Branch: master
https://github.com/mongodb/mongo/commit/7dfd7920c9cc023f88813f6146c33c7649acba1f

Comment by Githook User [ 04/Apr/21 ]

Author:

{'name': 'Andrew Morrow', 'email': 'acm@mongodb.com', 'username': 'acmorrow'}

Message: SERVER-49322 Add an experiment for building with reduced symbol visibility
Branch: master
https://github.com/mongodb/mongo/commit/ca4206b6d9da6f32ae2dca1f2170b97bc09d2272

Comment by Bruce Lucas (Inactive) [ 29/Mar/21 ]

How does this impact the quality of stack traces and symbols reported in the logs (segfaults, invariants, etc.), reported by the heap profiler, and obtained by gdb or pstack against a non-debug build in the field?

Generated at Thu Feb 08 05:19:32 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.