Search code examples
yocto

Error undefined hidden symbol `__dso_handle' can not be used when making a shared object


Yocto 3.4 failed at the glibc 2.34 compilation.

I think that the error happening at the linking stage:

  | /mnt/DATA/build/tmp/work/core2-64-poky-linux/glibc/2.34-r0/recipe-sysroot-native/usr/bin/x86_64-poky-linux/../../libexec/x86_64-poky-linux/gcc/x86_64-poky-linux/11.2.0/ld.bfd: /mnt/DATA/build/tmp/work/core2-64-poky-linux/glibc/2.34-r0/build-x86_64-poky-linux/malloc/libc_malloc_debug_pic.a(malloc-debug.os): in function `do_mtrace':
| /usr/src/debug/glibc/2.34-r0/git/malloc/mtrace-impl.c:201: undefined reference to `__dso_handle'
| /mnt/DATA/build/tmp/work/core2-64-poky-linux/glibc/2.34-r0/recipe-sysroot-native/usr/bin/x86_64-poky-linux/../../libexec/x86_64-poky-linux/gcc/x86_64-poky-linux/11.2.0/ld.bfd: /mnt/DATA/build/tmp/work/core2-64-poky-linux/glibc/2.34-r0/build-x86_64-poky-linux/malloc/libc_malloc_debug_pic.a(malloc-debug.os): relocation R_X86_64_PC32 against undefined hidden symbol `__dso_handle' can not be used when making a shared object
| /mnt/DATA/build/tmp/work/core2-64-poky-linux/glibc/2.34-r0/recipe-sysroot-native/usr/bin/x86_64-poky-linux/../../libexec/x86_64-poky-linux/gcc/x86_64-poky-linux/11.2.0/ld.bfd: final link failed: bad value
| collect2: error: ld returned 1 exit status
| make[2]: *** [../Makerules:536: /mnt/DATA/build/tmp/work/core2-64-poky-linux/glibc/2.34-r0/build-x86_64-poky-linux/malloc/libc_malloc_debug.so] Error 1
| make[2]: Leaving directory '/mnt/DATA/build/tmp/work/core2-64-poky-linux/glibc/2.34-r0/git/malloc'
| make[1]: *** [Makefile:498: malloc/others] Error 2
| make[1]: Leaving directory '/mnt/DATA/build/tmp/work/core2-64-poky-linux/glibc/2.34-r0/git'
| make: *** [Makefile:9: all] Error 2
| ERROR: oe_runmake failed
| WARNING: exit code 1 from a shell command.
ERROR: Task (/mnt/DATA/build/../poky/meta/recipes-core/glibc/glibc_2.34.bb:do_compile) failed with exit code '1'

Regarding "__dso_handle", it related to making shared objects.

I don't understand what is the cause of the error. Any idea can help?

The piece of code for that error:

  {
  static int added_atexit_handler;
  char *mallfile;

  /* Don't panic if we're called more than once.  */
  if (mallstream != NULL)
    return;

  mallfile = secure_getenv (mallenv);
  if (mallfile != NULL)
    {
      char *mtb = malloc (TRACE_BUFFER_SIZE);
      if (mtb == NULL)
        return;

      mallstream = fopen (mallfile != NULL ? mallfile : "/dev/null", "wce");
      if (mallstream != NULL)
        {
          /* Be sure it doesn't malloc its buffer!  */
          malloc_trace_buffer = mtb;
          setvbuf (mallstream, malloc_trace_buffer, _IOFBF, TRACE_BUFFER_SIZE);
          fprintf (mallstream, "= Start\n");
          if (!added_atexit_handler)
            {
              added_atexit_handler = 1;
              __cxa_atexit ((void (*)(void *))release_libc_mem, NULL,
                __dso_handle);
            }
      __malloc_debug_enable (MALLOC_MTRACE_HOOK);
        }
      else
        free (mtb);
    }
}

Solution

  • I tried with the definition in dso_handle.h as below:

    void *__dso_handle __attribute__((weak)) = NULL;
    

    But, it didn't work in my case.

    The error looked like comming from gcc compatibility.

    And my solution is

    I upgraded the build host's gcc version (>= 7.5.0) then cleanup and rebuild glibc. And the result is okay.