【发布时间】:2014-01-04 03:54:04
【问题描述】:
出于某些原因,我试图在 GCC 中使用顶级程序集来定义一些静态函数。然而,由于 GCC 没有“看到”这些函数的主体,它警告我它们“被使用但从未定义过。一个简单的源代码示例可能如下所示:
/* I'm going to patch the jump offset manually. */
asm(".pushsection .slen,\"awx\",@progbits;"
".type test1, @function;"
"test1: jmp 0;"
".popsection;");
/* Give GCC a C prototype: */
static void test(void);
int main(int argc, char **argv)
{
/* ... */
test();
/* ... */
}
然后,
$ gcc -c -o test.o test.c
test.c:74:13: warning: ‘test’ used but never defined [enabled by default]
static void test(void);
^
如何避免这种情况?
【问题讨论】:
-
为什么不能使用
asminside函数体? -
因为我希望能有函数的地址,在几个地方使用。
-
看起来你正在重新发明dynamic linking的过程链接表
-
是的,这是我的目的之一;但这并不是说我可以在自己的系统中重用现有的 dynlinker。 :)
标签: c gcc compiler-warnings inline-assembly