[Bug libc/25335] New: errno set by a DSO is not available to a static executable

tuliom at ascii dot art.br sourceware-bugzilla@sourceware.org
Thu Jan 2 13:49:00 GMT 2020


https://sourceware.org/bugzilla/show_bug.cgi?id=25335

            Bug ID: 25335
           Summary: errno set by a DSO is not available to a static
                    executable
           Product: glibc
           Version: 2.31
            Status: NEW
          Severity: normal
          Priority: P2
         Component: libc
          Assignee: unassigned at sourceware dot org
          Reporter: tuliom at ascii dot art.br
                CC: drepper.fsp at gmail dot com
  Target Milestone: ---

When a DSO sets errno, the value is not accessible from a static executable
because they expect errno at different addresses.

Look at the following example, where a static executable calls dlopen:

$ cat Makefile 
all: static-dlopen.test

static-dlopen: main.c errno.so
        $(CC) -static -DDLOPEN $< -ldl -o $@

errno.so: errno.c
        $(CC) -shared $< -o $@

%.test: %
        LD_LIBRARY_PATH=$(PWD) ./$(*F)

clean:
        rm -f errno.so

$ cat errno.c 
#include <errno.h>

int *
errno_addr (void)
{
  return &errno;
}

$ cat main.c 
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>

#ifdef DLOPEN
#include <dlfcn.h>

void *handle;
int * (*errno_addr) (void);

void
test_dlopen (void)
{
  handle = dlopen ("errno.so", RTLD_LAZY | RTLD_LOCAL);
  if (handle == NULL)
    {
      printf ("dlopen (errno.so): %s\n", dlerror ());
      exit (1);
    }

  errno_addr = dlsym (handle, "errno_addr");
  if (errno_addr == NULL)
    {
      printf ("dlsym (errno_addr): %s\n", dlerror ());
      exit (1);
    }

  printf("dlopen &errno = %p\n", errno_addr());

  errno_addr = NULL;
  dlclose (handle);
}
#endif

int
main ()
{
  printf("main &errno   = %p\n", &errno);
#if DLOPEN
  test_dlopen();
#endif
  return 0;
}

When running this example, we get:
main &errno   = 0x4d9840
dlopen &errno = 0x4d97a0

Reproduced on x86_64 and powerpc64le.

-- 
You are receiving this mail because:
You are on the CC list for the bug.


More information about the Glibc-bugs mailing list