gcc -fsanitize=leak crashes immediately

Bug #2038386 reported by Alexandre Ferrieux
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
gcc-defaults (Ubuntu)
Confirmed
Undecided
Unassigned

Bug Description

The Leak Sanitizer in the gcc version bundled with Ubuntu 20.04.6 LTS has a fatal issue that makes the compiled program crash immediately (even before main()) with:

  ==28797==Sanitizer CHECK failed: ../../../../src/libsanitizer/lsan/lsan_interceptors.cpp:53
  ((!lsan_init_is_running)) != (0) (0, 0)

This can be exercised even with a trivial program like this one:

  #include <stdio.h>
  #include <stdlib.h>

  int main(int argc,char **argv)
  {
    void *x;

    x=malloc(1789);
    printf("Hey I managed to allocate pointer %p !!!\n",x);
    free(x);

    exit(0);
  }

compiled with

  gcc -fsanitize=leak foo.c

Then executing "./a.out" yields the above error.

The root cause is an unwarranted assumption that "dlopen() calls only calloc()".
Specific code in liblsan.so allows to solve the chicken-and-egg problem between "dlopen calls calloc" and "instrumenting calloc needs dlopen", and thanks to this, __lsan_init() can then heavily call dlopen(). However, no such thing is done for malloc(), which nowadays is also called by dlopen(). As a result, within __lsan_init(), an unprotected malloc() is called by dlopen(), yielding an assert (as the instrumented malloc refuses execution during init).

The initial detection, analysis and (brutal) workaround are documented here:
https://github.com/magma/magma/issues/15279#issuecomment-1742247833

This bug has been fixed in gcc11+ (by reimplementation of a clean dlopen-specific allocator), but not in gcc9 or gcc10 (which are EOS).
The consequence is that gcc -fsanitize=leak is unusable on 20.04.6 LTS.

---

Description: Ubuntu 20.04.6 LTS
Release: 20.04

gcc:
  Installed: 4:9.3.0-1ubuntu2
  Candidate: 4:9.3.0-1ubuntu2
  Version table:
 *** 4:9.3.0-1ubuntu2 500
        500 http://fr.archive.ubuntu.com/ubuntu focal/main amd64 Packages
        100 /var/lib/dpkg/status

ProblemType: Bug
DistroRelease: Ubuntu 20.04
Package: gcc 4:9.3.0-1ubuntu2
ProcVersionSignature: Ubuntu 5.4.0-26.30-generic 5.4.30
Uname: Linux 5.4.0-26-generic x86_64
ApportVersion: 2.20.11-0ubuntu27.27
Architecture: amd64
CasperMD5CheckResult: skip
Date: Tue Oct 3 23:51:25 2023
InstallationDate: Installed on 2023-06-22 (103 days ago)
InstallationMedia: Ubuntu 20.04.6 LTS "Focal Fossa" - Release amd64 (20230316)
ProcEnviron:
 TERM=xterm
 PATH=(custom, no user)
 XDG_RUNTIME_DIR=<set>
 LANG=fr_FR.UTF-8
 SHELL=/bin/bash
SourcePackage: gcc-defaults
UpgradeStatus: No upgrade log present (probably fresh install)

Revision history for this message
Alexandre Ferrieux (ferrieuxa) wrote :
description: updated
Revision history for this message
Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in gcc-defaults (Ubuntu):
status: New → Confirmed
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.