错误未定义的隐藏符号`__dso_handle'创建共享对象时不能使用

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

Yocto 3.4 在 glibc 2.34 编译时失败。

我认为链接阶段发生的错误:

  | /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'

关于“__dso_handle”,与制作共享对象有关

我不明白错误的原因是什么。有什么想法可以帮助吗?

该错误的代码段:

  {
  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);
    }
}

我尝试使用 dso_handle.h 中的定义如下:

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

但是,它在我的情况下不起作用。

错误看起来像是来自 gcc 兼容性。

我的解决方案是

我升级了构建主机的 gcc 版本 (>= 7.5.0),然后清理并重建 glibc。结果是 okay.