“使用fds缓冲区调用的轮询太小”,链接时间优化(-flto)

时间:2014-01-05 03:48:27

标签: c linux sockets gcc

在某些旧代码的链接时突然开始出现此错误。我设法用一个非常简单的代码片段来复制问题:

#include <poll.h>
#include <stdio.h>

typedef struct
{
    struct pollfd m_fds[6000];
    nfds_t m_count;
} PollWrapper;
static PollWrapper g_pollWrapper;

int main()
{
    return poll(g_pollWrapper.m_fds, g_pollWrapper.m_count, 0);
}

没有-flto编译就可以了。

gcc -Wall -O3 -o poll.exe poll.c # gcc 4.8.1-10ubuntu9
# successful

但添加-flto会在链接时导致错误:

gcc -Wall -O3 -flto -o poll.exe poll.c # gcc 4.8.1-10ubuntu9
# error
gcc -Wall -O3 -flto -o poll.o -o poll.c
# compilation is fine
gcc -Wall -O3 -flto -o poll.exe poll.o
# linking fails

/usr/include/x86_64-linux-gnu/bits/poll2.h: In function `main`:
/usr/include/x86_64-linux-gnu/bits/poll2.h:41:2: warning: call to `__poll_chk_warn` > declared with attribute warning: poll called with fds buffer too small file nfds entries [enabled by default]
 return __poll_chk (__fds, __nfds, __timeout, __bos (__fds));
 ^

阅读了相关问题后,我尝试显式启用和禁用链接器插件,但都没有任何效果。

这只会出现在数组中,以下都不会出现同样的问题:

struct pollfd f;
int numfds = poll(&f, g_pollWrapper.m_size, duration);

struct pollfd fds[6000];
int numfds = poll(&f, g_pollWrapper.m_size, duration);

我是否遗漏了一些明显的东西,或者这是我的海湾合作委员会中的LTO缺陷,如果有,我有办法解决它吗?

0 个答案:

没有答案