gcc -fsanitize=leak crashes immediately
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=
((!lsan_
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:/
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://
100 /var/lib/
ProblemType: Bug
DistroRelease: Ubuntu 20.04
Package: gcc 4:9.3.0-1ubuntu2
ProcVersionSign
Uname: Linux 5.4.0-26-generic x86_64
ApportVersion: 2.20.11-
Architecture: amd64
CasperMD5CheckR
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_
LANG=fr_FR.UTF-8
SHELL=/bin/bash
SourcePackage: gcc-defaults
UpgradeStatus: No upgrade log present (probably fresh install)
description: | updated |
Status changed to 'Confirmed' because the bug affects multiple users.