Bug 28503 - dl_iterate_phdr namespace violation
Summary: dl_iterate_phdr namespace violation
Status: NEW
Alias: None
Product: glibc
Classification: Unclassified
Component: dynamic-link (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-10-27 06:23 UTC by Florian Weimer
Modified: 2021-12-28 21:55 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Florian Weimer 2021-10-27 06:23:44 UTC
The program below aborts even though it does nothing wrong. The reason is that the libgcc_s unwinder calls dl_iterate_phdr, which is not in the implementation namespace, so the application should be able to define it in a different way.

#define _POSIX_SOURCE
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>

void
dl_iterate_phdr (void)
{
  abort ();
}

static void *
thread_func (void *ignored)
{
  pthread_exit (NULL);
  return NULL;
}

int
main (void)
{
  pthread_t thr;
  if (pthread_create (&thr, NULL, thread_func, NULL) != 0)
    {
      puts ("pthread_create failed");
      return 1;
    }
  if (pthread_join (thr, NULL) != 0)
    {
      puts ("pthread_join failed");
      return 1;
    }
  return 0;
}
Comment 1 Sourceware Commits 2021-12-28 21:55:02 UTC
The master branch has been updated by Florian Weimer <fw@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=5d28a8962dcb6ec056b81d730e3c6fb57185a210

commit 5d28a8962dcb6ec056b81d730e3c6fb57185a210
Author: Florian Weimer <fweimer@redhat.com>
Date:   Tue Dec 28 22:52:56 2021 +0100

    elf: Add _dl_find_object function
    
    It can be used to speed up the libgcc unwinder, and the internal
    _dl_find_dso_for_object function (which is used for caller
    identification in dlopen and related functions, and in dladdr).
    
    _dl_find_object is in the internal namespace due to bug 28503.
    If libgcc switches to _dl_find_object, this namespace issue will
    be fixed.  It is located in libc for two reasons: it is necessary
    to forward the call to the static libc after static dlopen, and
    there is a link ordering issue with -static-libgcc and libgcc_eh.a
    because libc.so is not a linker script that includes ld.so in the
    glibc build tree (so that GCC's internal -lc after libgcc_eh.a does
    not pick up ld.so).
    
    It is necessary to do the i386 customization in the
    sysdeps/x86/bits/dl_find_object.h header shared with x86-64 because
    otherwise, multilib installations are broken.
    
    The implementation uses software transactional memory, as suggested
    by Torvald Riegel.  Two copies of the supporting data structures are
    used, also achieving full async-signal-safety.
    
    Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>