我如何链接到特定的glibc版本? [英] How can I link to a specific glibc version?

查看:1456
本文介绍了我如何链接到特定的glibc版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在Ubuntu Lucid 10.04 PC上编译一些内容时,它会与glibc链接。 Lucid使用2.11的glibc。当我在另一台装有旧版glibc的PC上运行这个二进制文件时,该命令失败,说没有glibc 2.11 ...

据我所知,glibc使用符号版本控制。我可以强制gcc链接到特定的符号版本吗?



在我的具体使用中,我尝试为ARM编译一个gcc交叉工具链。

解决方案

你是正确的,glibc使用符号版本。如果您好奇,glibc 2.1中引入的符号版本控制实现在此处描述,并且是扩展了Sun的符号版本控制方案 here



一个选项是静态链接您的二进制文件。这可能是最简单的选择。



您也可以在chroot构建环境中构建您的二进制文件,或者使用glibc- new => glibc - 旧的交叉编译器。根据 $ b rel =noreferrer> http://www.trevorpounds.com 博文 链接到旧的版本化符号(glibc) ,可以强制任何符号通过使用相同的 .symver 伪操作来链接旧版本,该伪操作用于定义第一名。以下示例摘自博客post>。



以下示例使用glibc的实际路径,但确保它与较旧的2.2.5版本链接。

  #include< limits.h> 
#include< stdlib.h>
#include< stdio.h>

__asm __(。symver realpath,realpath @ GLIBC_2.2.5);
int main()
{
char * unresolved =/ lib64;
char解决了[PATH_MAX + 1];

if(!realpath(unresolved,resolved))
{return 1; }

printf(%s\\\
,已解决);

返回0;
}


When I compile something on my Ubuntu Lucid 10.04 PC it gets linked against glibc. Lucid uses 2.11 of glibc. When I run this binary on another PC with an older glibc, the command fails saying there's no glibc 2.11...

As far as I know glibc uses symbol versioning. Can I force gcc to link against a specific symbol version?

In my concrete use I try to compile a gcc cross toolchain for ARM.

解决方案

You are correct in that glibc uses symbol versioning. If you are curious, the symbol versioning implementation introduced in glibc 2.1 is described here and is an extension of Sun's symbol versioning scheme described here.

One option is to statically link your binary. This is probably the easiest option.

You could also build your binary in a chroot build environment, or using a glibc-new => glibc-old cross-compiler.

According to the http://www.trevorpounds.com blog post Linking to Older Versioned Symbols (glibc), it is possible to to force any symbol to be linked against an older one so long as it is valid by using the the same .symver pseudo-op that is used for defining versioned symbols in the first place. The following example is excerpted from the blog post.

The following example makes use of glibc’s realpath, but makes sure it is linked against an older 2.2.5 version.

#include <limits.h>
#include <stdlib.h>
#include <stdio.h>

__asm__(".symver realpath,realpath@GLIBC_2.2.5");
int main()
{
    char* unresolved = "/lib64";
    char  resolved[PATH_MAX+1];

    if(!realpath(unresolved, resolved))
        { return 1; }

    printf("%s\n", resolved);

    return 0;
}

这篇关于我如何链接到特定的glibc版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