C编译:重定位被截断以适合R_X86_64_PC32针对符号 [英] C compiling: relocation truncated to fit R_X86_64_PC32 against symbol

查看:138
本文介绍了C编译:重定位被截断以适合R_X86_64_PC32针对符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

/* my program
   author/date:  me/now
*/

# include <stdio.h>

# define XX    1000
# define YY    20000       /* value of 1000 is ok */
# define ZZ    6000

/* global variable declaration */

int some_variable_this;
int some_variable_that;
double data[XX][YY][ZZ];

static void some_procedure_this ( void )
{
}

static void some_procedure_that ( void )
{
}

int main ( int argc, char *argv[] )
{
}

编写一个快速的C程序以重新格式化某些数据.通过 gcc myprogram.c 进行编译时,如果使全局 data 数组过大,则会出现编译器错误:

writing a quick C program to reformat some data. when compiling via gcc myprogram.c if I make the global data array too large I get the compiler error:

relocation truncated to fit R_X86_64_PC32 against symbol 'some_variable_this'
relocation truncated to fit R_X86_64_PC32 against symbol 'some_variable_that'

我的目标是做一个快速的C代码来重新格式化一些数据.

My goal is to do a quick c code to reformat some data.

  • R_X86_64_PC32 是什么意思?
  • 有没有可以用来解决这个问题的编译器标志?
  • 在使用C语言编写此代码的同时,还能保持编写代码的快速性和易读性的更好方法吗?

如果有必要,请在Linux上的gcc 4.3.4上使用.

this on gcc 4.3.4 in linux if it matters.

推荐答案

  • 这R_X86_64_PC32是什么意思?

这是用于x86_64的ELF中使用的ELF重定位类型.这种特殊类型表示,参考数据的位置是根据与程序计数器相关的地址的32位偏移量计算得出的.我将诊断解释为表明所需的偏移量太大而无法容纳所提供的32位,这意味着编译器生成的代码实际上在链接器中无法正确链接.

It is an ELF relocation type used in ELF for x86_64. This particular type expresses that the location of the referenced data is computed based on a 32-bit offset from the an address related to the program counter. I interpret the diagnostics to indicate that the needed offsets are too large to fit in the provided 32 bits, which means that the compiler generated code that, in practice, the linker wasn't able to link correctly.

  • 有没有可以用来解决这个问题的编译器标志?

也许.基本问题是您定义的对象大于编译器作者(当时)想象的任何人都可以容纳的对象.您已经超出了其设计限制.

Maybe. The basic problem is that you've defined an object that is larger than the authors of your compiler imagined (at the time) that anyone would be able to accommodate. You're going beyond its design limits.

有些选项可以减轻这种影响.特别是,您可以尝试旋转 -fPIC 和/或 -fPIE 选项,并且可能还有其他选项.

There may be options that would mitigate this effect. In particular, you could try twiddling the -fPIC and / or -fPIE options, and there may be others.

  • 在使用C语言编写此代码的同时,还能保持编写代码的快速性和易读性的更好方法吗?

这本身不是C问题, 是实现问题.然而,就语言标准而言,GCC并没有错或错误-该标准并不强制实现接受所有可能在技术上有效的程序.

It's not a C problem per se, it's an implementation problem. Yet GCC is not wrong or faulty here as far as the language standard is concerned -- the standard does not obligate implementations to accept every possible program that is technically valid.

话虽如此,您也可以尝试在 data some_variable_this some_variable_that 的声明移动>.可以想象,它也可能有助于声明这些变量 static 或将它们(或 data )移动到单独的共享库中.

With that said, you could also try moving the declarations of some_variable_this and some_variable_that after the declaration of data. Conceivably, it might also help to declare those variables static, or to move them (or data) to a separate shared library.

这篇关于C编译:重定位被截断以适合R_X86_64_PC32针对符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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