[SERVER-69841] ASAN builds on evergreen virtual workstation (gcc only) Created: 20/Sep/22  Updated: 02/Feb/24

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

Type: Improvement Priority: Major - P3
Reporter: Billy Donahue Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: workstations
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Assigned Teams:
Build
Participants:

 Description   

shm_open and shm_unlink are in library -lrt.
When ASAN is enabled, the Scons openssl configuration stage needs libasan, which needs librt, which isn't in the link for that tiny C probe program.

If I add LIBS=rt to my scons line, I can build executables.
Unfortunately those executables can't run because asan is complaining that it needs libasan to be first in the dynamic link order or something. Still drilling into that.

But it looks like we can't quite make asan executables out of the box, and we intend to be able to do that. Just running them on Evergreen isn't sufficient for debugging.

$ uname -a
Linux ip-10-122-8-67 5.4.0-1084-aws #91~18.04.1-Ubuntu SMP Sun Aug 14 01:24:43 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
 
 
$ /home/ubuntu/mongo-dev/work/mongo-vscode/python3-venv/bin/python3 buildscripts/scons.py VARIANT_DIR=dynamic_gcc_asan MONGO_GIT_HASH=unknown LLVM_SYMBOLIZER=/opt/mongodbtoolchain/v3/bin/llvm-symbolizer --opt=on CCACHE=ccache ICECC=icecc --ninja=enabled VERBOSE=1 --link-model=dynamic --variables-files=etc/scons/mongodbtoolchain_stable_gcc.vars --sanitize=address --allocator=system --modules=enterprise generate-ninja
 
file /home/ubuntu/mongo-dev/work/mongo-vscode/SConstruct,line 4576:
        Configure(confdir = build/scons/dynamic_gcc_asan/sconf_temp)
scons: Configure: Checking for SSLeay_version(0) in C library crypto... 
build/scons/dynamic_gcc_asan/sconf_temp/conftest_d6743137aeb7fb2674cc9632f9989034_0.c <-
  |
  |
  |#include "openssl/crypto.h"
  |
  |int
  |main() {
  |  SSLeay_version(0);
  |return 0;
  |}
  |
/opt/mongodbtoolchain/v3/bin/gcc -o build/scons/dynamic_gcc_asan/sconf_temp/conftest_d6743137aeb7fb2674cc9632f9989034_0.o -c -std=c11 -Werror -ffp-contract=off -fasynchronous-unwind-tables -ggdb -Wall -Wsign-compare -Wno-unknown-pragmas -Winvalid-pch -fno-omit-frame-pointer -fno-strict-aliasing -O2 -march=sandybridge -mtune=generic -mprefer-vector-width=128 -Wno-unused-local-typedefs -Wno-unused-function -Wno-deprecated-declarations -Wno-unused-const-variable -Wno-unused-but-set-variable -Wno-missing-braces -fstack-protector-strong -fsanitize=address -fno-omit-frame-pointer -Wa,--nocompress-debug-sections -fno-builtin-memcmp -fPIE -DMONGO_USE_VISIBILITY -DNDEBUG -D_XOPEN_SOURCE=700 -D_GNU_SOURCE -DADDRESS_SANITIZER -D_FORTIFY_SOURCE=2 build/scons/dynamic_gcc_asan/sconf_temp/conftest_d6743137aeb7fb2674cc9632f9989034_0.c
/opt/mongodbtoolchain/v3/bin/gcc -o build/scons/dynamic_gcc_asan/sconf_temp/conftest_d6743137aeb7fb2674cc9632f9989034_0_49a9d12433e36832ac7cd10084eabe88 -Wl,--fatal-warnings -Wl,--no-as-needed -pthread -Wl,-z,now -fuse-ld=gold -fstack-protector-strong -fsanitize=address -pie -rdynamic build/scons/dynamic_gcc_asan/sconf_temp/conftest_d6743137aeb7fb2674cc9632f9989034_0.o -lm -lresolv -ldl -lcrypto
/opt/mongodbtoolchain/revisions/549e9c72ce95de436fb83815796d54a47893c049/stow/gcc-v3.ePh/lib/gcc/x86_64-mongodb-linux/8.5.0/libasan.a(sanitizer_posix_libcdep.o):function __sanitizer::GetNamedMappingFd(char const*, unsigned long): error: undefined reference to 'shm_open'
/opt/mongodbtoolchain/revisions/549e9c72ce95de436fb83815796d54a47893c049/stow/gcc-v3.ePh/lib/gcc/x86_64-mongodb-linux/8.5.0/libasan.a(sanitizer_posix_libcdep.o):function __sanitizer::GetNamedMappingFd(char const*, unsigned long): error: undefined reference to 'shm_unlink'
collect2: error: ld returned 1 exit status
scons: Configure: no



 Comments   
Comment by Alex Neben [ 06/Dec/23 ]

My opinion is this is a lower priority since we already have sanitizers with clang. Opinions?

Comment by Daniel Moody [ 20/Sep/22 ]

Here is a small diff to put the rt library in the link line from the conf check before doing the openssl conf checks:

(venv) Sep.20 03:35 ubuntu[mongo2]: git diff
diff --git a/SConstruct b/SConstruct
index a2029692872..0b318827ad8 100755
--- a/SConstruct
+++ b/SConstruct
@@ -4582,6 +4582,14 @@ def doConfigure(myenv):
 
     libdeps.setup_conftests(conf)
 
+    if posix_system:
+        conf.env.SetConfigHeaderDefine("MONGO_CONFIG_HAVE_HEADER_UNISTD_H")
+        if myenv.ToolchainIs('gcc') and 'address' in get_option('sanitize').split(','):
+            conf.CheckLib('rt', autoadd=True)
+        else:
+            conf.CheckLib('rt')
+        conf.CheckLib('dl')
+
     ### --ssl checks
     def checkOpenSSL(conf):
         sslLibName = "ssl"
@@ -4905,10 +4913,7 @@ def doConfigure(myenv):
                     [boostlib + suffix for suffix in boostSuffixList],
                     language='C++',
                 )
-    if posix_system:
-        conf.env.SetConfigHeaderDefine("MONGO_CONFIG_HAVE_HEADER_UNISTD_H")
-        conf.CheckLib('rt')
-        conf.CheckLib('dl')
+
 
     if posix_monotonic_clock:
         conf.env.SetConfigHeaderDefine("MONGO_CONFIG_HAVE_POSIX_MONOTONIC_CLOCK")

Comment by Billy Donahue [ 20/Sep/22 ]

switching from GCC to Clang fixes the problems, btw.

Generated at Thu Feb 08 06:14:35 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.