gcc/ld - 使用 glibc.2.6 中的 __isoc99_sscanf@@GLIBC_2.7 符号创建一个新的 libc.so

发布于 2024-09-18 06:30:41 字数 848 浏览 2 评论 0原文

我有一个应用程序,当我尝试运行它时出现错误:

/lib/libc.so.6: version `GLIBC_2.7' not found

但它需要 glibc 2.7 的唯一符号是

__isoc99_sscanf@@GLIBC_2.7 

我想编写一个小型单个函数“库”,并使用此符号作为 __sscanf() 的别名

我该怎么办这个与 gcc/ld 一起吗?

我的变体不被接受,因为“@@”符号

 int __isoc99_sscanf@@GLIBC_2.7(const char *, const char *, ...) __attribute__((alias("__sscanf")));

是我的第二个变体,

#include <stdarg.h>
int __isoc99_sscanf1(const char *a, const char *b, va_list args)
{
   int i;
   va_list ap;
   va_copy(ap,args);
   i=sscanf(a,b,ap);
   va_end(ap);
   return i;
}

   // __asm__(".symver __isoc99_sscanf,__isoc99_sscanf@@GLIBC_2.7");
    __asm__(".symver __isoc99_sscanf1,__isoc99_sscanf@@GLIBC_2.7");

但它以链接器的“未找到符号 __isoc99_sscanf@@GLIBC_2.7 的版本节点”错误结束。

I have an application, which does a error when I try to run it:

/lib/libc.so.6: version `GLIBC_2.7' not found

But the only symbol it needs from glibc 2.7 is

__isoc99_sscanf@@GLIBC_2.7 

I want to write a small single function "library" with this symbol as alias to __sscanf()

How can I do this with gcc/ld?

My variant is not accepted because "@@" symbols

 int __isoc99_sscanf@@GLIBC_2.7(const char *, const char *, ...) __attribute__((alias("__sscanf")));

second my variant is

#include <stdarg.h>
int __isoc99_sscanf1(const char *a, const char *b, va_list args)
{
   int i;
   va_list ap;
   va_copy(ap,args);
   i=sscanf(a,b,ap);
   va_end(ap);
   return i;
}

   // __asm__(".symver __isoc99_sscanf,__isoc99_sscanf@@GLIBC_2.7");
    __asm__(".symver __isoc99_sscanf1,__isoc99_sscanf@@GLIBC_2.7");

but it ends with "version node not found for symbol __isoc99_sscanf@@GLIBC_2.7" error from linker.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

べ繥欢鉨o。 2024-09-25 06:30:41

您的第二个版本使用此脚本:

GLIBC_2.7 {
 global: __isoc99_sscanf;
 local: *;
};

使用 -Wl,--version-script=script.txt,但是,我不知道如何访问原始 sscanf@GLIBC_2.4< /代码>。

不管怎样,也许你想使用 -D_GNU_SOURCE 来代替;完全避免 __isoc99_sscanf

Your second version works with this script:

GLIBC_2.7 {
 global: __isoc99_sscanf;
 local: *;
};

Using -Wl,--version-script=script.txt, however, I don't know how to access the original sscanf@GLIBC_2.4.

Anyway, perhaps you would want to use -D_GNU_SOURCE instead; to avoid __isoc99_sscanf altogether.

单调的奢华 2024-09-25 06:30:41

我发现@felipec的回答非常有帮助。此外,我们的应用程序必须使用 ocaml 进行一些动态链接,我们发现给定的脚本不适用于此场景,因为它使应用程序仅将 __isoc99_sscanf 符号导出为全局符号。

GLIBC_2.7 {
 global: *;
};

上面的脚本解决了这个问题并允许 ocaml 的动态链接器正常工作。单独使用 -D_GNU_SOURCE 选项不足以避免此问题,因为对 GLIBC_2.7 的依赖来自我们静态链接的预构建二进制文件。

I found @felipecs answer very helpful. In addition our application had to do some dynamic linking using ocaml, and we found that the given script doesn't work for this scenario, since it makes the application only export the __isoc99_sscanf symbol as a global.

GLIBC_2.7 {
 global: *;
};

the above script resolves this issue and allows ocaml's dynamic linker to work properly. using the -D_GNU_SOURCE option alone wasn't enough to avoid this issue since the dependency on GLIBC_2.7 came from a prebuilt binary we were statically linking with.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文