[SERVER-18440] Can't pass -fsanitize-coverage to scons using CCFLAGS Created: 12/May/15  Updated: 01/Jun/22  Resolved: 01/Jun/22

Status: Closed
Project: Core Server
Component/s: Build
Affects Version/s: 3.1.2
Fix Version/s: Needs Further Definition

Type: Bug Priority: Major - P3
Reporter: Randolph Tan Assignee: Alex Neben
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: File config.log    
Issue Links:
Related
related to SERVER-18597 Add support for dumping ASan code cov... Closed
Operating System: ALL
Participants:

 Description   

using clang v3.6.0

scons -j12 --mute CC=/usr/local/bin/clang CXX=/usr/local/bin/clang++ CCFLAGS="-fsanitize-coverage=2" --opt=off --allocator=system --sanitize=address --variant-dir=asan mongod unittests
scons: Reading SConscript files ...
scons version: 2.3.4
python version: 2 7 4 'final' 0
Checking whether the C++ compiler works... yes
Checking whether the C compiler works... yes
Checking if C++ compiler "/usr/local/bin/clang++" is GCC... no
Checking if C++ compiler "/usr/local/bin/clang++" is clang... yes
Checking if C compiler "/usr/local/bin/clang" is clang... yes
Detected a x86_64 processor
Checking if target OS linux is supported by the toolchain yes
Checking if C compiler is clang 3.4 (or Apple XCode 5.1.1) or newer...no
Checking if C++ compiler is clang 3.4 (or Apple XCode 5.1.1) or newer...no
ERROR: Refusing to build with compiler that does not meet requirements
See /mnt/hdd/mongo-copy/build/scons/config.log for details

Attaching config.log.

Note: Hacking SConstruct to pass -fsanitize-coverage=2 manually appears to work.



 Comments   
Comment by Kamran K. [ 22/May/15 ]

The underlying issue is that the top-level SConstruct will run various configure checks before adding the sanitizer flags to support the '--sanitize=address' option. In contrast, the CCFLAGS values are passed directly to the configure checks, which leads to '-fsanitize-coverage=2' being passed without an accompanying -fsanitize=address option.

This leads to these errors in config.log: "clang: error: argument unused during compilation: '-fsanitize-coverage=2'"

Comment by Kamran K. [ 20/May/15 ]

I was able to get sanitizer coverage working with this command line:

scons -j9 CCFLAGS="-fsanitize-coverage=3 -fsanitize=address" CC=/usr/bin/clang-3.6 CXX=/usr/bin/clang++-3.6 --opt=off --allocator=system --sanitize=address --variant-dir=asan core

I haven't looked into why '-fsanitize=address' needs to be added to CCFLAGS despite --sanitize=address already being present, though.

Comment by Randolph Tan [ 13/May/15 ]

Yes. It fully compiles and based on the logs, it looks like it is being passed to clang++ as a parameter. This is the diff for the hack:

diff --git a/SConstruct b/SConstruct
index 97e6bac..7da53e3 100644
--- a/SConstruct
+++ b/SConstruct
@@ -1629,6 +1629,7 @@ def doConfigure(myenv):
         if AddToCCFLAGSIfSupported(myenv, sanitizer_option):
             myenv.Append(LINKFLAGS=[sanitizer_option])
             myenv.Append(CCFLAGS=['-fno-omit-frame-pointer'])
+            myenv.Append(CCFLAGS=['-fsanitize-coverage=2'])
         else:
             myenv.ConfError('Failed to enable sanitizers with flag: {0}', sanitizer_option )

Comment by Ernie Hershey [ 13/May/15 ]

Does it fully work when you hack SConstruct? I mean does the actual parameter get picked up and used? Or does it just not give a scons error?

Comment by Randolph Tan [ 12/May/15 ]

I am starting to suspect that -fsanitize-coverage is not actually supported in 3.6 (it's quite confusing actually, the parameter is mentioned in --help, but I can't find it in the v3.6 documentation). I also suspect that the reason why the hack did not result in an error is we might be suppressing the warning as an error.

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