Skip to content

Commit

Permalink
Mark dlsym with __attribute__((noinline)).
Browse files Browse the repository at this point in the history
In some circumstances (e.g. under higher optimization modes when
compiled with LLVM), `dlsym` gets inlined into `libvirtcpuid_init_dso`.

When this happens, dlsym's use of `__builtin_return_address(0)` no
longer returns the address of `dlsym` and instead returns the address of
`libvirtcpuid_init_dso`. When that happens, `_dl_sym` fails to find the
next `dlsym` and the process crashes.
  • Loading branch information
eatnumber1 committed Jun 25, 2021
1 parent 2ec341a commit 5de0735
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/dso_signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ static void protect_sigsegv_cpuid_handler(void)
extern void *_dl_sym (void *handle, const char *name, void *who);

static void *(*real_dlsym)(void *handle, const char *symbol);
LIB_EXPORT
LIB_EXPORT __attribute__((noinline))
void *dlsym(void *handle, const char *symbol)
{
if (!real_dlsym) {
Expand Down

0 comments on commit 5de0735

Please sign in to comment.