C &引用;fds缓冲区太小时调用轮询”;具有链路时间优化(-flto)

C &引用;fds缓冲区太小时调用轮询”;具有链路时间优化(-flto),c,linux,sockets,gcc,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_pollWrappe

在某些旧代码的链接时突然出现此错误。我用一段非常简单的代码成功地复制了这个问题:

#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 -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);

等等


我是否遗漏了一些明显的缺陷,或者这是我的GCC中的LTO缺陷,如果是的话,我有没有办法解决它?

我没有在我的Debian/Sid/x86-64上观察到GCC缺陷,使用的是
GCC版本4.8.2(Debian 4.8.2-10)
;因此,升级到GCC 4.8.2 GCC 4.8.3(s20131212)、FreeBSD 9.2/amd64没有问题。请查看(4.8.2的发行说明)<代码>链路时间优化(LTO)改进:LTO分区已重写,以提高可靠性和可维护性。导致链接失败的几个重要错误已经修复。非常好,我将在以后的GCC上尝试,如果问题消失,我想我可以在代码中对其进行注释,不再担心使用特定版本编译:)
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);