【发布时间】:2011-02-08 16:51:41
【问题描述】:
我收到链接时间错误:
WARNING: /home/gulevich/development/camac-fedorov/camac/linux/k0607-lsi6/camac-k0607-lsi6.o (.ctors): unexpected non-allocatable section.
Did you forget to use "ax"/"aw" in a .S file?
Note that for example <linux/init.h> contains
section definitions for use in .S files.
导致错误的代码(C 源代码中的汇编):
# if defined(__ELF__)
# define __SECTION_FLAGS ", \"aw\" , @progbits"
/* writable flag needed for ld ".[cd]tors" sections bug workaround) */
# elif defined(__COFF__)
# define __SECTION_FLAGS ", \"dr\""
/* untested, may be writable flag needed */
# endif
asm
(
".section .ctors" __SECTION_FLAGS "\n"
".globl __ctors_begin__\n"
"__ctors_begin__:\n"
".previous\n"
);
有没有办法解决这个问题?这个想法是在某个内存部分的开头放置一个变量__ctors_begin__。此代码是遗留代码,使用不同的构建系统和较旧的编译器可以正常工作。
an answer to my previous question 中解释的这个汇编代码的含义。
【问题讨论】:
-
你使用的是什么 C 编译器?
-
作为补充说明,您发布的确切代码在 64 位 ubuntu 上的 GCC 4.4.1 中编译得很好
-
这是链接时错误,而不是编译时错误。以下是版本信息:链接器:GNU ld (GNU Binutils for Debian) 2.20.1-system.20100303;编译器:gcc (Debian 4.4.2-9) 4.4.3 20100108(预发行版)。