I'm trying to call
dladdr() from Swift on Linux.
Related functions from
dlfcn.h are available in the
Glibc module, such as
dladdr() is not.
The reason for the omission is because
dladdr() requires the
_GNU_SOURCE macro to be defined, and the Clang importer does not define it on Linux.
_GNU_SOURCE is defined on Fuschia and Android though, and there is a comment in the importer suggesting why it's not enabled on Linux in general:
// Ideally we should turn this on for all Glibc targets that are actually // using Glibc or a libc that respects that flag. This will cause some // source breakage however (specifically with strerror_r()) on Linux // without a workaround.
My question is how we could turn on
_GNU_SOURCE on Linux, so I can call
The source breakage concern around
strerror_r() is real, for example this Swift package would break if
Glibc vended a version of
strerror_r() with a different signature. There are other examples to be found on GitHub.
The comment mentions a "workaround" but I can't envisage what that could be. Does anyone have any ideas?
strerror_r() the only function with source compatibility issues around
_GNU_SOURCE or are there others to consider too?