Shared-library field should never contain libasan/libubsan
When scanning a library that was compiled with sanitizers, the resulting GIR file (and typelib) list libasan and libubsan in the shared-library field. This is bad, because it means libgirepository will dlopen those libraries when looking for symbols in _g_typelib_do_dlopen()
. If this happens from an executable where libasan is linked statically (as Clang prefers to do) then the process will crash because linking both statically and dynamically to libasan in the same process is forbidden.
My guess is that libasan and libubsan should never be output in the shared-library field. But if that's not possible, then they could be skipped during searching of shared libraries in g_typelib_symbol()
.
Minimal example:
lib.c
/**
* lib_greet:
*/
const char *lib_greet(void) { return "Hello, world"; }
lib.h
#pragma once
const char *lib_greet(void);
Compile with:
gcc -fsanitize=address,undefined -c -o lib.o -fPIC lib.c
gcc -fsanitize=address,undefined -o liblib.so lib.o -fPIC -shared
g-ir-scanner --no-libtool --namespace=Lib --nsversion=0 --output Lib-0.gir -L. -lasan -lubsan --library lib lib.c lib.h
Result:
<?xml version="1.0"?>
<!-- This file was automatically generated from C sources - DO NOT EDIT!
To affect the contents of this file, edit the original C definitions,
and/or use gtk-doc annotations. -->
<repository version="1.2"
xmlns="http://www.gtk.org/introspection/core/1.0"
xmlns:c="http://www.gtk.org/introspection/c/1.0"
xmlns:glib="http://www.gtk.org/introspection/glib/1.0">
<namespace name="Lib"
version="0"
shared-library="libasan.so.6,libubsan.so.1,liblib.so"
c:identifier-prefixes="Lib"
c:symbol-prefixes="lib">
<function name="greet" c:identifier="lib_greet">
<source-position filename="lib.h" line="2"/>
<return-value transfer-ownership="none">
<type name="utf8" c:type="const char*"/>
</return-value>
</function>
</namespace>
</repository>