2011-08-21 64 views
0

按照另一个question I had asked earlier我想我可能已经找到了我的问题,但我需要专家的眼球。是否可以重复导致编译错误的C源代码?

我发现文件/net/ipv4/tcp_zero_copy.c这导致了我的内核编译失败。

当我在C/C++编辑器中查看文件时,我对C或C++没有多少了解,它看起来像相同的代码重复了一遍(我认为是4次)。

我的问题很简单;

这足以导致编译器出现问题吗?如果相同的代码在同一个文件中反复出现?

这是该文件的源代码(总共148行,从头到尾);

/* 
* Support routines for TCP zero copy transmit 
* 
* Created by Vladislav Bolkhovitin 
* 
* This program is free software; you can redistribute it and/or 
*  modify it under the terms of the GNU General Public License 
*  version 2 as published by the Free Software Foundation. 
*/ 

#include <linux/skbuff.h> 

net_get_page_callback_t net_get_page_callback __read_mostly; 
EXPORT_SYMBOL(net_get_page_callback); 

net_put_page_callback_t net_put_page_callback __read_mostly; 
EXPORT_SYMBOL(net_put_page_callback); 

/* 
* Caller of this function must ensure that at the moment when it's called 
* there are no pages in the system with net_priv field set to non-zero 
* value. Hence, this function, as well as net_get_page() and net_put_page(), 
* don't need any protection. 
*/ 
int net_set_get_put_page_callbacks(
    net_get_page_callback_t get_callback, 
    net_put_page_callback_t put_callback) 
{ 
    int res = 0; 

    if ((net_get_page_callback != NULL) && (get_callback != NULL) && 
     (net_get_page_callback != get_callback)) { 
     res = -EBUSY; 
     goto out; 
    } 

    if ((net_put_page_callback != NULL) && (put_callback != NULL) && 
     (net_put_page_callback != put_callback)) { 
     res = -EBUSY; 
     goto out; 
    } 

    net_get_page_callback = get_callback; 
    net_put_page_callback = put_callback; 

out: 
    return res; 
} 
EXPORT_SYMBOL(net_set_get_put_page_callbacks); 
/* 
* Support routines for TCP zero copy transmit 
* 
* Created by Vladislav Bolkhovitin 
* 
* This program is free software; you can redistribute it and/or 
*  modify it under the terms of the GNU General Public License 
*  version 2 as published by the Free Software Foundation. 
*/ 

#include <linux/skbuff.h> 

net_get_page_callback_t net_get_page_callback __read_mostly; 
EXPORT_SYMBOL(net_get_page_callback); 

net_put_page_callback_t net_put_page_callback __read_mostly; 
EXPORT_SYMBOL(net_put_page_callback); 

/* 
* Caller of this function must ensure that at the moment when it's called 
* there are no pages in the system with net_priv field set to non-zero 
* value. Hence, this function, as well as net_get_page() and net_put_page(), 
* don't need any protection. 
*/ 
int net_set_get_put_page_callbacks(
    net_get_page_callback_t get_callback, 
    net_put_page_callback_t put_callback) 
{ 
    int res = 0; 

    if ((net_get_page_callback != NULL) && (get_callback != NULL) && 
     (net_get_page_callback != get_callback)) { 
     res = -EBUSY; 
     goto out; 
    } 

    if ((net_put_page_callback != NULL) && (put_callback != NULL) && 
     (net_put_page_callback != put_callback)) { 
     res = -EBUSY; 
     goto out; 
    } 

    net_get_page_callback = get_callback; 
    net_put_page_callback = put_callback; 

out: 
    return res; 
} 
EXPORT_SYMBOL(net_set_get_put_page_callbacks); 
/* 
* Support routines for TCP zero copy transmit 
* 
* Created by Vladislav Bolkhovitin 
* 
* This program is free software; you can redistribute it and/or 
*  modify it under the terms of the GNU General Public License 
*  version 2 as published by the Free Software Foundation. 
*/ 

#include <linux/skbuff.h> 

net_get_page_callback_t net_get_page_callback __read_mostly; 
EXPORT_SYMBOL(net_get_page_callback); 

net_put_page_callback_t net_put_page_callback __read_mostly; 
EXPORT_SYMBOL(net_put_page_callback); 

/* 
* Caller of this function must ensure that at the moment when it's called 
* there are no pages in the system with net_priv field set to non-zero 
* value. Hence, this function, as well as net_get_page() and net_put_page(), 
* don't need any protection. 
*/ 
int net_set_get_put_page_callbacks(
    net_get_page_callback_t get_callback, 
    net_put_page_callback_t put_callback) 
{ 
    int res = 0; 

    if ((net_get_page_callback != NULL) && (get_callback != NULL) && 
     (net_get_page_callback != get_callback)) { 
     res = -EBUSY; 
     goto out; 
    } 

    if ((net_put_page_callback != NULL) && (put_callback != NULL) && 
     (net_put_page_callback != put_callback)) { 
     res = -EBUSY; 
     goto out; 
    } 

    net_get_page_callback = get_callback; 
    net_put_page_callback = put_callback; 

out: 
    return res; 
} 
EXPORT_SYMBOL(net_set_get_put_page_callbacks); 

