[Bug sanitizer/84250] Symbol collision when using both Address and Undefined Behavior sanitizers (-fsanitize=address,undefined)

chefmax at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Thu Dec 23 04:05:06 GMT 2021


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84250

chefmax at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |WAITING

--- Comment #12 from chefmax at gcc dot gnu.org ---
> If you're not planning to get back to this then I think it'd be good to
> unassign.  I don't know whom we would reassign this to at this point.

Ok, I'm unassigning this now because I can't guarantee prompt reaction/updates.

Meanwhile, I found the reason why option 1) was reverted (explained by Jakub):
https://gcc.gnu.org/pipermail/gcc-patches/2018-July/501921.html

> the 1) variant is actually not a good idea, it will not work properly anyway
> if you link one library with -fsanitize=undefined and another library
> with -fsanitize=address, the right solution is to make the two libraries
> coexist sanely

If we want to follow this way, we may need to introduce something like
libsanitizer_common.so but this may also require pushing some patches in LLVM
upstream.

And just in case, let me post the variant 2) fix here, just to have a
reference:

diff --git a/libsanitizer/sanitizer_common/sanitizer_file.cpp
b/libsanitizer/sanitizer_common/sanitizer_file.cpp
index 5492560df91..c7013166ef6 100644
--- a/libsanitizer/sanitizer_common/sanitizer_file.cpp
+++ b/libsanitizer/sanitizer_common/sanitizer_file.cpp
@@ -27,7 +27,8 @@ void CatastrophicErrorWrite(const char *buffer, uptr length)
{
 }

 StaticSpinMutex report_file_mu;
-ReportFile report_file = {&report_file_mu, kStderrFd, "", "", 0};
+SANITIZER_INTERFACE_ATTRIBUTE ReportFile report_file = {&report_file_mu,
+                                                        kStderrFd, "", "", 0};

 void RawWrite(const char *buffer) {
   report_file.Write(buffer, internal_strlen(buffer));
diff --git a/libsanitizer/sanitizer_common/sanitizer_file.h
b/libsanitizer/sanitizer_common/sanitizer_file.h
index 3d7916171c1..0ce1f417030 100644
--- a/libsanitizer/sanitizer_common/sanitizer_file.h
+++ b/libsanitizer/sanitizer_common/sanitizer_file.h
@@ -47,7 +47,7 @@ struct ReportFile {
  private:
   void ReopenIfNecessary();
 };
-extern ReportFile report_file;
+extern SANITIZER_INTERFACE_ATTRIBUTE ReportFile report_file;

 enum FileAccessMode {
   RdOnly,
diff --git a/libsanitizer/ubsan/ubsan_init.cpp
b/libsanitizer/ubsan/ubsan_init.cpp
index 9931d85bf40..042026fee8d 100644
--- a/libsanitizer/ubsan/ubsan_init.cpp
+++ b/libsanitizer/ubsan/ubsan_init.cpp
@@ -43,7 +43,13 @@ static void CommonStandaloneInit() {
   CacheBinaryName();
   InitializeFlags();
   __sanitizer::InitializePlatformEarly();
-  __sanitizer_set_report_path(common_flags()->log_path);
+
+  // GCC-specific: in case of both ASan/UBSan runtimes are present,
+  // ASan or application itself may have aleady defined report path.
+  // Do not override it when initializing UBSan.
+  if (!__sanitizer_get_report_path()) {
+    __sanitizer_set_report_path(common_flags()->log_path);
+  }
   AndroidLogInit();
   InitializeCoverage(common_flags()->coverage, common_flags()->coverage_dir);
   CommonInit();


More information about the Gcc-bugs mailing list