**编辑**

而且我只是用记事本++到它看起来像他们结束的代码的各个块进行比较。根据比较工具全部3块互相匹配。

这是从它死亡的地方到它返回给我的命令提示符的编译器输出。

CC  net/ipv4/tcp_zero_copy.o 
net/ipv4/tcp_zero_copy.c:63:1: error: redefinition of â__kcrctab_net_get_page_callbackâ 
net/ipv4/tcp_zero_copy.c:14:1: note: previous definition of â__kcrctab_net_get_page_callbackâ was here 
net/ipv4/tcp_zero_copy.c:63:1: error: redefinition of â__kstrtab_net_get_page_callbackâ 
net/ipv4/tcp_zero_copy.c:14:1: note: previous definition of â__kstrtab_net_get_page_callbackâ was here 
net/ipv4/tcp_zero_copy.c:63:1: error: redefinition of â__ksymtab_net_get_page_callbackâ 
net/ipv4/tcp_zero_copy.c:14:1: note: previous definition of â__ksymtab_net_get_page_callbackâ was here 
net/ipv4/tcp_zero_copy.c:66:1: error: redefinition of â__kcrctab_net_put_page_callbackâ 
net/ipv4/tcp_zero_copy.c:17:1: note: previous definition of â__kcrctab_net_put_page_callbackâ was here 
net/ipv4/tcp_zero_copy.c:66:1: error: redefinition of â__kstrtab_net_put_page_callbackâ 
net/ipv4/tcp_zero_copy.c:17:1: note: previous definition of â__kstrtab_net_put_page_callbackâ was here 
net/ipv4/tcp_zero_copy.c:66:1: error: redefinition of â__ksymtab_net_put_page_callbackâ 
net/ipv4/tcp_zero_copy.c:17:1: note: previous definition of â__ksymtab_net_put_page_callbackâ was here 
net/ipv4/tcp_zero_copy.c:74:5: error: redefinition of ânet_set_get_put_page_callbacksâ 
net/ipv4/tcp_zero_copy.c:25:5: note: previous definition of ânet_set_get_put_page_callbacksâ was here 
net/ipv4/tcp_zero_copy.c:98:1: error: redefinition of â__kcrctab_net_set_get_put_page_callbacksâ 
net/ipv4/tcp_zero_copy.c:49:1: note: previous definition of â__kcrctab_net_set_get_put_page_callbacksâ was here 
net/ipv4/tcp_zero_copy.c:98:1: error: redefinition of â__kstrtab_net_set_get_put_page_callbacksâ 
net/ipv4/tcp_zero_copy.c:49:1: note: previous definition of â__kstrtab_net_set_get_put_page_callbacksâ was here 
net/ipv4/tcp_zero_copy.c:98:1: error: redefinition of â__ksymtab_net_set_get_put_page_callbacksâ 
net/ipv4/tcp_zero_copy.c:49:1: note: previous definition of â__ksymtab_net_set_get_put_page_callbacksâ was here 
make[2]: *** [net/ipv4/tcp_zero_copy.o] Error 1 
make[1]: *** [net/ipv4] Error 2 
make: *** [net] Error 2 
[email protected]:/usr/src/linux# ls 
+0

直接的答案是肯定的,这是一个问题。更有趣的答案将是这个问题发生的原因或方式。 –

+0

@Solignis:这是哪个版本的内核? (完整版,包括平台,操作系统等) –

回答

1

这取决于被重复什么,

函数声明重复不会给任何错误。
重复的函数定义会给出错误。
正在创建\定义为相同名称的变量会给出错误。

#2 & #3给出错误,因为他们打破了ODR(一个定义规则)。

void doSomething(); //no error 
void doSomething(); 
void doSomething(); 

void doSomething() 
{ 

} 

int main() 
{ 
    int i; //error 
    int i; 
    doSomething(); 
    return 1; 
} 

在此代码:

net_get_page_callback_t net_get_page_callback __read_mostly; 

限定可变的,并且这样做多次,导致相同的命名变量的多个定义,因而重定义错误。

+0

所以它们是多余的?所以删除它们并保持代码块#1?一切都应该好? – ianc1215

+0

@Solignis:是的,他们是简化版,也许有人在代码中不小心复制了粘贴的代码块? –

+0

是啊不知道如何可以通过。无论如何希望它会在这次工作。 – ianc1215

1

函数在翻译单元中被多次定义是错误的。这是发生在这里的事情。尝试发布编译中的前几个错误消息。

+0

我从它死亡的地方添加了输出。 – ianc1215

+0

是的,错误消息证实了这一点。 –

相关问题