From ee9f479d86e45b541891860c7c4de37dbc250b0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=91=E6=B2=A7?= <1050706328@qq.com> Date: Mon, 16 Sep 2024 06:30:42 +0000 Subject: [PATCH 01/35] =?UTF-8?q?aarch=E4=B8=8B-fstack-clash-protection?= =?UTF-8?q?=E5=BC=95=E8=B5=B7=E7=9A=84-Wunused-command-line-argument?= =?UTF-8?q?=E9=94=99=E8=AF=AF.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 云沧 <1050706328@qq.com> --- ...mand-line-argument\351\224\231\350\257\257.md" | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 "LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/aarch\344\270\213-fstack-clash-protection\345\274\225\350\265\267\347\232\204-Wunused-command-line-argument\351\224\231\350\257\257.md" diff --git "a/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/aarch\344\270\213-fstack-clash-protection\345\274\225\350\265\267\347\232\204-Wunused-command-line-argument\351\224\231\350\257\257.md" "b/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/aarch\344\270\213-fstack-clash-protection\345\274\225\350\265\267\347\232\204-Wunused-command-line-argument\351\224\231\350\257\257.md" new file mode 100644 index 0000000..fe6cde6 --- /dev/null +++ "b/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/aarch\344\270\213-fstack-clash-protection\345\274\225\350\265\267\347\232\204-Wunused-command-line-argument\351\224\231\350\257\257.md" @@ -0,0 +1,15 @@ +# 1、问题现象 + +`[ 95s] clang: error: argument unused during compilation: '-fstack-clash-protection' [-Werror,-Wunused-command-line-argument]` + +# 2、问题根因分析 + +[macOS arm64 support · Issue #183 · GrapheneOS/hardened_malloc (github.com)](https://github.com/GrapheneOS/hardened_malloc/issues/183) + +参考这个Issue可知,`The issue with -fstack-clash-protection is that it's not implemented on arm64 yet.`,即aarch64下`-fstack-clash-protection`特性还未在clang中实现。因此会出现报错。 + +# 3、问题修改建议 + +不必修改。 + +openEuler社区会默认将这个error降级为warning,实际情况中不影响构建。 \ No newline at end of file -- Gitee From 5cbea52ee8cf1cd40364b66b0d64c25cdf3f27b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=91=E6=B2=A7?= <1050706328@qq.com> Date: Mon, 16 Sep 2024 06:43:42 +0000 Subject: [PATCH 02/35] =?UTF-8?q?add=20LLVM=20Parallel=20Universe=20Projec?= =?UTF-8?q?t/=E9=97=AE=E9=A2=98=E5=AE=9A=E4=BD=8D=E6=80=BB=E7=BB=93/bad=20?= =?UTF-8?q?date=20in=20%changelog=E9=97=AE=E9=A2=98.md.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 云沧 <1050706328@qq.com> --- ... in %changelog\351\227\256\351\242\230.md" | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 "LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/bad date in %changelog\351\227\256\351\242\230.md" diff --git "a/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/bad date in %changelog\351\227\256\351\242\230.md" "b/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/bad date in %changelog\351\227\256\351\242\230.md" new file mode 100644 index 0000000..9f50d08 --- /dev/null +++ "b/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/bad date in %changelog\351\227\256\351\242\230.md" @@ -0,0 +1,38 @@ +# 1、问题现象 + +`bad date in %changelog: Tue June 11 2024 jikai - 2.1.4-8` + +# 2、changelog日期写法规范 + +规范写法是: + +星期(简写) 月(简写) 日 年 名称 邮箱 - 版本 + +例如:`Tue Jun 11 2024 jikai - 2.1.4-8` + +以下是星期与月份的规范简写: + +一月:January 简写:Jan +二月:February 简写:Feb +三月:March 简写:Mar +四月:April 简写:Apr +五月:May 简写:May +六月:June 简写:Jun +七月:July 简写:Jul +八月:August 简写:Aug +九月:September 简写:Sep +十月:October 简写:Oct +十一月:November 简写:Nov +十二月:December 简写:Dec + +星期一:Monday 简写:Mon +星期二:Tuesday 简写:Tue +星期三:Wednesday 简写:Wed +星期四:Thursday 简写:Thu +星期五:Friday 简写:Fri +星期六:Saturday 简写:Sat +星期日:Sunday 简写:Sun + +# 3、修改建议 + +June改为Jun \ No newline at end of file -- Gitee From 1c7935be6f93d157f6cb80a2b8844a633263383f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=91=E6=B2=A7?= <1050706328@qq.com> Date: Mon, 16 Sep 2024 08:00:16 +0000 Subject: [PATCH 03/35] =?UTF-8?q?add=20LLVM=20Parallel=20Universe=20Projec?= =?UTF-8?q?t/=E9=97=AE=E9=A2=98=E5=AE=9A=E4=BD=8D=E6=80=BB=E7=BB=93/call?= =?UTF-8?q?=20to=20undeclared=20function=E9=97=AE=E9=A2=98.md.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 云沧 <1050706328@qq.com> --- ...lared function\351\227\256\351\242\230.md" | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 "LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/call to undeclared function\351\227\256\351\242\230.md" diff --git "a/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/call to undeclared function\351\227\256\351\242\230.md" "b/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/call to undeclared function\351\227\256\351\242\230.md" new file mode 100644 index 0000000..81ddb7f --- /dev/null +++ "b/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/call to undeclared function\351\227\256\351\242\230.md" @@ -0,0 +1,25 @@ +# 1、问题现象 + +`[ 705s] test/regress.c:3689:12: error: call to undeclared function 'event_base_start_iocp_'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]` + +`[ 705s] test/regress.c:3691:2: error: call to undeclared function 'event_base_stop_iocp_'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]` + +# 2、问题定位 + +## 2.1、问题定位分析 + +[add-testcases-for-event.c-apis.patch](https://gitee.com/src-openeuler/libevent/blob/6fd712438bafd9eafdb3cf3b3e9d66913378b2a3/add-testcases-for-event.c-apis.patch)是对regress.c的patch,该patch中调用了函数`event_base_start_iocp_`与`event_base_stop_iocp_`但忘记了#include其所在的头文件"iocp-internal.h" + +## 2.2 gcc与clang对于调用未声明函数的差异处理 + +对于调用未声明的函数,clang对于语法要求更加严格,会直接报错,而gcc则较为宽松,仅仅对其进行警告,并询问是否是要调用已包含的其他名称相近的函数 + +![gcc遇到未声明函数时的表现](https://foruda.gitee.com/images/1725034630272359183/577103f3_13034847.png "屏幕截图") + +## 2.3、问题总结及根因确认 + +[add-testcases-for-event.c-apis.patch](https://gitee.com/src-openeuler/libevent/blob/6fd712438bafd9eafdb3cf3b3e9d66913378b2a3/add-testcases-for-event.c-apis.patch)是对regress.c的patch,该patch中调用了函数`event_base_start_iocp_`与`event_base_stop_iocp_`但忘记了#include其所在的头文件"iocp-internal.h",gcc对于调用未声明函数会进行模糊处理,仅仅warning,而clang会报error + +# 3、修改建议 + +补充打一个patch,在regress.c中#include "iocp-internal.h",参考:[Fix function undeclared,incompatible pointer and parameter lack in 'add-testcases-for-event.c-apis.patch',support clang build · Pull Request !74 · src-openEuler/libevent - Gitee.com](https://gitee.com/src-openeuler/libevent/pulls/74) \ No newline at end of file -- Gitee From a7b1084d69848bfead708142a4381ce2126a5ca5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=91=E6=B2=A7?= <1050706328@qq.com> Date: Mon, 16 Sep 2024 08:04:22 +0000 Subject: [PATCH 04/35] =?UTF-8?q?add=20LLVM=20Parallel=20Universe=20Projec?= =?UTF-8?q?t/=E9=97=AE=E9=A2=98=E5=AE=9A=E4=BD=8D=E6=80=BB=E7=BB=93/call,?= =?UTF-8?q?=20expected=202,=20have=201=E9=97=AE=E9=A2=98.md.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 云沧 <1050706328@qq.com> --- ...cted 2, have 1\351\227\256\351\242\230.md" | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 "LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/call, expected 2, have 1\351\227\256\351\242\230.md" diff --git "a/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/call, expected 2, have 1\351\227\256\351\242\230.md" "b/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/call, expected 2, have 1\351\227\256\351\242\230.md" new file mode 100644 index 0000000..60bc16f --- /dev/null +++ "b/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/call, expected 2, have 1\351\227\256\351\242\230.md" @@ -0,0 +1,53 @@ +# 1、问题现象 + +```c +[ 142s] test/regress.c:3691:39: error: call, expected 2, have 1 +[ 142s] 3691 | int res = event_base_start_iocp_(base); +[ 142s] | ~~~~~~~~~~~~~~~~~~~~~~ ^ +[ 142s] ./iocp-internal.h:197:5: note: 'event_base_start_iocp_' declared here +[ 142s] 197 | int event_base_start_iocp_(struct event_base *base, int n_cpus); +[ 142s] | ^ +``` + +# 2、问题定位 + +## 2.1、问题定位分析 + +错误出处:`int res = event_base_start_iocp_(base);` + +查找`event_base_start_iocp_`函数的定义,在event.c中: + +```c +int +event_base_start_iocp_(struct event_base *base, int n_cpus) +{ +#ifdef _WIN32 + if (base->iocp) + return 0; + base->iocp = event_iocp_port_launch_(n_cpus); + if (!base->iocp) { + event_warnx("%s: Couldn't launch IOCP", __func__); + return -1; + } + return 0; +#else + return -1; +#endif +} +``` + +可见,该函数要求两个参数,而该处错误只传入了一个参数 + +![输入图片说明](https://foruda.gitee.com/images/1725034687466247382/59733cb3_13034847.png "屏幕截图") + +综合其他所有地方的用处来看,参数改为(base,0)是保险的修复方法 + +## 2.2、问题总结及根因确认 + +调用函数时,传入的参数的数量不符合预期,要求2,实际1 + +# 3、修改建议 + +使用合理的参数补全参数个数要求,即将int res = event_base_start_iocp_(base);改为int res = event_base_start_iocp_(base,0); + +参考:[Fix function undeclared,incompatible pointer and parameter lack in 'add-testcases-for-event.c-apis.patch',support clang build · Pull Request !74 · src-openEuler/libevent - Gitee.com](https://gitee.com/src-openeuler/libevent/pulls/74) \ No newline at end of file -- Gitee From f30908e4bb777840cac1fa4cf5eb3c8d7482bf53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=91=E6=B2=A7?= <1050706328@qq.com> Date: Mon, 16 Sep 2024 08:07:36 +0000 Subject: [PATCH 05/35] =?UTF-8?q?add=20=E9=94=99=E8=AF=AF=E8=B0=83?= =?UTF-8?q?=E7=94=A8=E5=AF=BC=E8=87=B4=E7=9A=84incompatible=20function=20p?= =?UTF-8?q?ointer=20types=E9=97=AE=E9=A2=98.md.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 云沧 <1050706328@qq.com> --- ... pointer types\351\227\256\351\242\230.md" | 240 ++++++++++++++++++ 1 file changed, 240 insertions(+) create mode 100644 "LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/\351\224\231\350\257\257\350\260\203\347\224\250\345\257\274\350\207\264\347\232\204incompatible function pointer types\351\227\256\351\242\230.md" diff --git "a/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/\351\224\231\350\257\257\350\260\203\347\224\250\345\257\274\350\207\264\347\232\204incompatible function pointer types\351\227\256\351\242\230.md" "b/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/\351\224\231\350\257\257\350\260\203\347\224\250\345\257\274\350\207\264\347\232\204incompatible function pointer types\351\227\256\351\242\230.md" new file mode 100644 index 0000000..6f7497b --- /dev/null +++ "b/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/\351\224\231\350\257\257\350\260\203\347\224\250\345\257\274\350\207\264\347\232\204incompatible function pointer types\351\227\256\351\242\230.md" @@ -0,0 +1,240 @@ +# 1、问题现象 + +```c +[ 140s] test/regress.c:3707:2: error: incompatible function pointer types initializing 'testcase_fn' (aka 'void (*)(void *)') with an expression of type 'void (void)' [-Wincompatible-function-pointer-types] +[ 140s] 3707 | BASIC(event_config_set_max_dispatch_interval, TT_FORK|TT_NEED_BASE), +[ 140s] | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +[ 140s] test/regress.h:105:11: note: expanded from macro 'BASIC' +[ 140s] 105 | { #name, test_## name, flags, &basic_setup, NULL } +[ 140s] | ^~~~~~~~~~~~ +[ 140s] :168:1: note: expanded from here +[ 140s] 168 | test_event_config_set_max_dispatch_interval +[ 140s] | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +[ 140s] test/regress.c:3708:2: error: incompatible function pointer types initializing 'testcase_fn' (aka 'void (*)(void *)') with an expression of type 'void (void)' [-Wincompatible-function-pointer-types] +[ 140s] 3708 | BASIC(event_config_set_num_cpus_hint, TT_FORK|TT_NEED_BASE), +[ 140s] | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +[ 140s] test/regress.h:105:11: note: expanded from macro 'BASIC' +[ 140s] 105 | { #name, test_## name, flags, &basic_setup, NULL } +[ 140s] | ^~~~~~~~~~~~ +[ 140s] :170:1: note: expanded from here +[ 140s] 170 | test_event_config_set_num_cpus_hint +[ 140s] | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +[ 140s] 2 errors generated. +``` + +# 2、问题定位 + +## 2.1、问题定位分析 + +错误定位: + +```c +struct testcase_t main_testcases[] = { ++ /* event.c api tests */ ++ BASIC(event_base_del_virtual_, TT_FORK|TT_NEED_BASE), ++ BASIC(event_deferred_cb_set_priority_, TT_FORK|TT_NEED_BASE), ++ BASIC(event_callback_init_, TT_FORK|TT_NEED_BASE), ++ BASIC(event_del_noblock, TT_FORK|TT_NEED_BASE), ++ BASIC(event_del_block, TT_FORK|TT_NEED_BASE), ++ BASIC(event_get_events, TT_FORK|TT_NEED_BASE|TT_NEED_SOCKETPAIR), ++ BASIC(event_config_set_max_dispatch_interval, TT_FORK|TT_NEED_BASE), ++ BASIC(event_config_set_num_cpus_hint, TT_FORK|TT_NEED_BASE), ++ BASIC(event_base_stop_iocp_, TT_FORK|TT_NEED_BASE), +``` + +main_testcases[]的元素类型为struct testcase_t,而struct testcase_t的定义为: + +```c +/** A single test-case that you can run. */ +struct testcase_t { + const char *name; /**< An identifier for this case. */ + testcase_fn fn; /**< The function to run to implement this case. */ + unsigned long flags; /**< Bitfield of TT_* flags. */ + const struct testcase_setup_t *setup; /**< Optional setup/cleanup fns*/ + void *setup_data; /**< Extra data usable by setup function */ +}; +``` + +错误就出现在第二个元素testcase_fn fn,其类型定义为: + +```c +typedef void (*testcase_fn)(void *); +``` + +也就是说,要求类型为void\*(void\*) + +我们再来看看BASIC是什么,他是一个宏,定义如下,同时还需要注意,与他一同定义的LEGACY宏 + +```c +#define BASIC(name,flags) \ + { #name, test_## name, flags, &basic_setup, NULL } + +#define LEGACY(name,flags) \ + { #name, run_legacy_test_fn, flags|TT_LEGACY, &legacy_setup, \ + test_## name } +``` + +我们再回来看一开始报错的地方 + +```c ++ BASIC(event_config_set_max_dispatch_interval, TT_FORK|TT_NEED_BASE), ++ BASIC(event_config_set_num_cpus_hint, TT_FORK|TT_NEED_BASE), +``` + +也就是说,问题出在函数test_event_config_set_max_dispatch_interval和test_event_config_set_num_cpus_hint的类型不符合void\*(void\*)的要求,那我们来看看这两个函数的定义: + +```c ++static void ++test_event_config_set_max_dispatch_interval(void) ++{ ++ struct event_config *cfg = NULL; ++ struct timeval tv; ++ int max_dispatch_cbs = 100; ++ int min_priority = 2; ++ ++ evutil_timerclear(&tv); ++ tv.tv_sec = 3; ++ tv.tv_usec = 0; ++ ++ cfg = event_config_new(); ++ event_config_set_max_dispatch_interval(cfg, &tv, max_dispatch_cbs, min_priority); ++ ++ tt_assert(max_dispatch_cbs == cfg->max_dispatch_callbacks); ++ tt_assert(min_priority == cfg->limit_callbacks_after_prio); ++ tt_assert(3 == cfg->max_dispatch_interval.tv_sec); ++ tt_assert(0 == cfg->max_dispatch_interval.tv_usec); ++end: ++ if (cfg) ++ event_config_free(cfg); ++} ++ ++static void ++test_event_config_set_num_cpus_hint(void) ++{ ++ struct event_config *cfg = NULL; ++ int n_cpus = 4; ++ ++ cfg = event_config_new(); ++ event_config_set_num_cpus_hint(cfg, 4); ++ tt_assert(4 == cfg->n_cpus_hint); ++end: ++ if (cfg) ++ event_config_free(cfg); ++} +``` + +可见他们的类型是void(void) + +除了这两个函数之外,其他BASIC宏传入的函数(没有被报错的)的类型例如下: + +```c ++static void ++test_event_del_noblock(void *ptr) { ++ struct basic_test_data *data = ptr; ++ struct event_base *base = data->base; ++ struct timeval tv; ++ struct event ev; ++ int count = 0; ++ int res_del = 0; ++ ++ evutil_timerclear(&tv); ++ tv.tv_usec = 10000; ++ ++ event_assign(&ev, base, -1, EV_TIMEOUT|EV_PERSIST, ++ timeout_cb, &count); ++ event_add(&ev, &tv); ++ ++ res_del = event_del_noblock(&ev); ++ tt_int_op(res_del, ==, 0); ++end: ++ ; ++} ++ +``` + +修改方法显然不能直接改参数要求,如果将void改为void*,那么凭空要求传入一个参数,显然不对,那么还有其他方法吗?我在上游社区没有发现类似的issue,然而,我们可以去找找看,对于void(void)类型的函数,上游社区是如何将其传入testcase的,我们大致看一部分: + +```c +struct testcase_t main_testcases[] = { + /* Some converted-over tests */ + { "methods", test_methods, TT_FORK, NULL, NULL }, + { "version", test_version, 0, NULL, NULL }, + BASIC(base_features, TT_FORK|TT_NO_LOGS), + { "base_environ", test_base_environ, TT_FORK, NULL, NULL }, + + BASIC(event_base_new, TT_FORK|TT_NEED_SOCKETPAIR), + BASIC(free_active_base, TT_FORK|TT_NEED_SOCKETPAIR), + + BASIC(manipulate_active_events, TT_FORK|TT_NEED_BASE), + BASIC(event_new_selfarg, TT_FORK|TT_NEED_BASE), + BASIC(event_assign_selfarg, TT_FORK|TT_NEED_BASE), + BASIC(event_base_get_num_events, TT_FORK|TT_NEED_BASE), + BASIC(event_base_get_max_events, TT_FORK|TT_NEED_BASE), + BASIC(evmap_invalid_slots, TT_FORK|TT_NEED_BASE), + + BASIC(bad_assign, TT_FORK|TT_NEED_BASE|TT_NO_LOGS), + BASIC(bad_reentrant, TT_FORK|TT_NEED_BASE|TT_NO_LOGS), + BASIC(active_later, TT_FORK|TT_NEED_BASE|TT_NEED_SOCKETPAIR|TT_RETRIABLE), + BASIC(event_remove_timeout, TT_FORK|TT_NEED_BASE|TT_NEED_SOCKETPAIR), + + /* These are still using the old API */ + LEGACY(persistent_timeout, TT_FORK|TT_NEED_BASE), + { "persistent_timeout_jump", test_persistent_timeout_jump, TT_FORK|TT_NEED_BASE, &basic_setup, NULL }, + { "persistent_active_timeout", test_persistent_active_timeout, + TT_FORK|TT_NEED_BASE|TT_RETRIABLE, &basic_setup, NULL }, + LEGACY(priorities, TT_FORK|TT_NEED_BASE), + BASIC(priority_active_inversion, TT_FORK|TT_NEED_BASE), + { "common_timeout", test_common_timeout, TT_FORK|TT_NEED_BASE|TT_RETRIABLE, + &basic_setup, NULL }, + + /* These legacy tests may not all need all of these flags. */ + LEGACY(simpleread, TT_ISOLATED), + LEGACY(simpleread_multiple, TT_ISOLATED), + LEGACY(simplewrite, TT_ISOLATED), + { "simpleclose_rw", test_simpleclose_rw, TT_FORK, &basic_setup, NULL }, + /* simpleclose */ + { "simpleclose_close", test_simpleclose, + TT_FORK|TT_NEED_SOCKETPAIR|TT_NEED_BASE, + &basic_setup, (void *)"close" }, + { "simpleclose_shutdown", test_simpleclose, + TT_FORK|TT_NEED_SOCKETPAIR|TT_NEED_BASE, + &basic_setup, (void *)"shutdown" }, +``` + + +可见,除了BASIC,有时也用LEGACY,那么什么时候用BASIC,什么时候用LEGACY呢?本人查看了上文的所有testcase中的测试函数,发现BASIC用于传入void(void*),而LEGACY用于传入void(void),全部贴上来篇幅过长,因此此处只放一个例子: + +```c +LEGACY(persistent_timeout, TT_FORK|TT_NEED_BASE) +``` + +```c +static void +test_persistent_timeout(void) +{ + struct timeval tv; + struct event ev; + int count = 0; + + evutil_timerclear(&tv); + tv.tv_usec = 10000; + + event_assign(&ev, global_base, -1, EV_TIMEOUT|EV_PERSIST, + periodic_timeout_cb, &count); + event_add(&ev, &tv); + + event_dispatch(); + + event_del(&ev); +} +``` + +## 2.2、问题总结及根因确认 + +[add-testcases-for-event.c-apis.patch](https://gitee.com/src-openeuler/libevent/blob/6fd712438bafd9eafdb3cf3b3e9d66913378b2a3/add-testcases-for-event.c-apis.patch)该patch试图增加对一些函数的testcase,对于void(void)类型的函数,正确的方法是调用LEGACY宏将函数加入测试行列,错误在于调用了BASIC宏(其用于void(void*)类型的函数) + +# 3、修改建议 + +把报错两处的BASIC改为LEGACY, + +参考:[Fix function undeclared,incompatible pointer and parameter lack in 'add-testcases-for-event.c-apis.patch',support clang build · Pull Request !74 · src-openEuler/libevent - Gitee.com](https://gitee.com/src-openeuler/libevent/pulls/74) \ No newline at end of file -- Gitee From 5b645cfadad6f7e3bcfd97f7ab644fa79302bc85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=91=E6=B2=A7?= <1050706328@qq.com> Date: Mon, 16 Sep 2024 08:35:21 +0000 Subject: [PATCH 06/35] =?UTF-8?q?autoreconf:=20command=20not=20found?= =?UTF-8?q?=E9=97=AE=E9=A2=98.md.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 云沧 <1050706328@qq.com> --- ...f: command not found\351\227\256\351\242\230.md" | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 "LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/autoreconf: command not found\351\227\256\351\242\230.md" diff --git "a/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/autoreconf: command not found\351\227\256\351\242\230.md" "b/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/autoreconf: command not found\351\227\256\351\242\230.md" new file mode 100644 index 0000000..4edc44b --- /dev/null +++ "b/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/autoreconf: command not found\351\227\256\351\242\230.md" @@ -0,0 +1,13 @@ +# 1、问题现象 + +`[ 119s] /var/tmp/rpm-tmp.PicZ3O: line 47: autoreconf: command not found` + +# 2、问题成因 + +rpm打包时使用了autoreconf命令,但是在BuildRequires中没有写该命令的软件依赖 + +# 3、修改建议 + +在spec文件的BuildRequires中添加autoconf automake libtool + +参考:[Fix function undeclared,incompatible pointer and parameter lack in 'add-testcases-for-event.c-apis.patch',support clang build · Pull Request !74 · src-openEuler/libevent - Gitee.com](https://gitee.com/src-openeuler/libevent/pulls/74) \ No newline at end of file -- Gitee From f30b204ae698bbcd89c4d62d24bc7cc9666cf1e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=91=E6=B2=A7?= <1050706328@qq.com> Date: Mon, 16 Sep 2024 08:39:23 +0000 Subject: [PATCH 07/35] =?UTF-8?q?attribute=20'visibility'=20is=20ignored,?= =?UTF-8?q?=20place=20it=20after=20"struct"=E9=97=AE=E9=A2=98.md.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 云沧 <1050706328@qq.com> --- ...ter \"struct\"\351\227\256\351\242\230.md" | 132 ++++++++++++++++++ 1 file changed, 132 insertions(+) create mode 100644 "LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/attribute 'visibility' is ignored, place it after \"struct\"\351\227\256\351\242\230.md" diff --git "a/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/attribute 'visibility' is ignored, place it after \"struct\"\351\227\256\351\242\230.md" "b/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/attribute 'visibility' is ignored, place it after \"struct\"\351\227\256\351\242\230.md" new file mode 100644 index 0000000..b140bf6 --- /dev/null +++ "b/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/attribute 'visibility' is ignored, place it after \"struct\"\351\227\256\351\242\230.md" @@ -0,0 +1,132 @@ +# 1、问题现象 + +`[ 98s] /home/abuild/rpmbuild/BUILD/lcr-v2.1.4/src/runtime/lcrcontainer.h:43:1: error: attribute 'visibility' is ignored, place it after "struct" to apply attribute to type declaration [-Werror,-Wignored-attributes]` + +# 2、问题定位 + +## 2.1、问题复现 + +小例子复现: + +### 第一种:__attribute__((visibility("default"))) struct A{...}; + +lcrcontainer_1.h + +```c +__attribute__((visibility("default"))) struct A { + int n; +}; +``` + +main.c + +```c +#include +#include "lcrcontainer_1.h" + +int main() { + struct A a={1}; + printf("%d\n",a.n); + return 0; +} +``` + +执行编译与运行命令,gcc正常,clang报错: + +```c +[root@localhost lcr]# gcc main.c -fvisibility=hidden -Werror -o gcc1.out +[root@localhost lcr]# ./gcc1.out +1 +[root@localhost lcr]# clang main.c -fvisibility=hidden -Werror -o clang1.out +In file included from main.c:2: +./lcrcontainer_1.h:1:16: error: attribute 'visibility' is ignored, place it after "struct" to apply attribute to type declaration [-Werror,-Wignored-attributes] + 1 | __attribute__((visibility("default"))) struct A { + | ^ +1 error generated. +``` + +### 第二种:struct __attribute__((visibility("default"))) A{...}; + +lcrcontainer_2.h + +```c +struct __attribute__((visibility("default"))) A { + int n; +}; +``` + +执行编译与运行命令,gcc报错,clang正常: + +```c +[root@localhost lcr]# gcc main.c -fvisibility=hidden -Werror -o gcc2.out +In file included from main.c:2: +lcrcontainer_2.h:3:1: 错误:‘visibility’属性在类型上被忽略 [-Werror=attributes] + 3 | }; + | ^ +cc1:所有的警告都被当作是错误 +[root@localhost lcr]# clang main.c -fvisibility=hidden -Werror -o clang2.out +[root@localhost lcr]# ./clang2.out +1 +``` + +### 第三种:删去__attribute__((visibility("default"))) + +lcrcontainer_3.h + +```c +#include +#include "lcrcontainer_3.h" + +int main() { + struct A a={1}; + printf("%d\n",a.n); + return 0; +} +``` + +执行编译与运行命令,gcc与clang都正常: + +```c +[root@localhost lcr]# gcc main.c -fvisibility=hidden -Werror -o gcc3.out +[root@localhost lcr]# ./gcc3.out +1 +[root@localhost lcr]# clang main.c -fvisibility=hidden -Werror -o clang3.out +[root@localhost lcr]# ./clang3.out +1 +``` + +## 2.2、关于attribute 'visibility' + +可以通过查阅GNU([Visibility - GCC Wiki (gnu.org)](https://gcc.gnu.org/wiki/Visibility))以及LLVM官方文档([LTO Visibility — Clang 20.0.0git documentation (llvm.org)](https://clang.llvm.org/docs/LTOVisibility.html))去了解。 + +### 2.2.1、visibility的作用 + +简单来说,Visibility在编译和链接过程中控制着符号(如函数、变量和类型信息)的可见性,即它们是否可以被其他编译单元或动态共享对象(DSO)引用。以下是Visibility的几个主要作用: + +1. **优化加载时间**:通过减少不必要的符号导出,可以减少动态共享对象(DSO)的大小,从而加快加载时间。 +2. **提高代码优化**:Visibility允许编译器生成更优化的代码。例如,通过避免全局偏移表(GOT)的间接寻址,可以减少处理器流水线停顿,提高代码执行速度。 +3. **减少DSO大小**:通过减少导出的符号数量,可以显著减少DSO的大小,因为ELF的导出符号表格式占用较多空间。 +4. **降低符号冲突**:减少不必要的符号导出可以降低不同库之间符号名称冲突的可能性。 +5. **支持链接时优化(LTO)** :Visibility对于使用链接时优化特性(如全程序虚拟表优化和控制流完整性检查)至关重要,因为这些特性需要在整个程序级别上可见的类层次结构。 +6. **避免ODR违规**:Visibility属性需要在不同翻译单元之间保持一致,以避免违反C++的One Definition Rule(ODR),确保每个非内联函数或变量在整个程序中只有一个定义。 +7. **跨平台兼容性**:Visibility提供了一种机制,使得在不同平台(如Windows和POSIX系统)上进行编译的代码可以有一致的行为,这对于开发可移植的应用程序非常重要。 +8. **细粒度控制**:开发者可以细粒度地控制哪些符号应该公开,哪些应该隐藏,从而优化程序的性能和安全性。 +9. **简化构建系统**:通过使用Visibility属性,可以简化构建系统,因为可以减少对链接器脚本的依赖,从而减少维护成本。 + +### 2.2.2、关于attribute 'visibility'在类型(type)上的应用 + +参考[Type Attributes - Using the GNU Compiler Collection (GCC)](https://gcc.gnu.org/onlinedocs/gcc-4.7.2/gcc/Type-Attributes.html#Type-Attributes)可知, + +`In C++, attribute visibility (see Function Attributes) can also be applied to class, struct, union and enum types. Unlike other type attributes, the attribute must appear between the initial keyword and the name of the type; it cannot appear after the body of the type.` + +即,在C++中attribute 'visibility'可以应用于class,struct,union以及enum类型,并且用法是将其置于关键字和类型名称之间,例如`struct __attribute__((visibility("default"))) A{...};` + +然而,经过上面的小例子测试可知,在C中,gcc并不支持将attribute 'visibility'应用于type,然而clang是支持的,这就是问题的根源 + +## 2.3、问题总结及根因确认 + +在C++中attribute 'visibility'可以应用于class,struct,union以及enum类型,并且用法是将其置于关键字和类型名称之间,在C中,gcc并不支持将attribute 'visibility'应用于type,然而clang是支持的。所以对于struct及attribute 'visibility'的顺序,无论是谁前谁后,必定有一个编译器报错,唯一的二者兼顾方法是删去__attribute__ ((visibility("default")))。 + +# 3、问题修改建议 + +想要兼顾gcc和clang,目前能想到的方法只能是C语言中不将attribute 'visibility'应用于type。参考:[https://gitee.com/openeuler/lcr/pulls/332](https://gitee.com/openeuler/lcr/pulls/332) \ No newline at end of file -- Gitee From 52f3d1417e2dd4ebcf5bfe652a4746d4d1d68d10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=91=E6=B2=A7?= <1050706328@qq.com> Date: Mon, 16 Sep 2024 08:44:50 +0000 Subject: [PATCH 08/35] =?UTF-8?q?update=20aarch=E4=B8=8B-fstack-clash-prot?= =?UTF-8?q?ection=E5=BC=95=E8=B5=B7=E7=9A=84-Wunused-command-line-argument?= =?UTF-8?q?=E9=94=99=E8=AF=AF.md.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 云沧 <1050706328@qq.com> --- ...204-Wunused-command-line-argument\351\224\231\350\257\257.md" | 1 + 1 file changed, 1 insertion(+) diff --git "a/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/aarch\344\270\213-fstack-clash-protection\345\274\225\350\265\267\347\232\204-Wunused-command-line-argument\351\224\231\350\257\257.md" "b/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/aarch\344\270\213-fstack-clash-protection\345\274\225\350\265\267\347\232\204-Wunused-command-line-argument\351\224\231\350\257\257.md" index fe6cde6..76d04ff 100644 --- "a/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/aarch\344\270\213-fstack-clash-protection\345\274\225\350\265\267\347\232\204-Wunused-command-line-argument\351\224\231\350\257\257.md" +++ "b/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/aarch\344\270\213-fstack-clash-protection\345\274\225\350\265\267\347\232\204-Wunused-command-line-argument\351\224\231\350\257\257.md" @@ -1,4 +1,5 @@ # 1、问题现象 +出自:https://gitee.com/src-openeuler/lcr (openEuler-24.03-LTS) `[ 95s] clang: error: argument unused during compilation: '-fstack-clash-protection' [-Werror,-Wunused-command-line-argument]` -- Gitee From 45929431efd08fc9b2add5784ef7f71a9f5b01b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=91=E6=B2=A7?= <1050706328@qq.com> Date: Mon, 16 Sep 2024 08:45:26 +0000 Subject: [PATCH 09/35] =?UTF-8?q?update=20attribute=20'visibility'=20is=20?= =?UTF-8?q?ignored,=20place=20it=20after=20"struct"=E9=97=AE=E9=A2=98.md.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 云沧 <1050706328@qq.com> --- ...nored, place it after \"struct\"\351\227\256\351\242\230.md" | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git "a/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/attribute 'visibility' is ignored, place it after \"struct\"\351\227\256\351\242\230.md" "b/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/attribute 'visibility' is ignored, place it after \"struct\"\351\227\256\351\242\230.md" index b140bf6..43ca0d5 100644 --- "a/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/attribute 'visibility' is ignored, place it after \"struct\"\351\227\256\351\242\230.md" +++ "b/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/attribute 'visibility' is ignored, place it after \"struct\"\351\227\256\351\242\230.md" @@ -1,5 +1,5 @@ # 1、问题现象 - +出自:https://gitee.com/src-openeuler/lcr (openEuler-24.03-LTS) `[ 98s] /home/abuild/rpmbuild/BUILD/lcr-v2.1.4/src/runtime/lcrcontainer.h:43:1: error: attribute 'visibility' is ignored, place it after "struct" to apply attribute to type declaration [-Werror,-Wignored-attributes]` # 2、问题定位 -- Gitee From 8033424ac334679e5c51ef714e2180183961435a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=91=E6=B2=A7?= <1050706328@qq.com> Date: Mon, 16 Sep 2024 08:45:46 +0000 Subject: [PATCH 10/35] =?UTF-8?q?update=20attribute=20'visibility'=20is=20?= =?UTF-8?q?ignored,=20place=20it=20after=20"struct"=E9=97=AE=E9=A2=98.md.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 云沧 <1050706328@qq.com> --- ...gnored, place it after \"struct\"\351\227\256\351\242\230.md" | 1 + 1 file changed, 1 insertion(+) diff --git "a/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/attribute 'visibility' is ignored, place it after \"struct\"\351\227\256\351\242\230.md" "b/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/attribute 'visibility' is ignored, place it after \"struct\"\351\227\256\351\242\230.md" index 43ca0d5..63f1028 100644 --- "a/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/attribute 'visibility' is ignored, place it after \"struct\"\351\227\256\351\242\230.md" +++ "b/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/attribute 'visibility' is ignored, place it after \"struct\"\351\227\256\351\242\230.md" @@ -1,5 +1,6 @@ # 1、问题现象 出自:https://gitee.com/src-openeuler/lcr (openEuler-24.03-LTS) + `[ 98s] /home/abuild/rpmbuild/BUILD/lcr-v2.1.4/src/runtime/lcrcontainer.h:43:1: error: attribute 'visibility' is ignored, place it after "struct" to apply attribute to type declaration [-Werror,-Wignored-attributes]` # 2、问题定位 -- Gitee From 7466e723798541f4819b0741bf2a0b2ae191f444 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=91=E6=B2=A7?= <1050706328@qq.com> Date: Mon, 16 Sep 2024 08:47:19 +0000 Subject: [PATCH 11/35] =?UTF-8?q?update=20LLVM=20Parallel=20Universe=20Pro?= =?UTF-8?q?ject/=E9=97=AE=E9=A2=98=E5=AE=9A=E4=BD=8D=E6=80=BB=E7=BB=93/bad?= =?UTF-8?q?=20date=20in=20%changelog=E9=97=AE=E9=A2=98.md.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 云沧 <1050706328@qq.com> --- .../bad date in %changelog\351\227\256\351\242\230.md" | 1 + 1 file changed, 1 insertion(+) diff --git "a/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/bad date in %changelog\351\227\256\351\242\230.md" "b/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/bad date in %changelog\351\227\256\351\242\230.md" index 9f50d08..0c09536 100644 --- "a/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/bad date in %changelog\351\227\256\351\242\230.md" +++ "b/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/bad date in %changelog\351\227\256\351\242\230.md" @@ -1,4 +1,5 @@ # 1、问题现象 +出自:https://gitee.com/src-openeuler/lcr (openEuler-24.03-LTS) `bad date in %changelog: Tue June 11 2024 jikai - 2.1.4-8` -- Gitee From 50bd0d37fbaee67fb14b71dda6ce3d55be45906e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=91=E6=B2=A7?= <1050706328@qq.com> Date: Mon, 16 Sep 2024 08:48:21 +0000 Subject: [PATCH 12/35] =?UTF-8?q?update=20LLVM=20Parallel=20Universe=20Pro?= =?UTF-8?q?ject/=E9=97=AE=E9=A2=98=E5=AE=9A=E4=BD=8D=E6=80=BB=E7=BB=93/aut?= =?UTF-8?q?oreconf:=20command=20not=20found=E9=97=AE=E9=A2=98.md.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 云沧 <1050706328@qq.com> --- .../autoreconf: command not found\351\227\256\351\242\230.md" | 1 + 1 file changed, 1 insertion(+) diff --git "a/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/autoreconf: command not found\351\227\256\351\242\230.md" "b/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/autoreconf: command not found\351\227\256\351\242\230.md" index 4edc44b..2454ed2 100644 --- "a/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/autoreconf: command not found\351\227\256\351\242\230.md" +++ "b/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/autoreconf: command not found\351\227\256\351\242\230.md" @@ -1,4 +1,5 @@ # 1、问题现象 +出自:https://gitee.com/src-openeuler/libevent (openEuler-24.03-LTS) `[ 119s] /var/tmp/rpm-tmp.PicZ3O: line 47: autoreconf: command not found` -- Gitee From 6261a3fca673a46f0b74fb6b81f230adfd510aab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=91=E6=B2=A7?= <1050706328@qq.com> Date: Mon, 16 Sep 2024 08:49:07 +0000 Subject: [PATCH 13/35] =?UTF-8?q?update=20LLVM=20Parallel=20Universe=20Pro?= =?UTF-8?q?ject/=E9=97=AE=E9=A2=98=E5=AE=9A=E4=BD=8D=E6=80=BB=E7=BB=93/cal?= =?UTF-8?q?l=20to=20undeclared=20function=E9=97=AE=E9=A2=98.md.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 云沧 <1050706328@qq.com> --- .../call to undeclared function\351\227\256\351\242\230.md" | 1 + 1 file changed, 1 insertion(+) diff --git "a/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/call to undeclared function\351\227\256\351\242\230.md" "b/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/call to undeclared function\351\227\256\351\242\230.md" index 81ddb7f..a9bb5cb 100644 --- "a/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/call to undeclared function\351\227\256\351\242\230.md" +++ "b/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/call to undeclared function\351\227\256\351\242\230.md" @@ -1,4 +1,5 @@ # 1、问题现象 +出自:https://gitee.com/src-openeuler/libevent (openEuler-24.03-LTS) `[ 705s] test/regress.c:3689:12: error: call to undeclared function 'event_base_start_iocp_'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]` -- Gitee From 84854b0bf561d6c1e7468ba0d85f4641a126b90b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=91=E6=B2=A7?= <1050706328@qq.com> Date: Mon, 16 Sep 2024 08:49:37 +0000 Subject: [PATCH 14/35] =?UTF-8?q?update=20LLVM=20Parallel=20Universe=20Pro?= =?UTF-8?q?ject/=E9=97=AE=E9=A2=98=E5=AE=9A=E4=BD=8D=E6=80=BB=E7=BB=93/cal?= =?UTF-8?q?l,=20expected=202,=20have=201=E9=97=AE=E9=A2=98.md.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 云沧 <1050706328@qq.com> --- .../call, expected 2, have 1\351\227\256\351\242\230.md" | 1 + 1 file changed, 1 insertion(+) diff --git "a/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/call, expected 2, have 1\351\227\256\351\242\230.md" "b/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/call, expected 2, have 1\351\227\256\351\242\230.md" index 60bc16f..5a7510f 100644 --- "a/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/call, expected 2, have 1\351\227\256\351\242\230.md" +++ "b/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/call, expected 2, have 1\351\227\256\351\242\230.md" @@ -1,4 +1,5 @@ # 1、问题现象 +出自:https://gitee.com/src-openeuler/libevent (openEuler-24.03-LTS) ```c [ 142s] test/regress.c:3691:39: error: call, expected 2, have 1 -- Gitee From 9669ae378b31f619c4e7eb22edd2ca979577d206 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=91=E6=B2=A7?= <1050706328@qq.com> Date: Mon, 16 Sep 2024 08:49:49 +0000 Subject: [PATCH 15/35] =?UTF-8?q?update=20LLVM=20Parallel=20Universe=20Pro?= =?UTF-8?q?ject/=E9=97=AE=E9=A2=98=E5=AE=9A=E4=BD=8D=E6=80=BB=E7=BB=93/?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E8=B0=83=E7=94=A8=E5=AF=BC=E8=87=B4=E7=9A=84?= =?UTF-8?q?incompatible=20function=20pointer=20types=E9=97=AE=E9=A2=98.md.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 云沧 <1050706328@qq.com> --- ...compatible function pointer types\351\227\256\351\242\230.md" | 1 + 1 file changed, 1 insertion(+) diff --git "a/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/\351\224\231\350\257\257\350\260\203\347\224\250\345\257\274\350\207\264\347\232\204incompatible function pointer types\351\227\256\351\242\230.md" "b/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/\351\224\231\350\257\257\350\260\203\347\224\250\345\257\274\350\207\264\347\232\204incompatible function pointer types\351\227\256\351\242\230.md" index 6f7497b..fac3044 100644 --- "a/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/\351\224\231\350\257\257\350\260\203\347\224\250\345\257\274\350\207\264\347\232\204incompatible function pointer types\351\227\256\351\242\230.md" +++ "b/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/\351\224\231\350\257\257\350\260\203\347\224\250\345\257\274\350\207\264\347\232\204incompatible function pointer types\351\227\256\351\242\230.md" @@ -1,4 +1,5 @@ # 1、问题现象 +出自:https://gitee.com/src-openeuler/libevent (openEuler-24.03-LTS) ```c [ 140s] test/regress.c:3707:2: error: incompatible function pointer types initializing 'testcase_fn' (aka 'void (*)(void *)') with an expression of type 'void (void)' [-Wincompatible-function-pointer-types] -- Gitee From 356197884bdf3a25d04d93108e07194764daf678 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=91=E6=B2=A7?= <1050706328@qq.com> Date: Tue, 17 Sep 2024 06:39:52 +0000 Subject: [PATCH 16/35] =?UTF-8?q?undefined=20behavior=20in=20scmp=5Fbpf=5F?= =?UTF-8?q?sim.c=20causing=20issues=E9=97=AE=E9=A2=98.md.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 云沧 <1050706328@qq.com> --- ...causing issues\351\227\256\351\242\230.md" | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 "LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/undefined behavior in scmp_bpf_sim.c causing issues\351\227\256\351\242\230.md" diff --git "a/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/undefined behavior in scmp_bpf_sim.c causing issues\351\227\256\351\242\230.md" "b/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/undefined behavior in scmp_bpf_sim.c causing issues\351\227\256\351\242\230.md" new file mode 100644 index 0000000..09a2a80 --- /dev/null +++ "b/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/undefined behavior in scmp_bpf_sim.c causing issues\351\227\256\351\242\230.md" @@ -0,0 +1,58 @@ +# 1、问题现象 + +出自:https://gitee.com/src-openeuler/libseccomp (openEuler-24.03-LTS) + + +```c +[ 377s] Regression Test Summary +[ 377s] tests run: 5761 +[ 377s] tests skipped: 122 +[ 377s] tests passed: 4615 +[ 377s] tests failed: 1146 +[ 377s] tests errored: 0 +``` + +然后发现,这些tests failed都是因为bpf_sim的result不正确 + +```c +[ 340s] Test 42-sim-adv_chains%%003-00001 result: FAILURE bpf_sim resulted in KILL +[ 340s] Test 42-sim-adv_chains%%004-00001 result: SUCCESS +[ 340s] Test 42-sim-adv_chains%%005-00001 result: FAILURE bpf_sim resulted in ALLOW +[ 341s] Test 42-sim-adv_chains%%006-00001 result: SUCCESS +[ 341s] Test 42-sim-adv_chains%%007-00001 result: SUCCESS +[ 341s] Test 42-sim-adv_chains%%008-00001 result: FAILURE bpf_sim resulted in TRAP +[ 341s] Test 42-sim-adv_chains%%009-00001 result: SUCCESS +[ 341s] Test 42-sim-adv_chains%%010-00001 result: SUCCESS +[ 341s] Test 42-sim-adv_chains%%011-00001 result: SUCCESS +[ 341s] Test 42-sim-adv_chains%%012-00001 result: SUCCESS +[ 341s] Test 42-sim-adv_chains%%013-00001 result: FAILURE bpf_sim resulted in KILL +[ 341s] Test 42-sim-adv_chains%%014-00001 result: FAILURE bpf_sim resulted in KILL +``` + +# 2、问题定位 + +问题出在`scmp_bpf_sim.c`中的 + +```c +uint32_t val = *((uint32_t *)&sys_data_b[k]); +``` + +这行代码试图通过将`sys_data_b[k]`的地址转换为`uint32_t`指针,然后解引用该指针来获取一个`uint32_t`类型的值。这里的问题在于如果`sys_data_b`的元素不是以`uint32_t`对齐的,这种直接解引用会导致未定义行为,因为不是所有的硬件平台都支持不对齐的内存访问。 + +# 3、修改建议 + +修改后的代码: + +```c +uint32_t val; +memcpy(&val, &sys_data_b[k], sizeof(val)); +``` + +使用`memcpy`函数从`sys_data_b`数组的第`k`个元素的地址复制`sizeof(val)`个字节到`val`的地址。这种方式的好处包括: + +1. **类型安全**:`memcpy`不关心数据的类型,它只是简单地复制字节,因此不会因为类型不对齐而引发问题。 +2. **可移植性**:`memcpy`是标准库函数,它在所有平台上的行为都是一致的,因此这段代码在不同的编译器和硬件平台上都能可靠地工作。 + +参考: + +[fix undefined behavior in scmp_bpf_sim.c causing issues when building with clang · Pull Request !50 · src-openEuler/libseccomp - Gitee.com](https://gitee.com/src-openeuler/libseccomp/pulls/50) \ No newline at end of file -- Gitee From 7adb80493905cc2b4f44eac02423d82f9fa4a445 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=91=E6=B2=A7?= <1050706328@qq.com> Date: Tue, 17 Sep 2024 07:57:24 +0000 Subject: [PATCH 17/35] =?UTF-8?q?function=20definition=20without=20a=20pro?= =?UTF-8?q?totype=20is=20deprecated=E9=97=AE=E9=A2=98.md.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 云沧 <1050706328@qq.com> --- ... is deprecated\351\227\256\351\242\230.md" | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 "LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/function definition without a prototype is deprecated\351\227\256\351\242\230.md" diff --git "a/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/function definition without a prototype is deprecated\351\227\256\351\242\230.md" "b/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/function definition without a prototype is deprecated\351\227\256\351\242\230.md" new file mode 100644 index 0000000..e8348ca --- /dev/null +++ "b/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/function definition without a prototype is deprecated\351\227\256\351\242\230.md" @@ -0,0 +1,45 @@ +# 1、问题现象 + +出自:https://gitee.com/src-openeuler/libreswan (openEuler-24.03-LTS) + + +`a function definition without a prototype is deprecated in all versions of C and is not supported in C2x [-Werror,-Wdeprecated-non-prototype]` + +# 2、问题定位 + +有两处使用的函数原型定义方式(形参的类型单独在括号外说明)已经被弃用,一处在上游有commit + +[building: prototype maskcount() definition; clang-16 · libreswan/libreswan@e52a0af (github.com)](https://github.com/libreswan/libreswan/commit/e52a0af61990754b26a2825fb775fd5d1680112b) + +另一处找不到上游对应的文件,但也可以用同样的改法 + +```c +size_t /* length required for full conversion */ +ultot(n, base, dst, dstlen) +unsigned long n; +int base; +char *dst; /* need not be valid if dstlen is 0 */ +size_t dstlen; +{ + ... +} + +``` + +改为 + +```c +size_t /* length required for full conversion */ +ultot(unsigned long n, int base, char *dst, size_t dstlen) + /* char *dst need not be valid if dstlen is 0 */ +{ + ... +} +``` + +# 3、修改建议 + +将函数原型定义方式改为现在支持的形式。 + +参考: +[Fix prototype deprecated and expression result unused,as well rewrite spec to support clang build · Pull Request !99 · src-openEuler/libreswan - Gitee.com](https://gitee.com/src-openeuler/libreswan/pulls/99) \ No newline at end of file -- Gitee From 3cf10673e90b194b4d97266743a9596349e60b77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=91=E6=B2=A7?= <1050706328@qq.com> Date: Tue, 17 Sep 2024 07:58:32 +0000 Subject: [PATCH 18/35] =?UTF-8?q?=E8=AF=AD=E5=8F=A5=E8=AF=AF=E7=94=A8","?= =?UTF-8?q?=E8=80=8C=E9=9D=9E";"=E7=BB=93=E5=B0=BE=E8=80=8C=E5=BC=95?= =?UTF-8?q?=E8=B5=B7=E7=9A=84expression=20result=20unused=E9=97=AE?= =?UTF-8?q?=E9=A2=98.md.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 云沧 <1050706328@qq.com> --- ... result unused\351\227\256\351\242\230.md" | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 "LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/\350\257\255\345\217\245\350\257\257\347\224\250\",\"\350\200\214\351\235\236\";\"\347\273\223\345\260\276\350\200\214\345\274\225\350\265\267\347\232\204expression result unused\351\227\256\351\242\230.md" diff --git "a/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/\350\257\255\345\217\245\350\257\257\347\224\250\",\"\350\200\214\351\235\236\";\"\347\273\223\345\260\276\350\200\214\345\274\225\350\265\267\347\232\204expression result unused\351\227\256\351\242\230.md" "b/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/\350\257\255\345\217\245\350\257\257\347\224\250\",\"\350\200\214\351\235\236\";\"\347\273\223\345\260\276\350\200\214\345\274\225\350\265\267\347\232\204expression result unused\351\227\256\351\242\230.md" new file mode 100644 index 0000000..09ecd0e --- /dev/null +++ "b/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/\350\257\255\345\217\245\350\257\257\347\224\250\",\"\350\200\214\351\235\236\";\"\347\273\223\345\260\276\350\200\214\345\274\225\350\265\267\347\232\204expression result unused\351\227\256\351\242\230.md" @@ -0,0 +1,52 @@ +# 1、问题现象 + +出自:https://gitee.com/src-openeuler/libreswan (openEuler-24.03-LTS) + + +```c +[ 97s] /home/abuild/rpmbuild/BUILD/libreswan-4.15/lib/libswan/ckaid.c:85:2: error: expression result unused [-Werror,-Wunused-value] +[ 97s] 85 | pexpect(ckaid.len == nss_ckaid_len); +[ 97s] | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +[ 97s] ../../include/lswlog.h:489:29: note: expanded from macro 'pexpect' +[ 97s] 489 | #define pexpect(ASSERTION) PEXPECT(&global_logger, ASSERTION) +[ 97s] | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +[ 97s] ../../include/lswlog.h:486:3: note: expanded from macro 'PEXPECT' +[ 97s] 486 | assertion__; /* result */ \ +[ 97s] | ^~~~~~~~~~~ +[ 97s] 1 error generated. +``` + +# 2、问题定位 + +## 2.1、问题定位分析 + +* 问题定位: + +```c +ckaid_t ckaid_from_secitem(const SECItem *const nss_ckaid) +{ + size_t nss_ckaid_len = nss_ckaid->len; + /* ckaid = { .len = min(...), } barfs with gcc 11.2.1 */ + ckaid_t ckaid = {0}; + /* should not be truncated but can be */ + ckaid.len = min(nss_ckaid_len, sizeof(ckaid.ptr/*array*/)), + pexpect(ckaid.len == nss_ckaid_len); + memmove(ckaid.ptr, nss_ckaid->data, ckaid.len); + return ckaid; +} +``` + +发现其实是因为ckaid.len = min(nss_ckaid_len, sizeof(ckaid.ptr/\*array *** /)),结尾是逗号,而不是分号 + +在上游提交了pr:https://github.com/libreswan/libreswan/pull/1791修正了问题 + +## 2.2、问题总结及根因确认 + +语句误用","而非";"结尾,编译器没有识别出这个错误,而是错误地将其识别成了expression result unused错误,gcc对于这种类型的错误可能较为宽松,导致gcc编译时没有发现这个错误。 + +# 3、修改建议 + +ckaid.len = min(nss_ckaid_len, sizeof(ckaid.ptr/\*array *** /)),结尾的","改为";" + +参考: +[Fix prototype deprecated and expression result unused,as well rewrite spec to support clang build · Pull Request !99 · src-openEuler/libreswan - Gitee.com](https://gitee.com/src-openeuler/libreswan/pulls/99) \ No newline at end of file -- Gitee From d1cf840b2cd1848b1be3c607d10e0f2a8eb7a628 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=91=E6=B2=A7?= <1050706328@qq.com> Date: Tue, 17 Sep 2024 07:59:05 +0000 Subject: [PATCH 19/35] =?UTF-8?q?unknown=20warning=20option=E9=97=AE?= =?UTF-8?q?=E9=A2=98.md.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 云沧 <1050706328@qq.com> --- ...warning option\351\227\256\351\242\230.md" | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 "LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/unknown warning option\351\227\256\351\242\230.md" diff --git "a/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/unknown warning option\351\227\256\351\242\230.md" "b/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/unknown warning option\351\227\256\351\242\230.md" new file mode 100644 index 0000000..c7d192c --- /dev/null +++ "b/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/unknown warning option\351\227\256\351\242\230.md" @@ -0,0 +1,21 @@ +# 1、问题现象 + +出自:https://gitee.com/src-openeuler/libreswan (openEuler-24.03-LTS) + + +```c +[ 537s] error: unknown warning option '-Wno-maybe-uninitialized'; did you mean '-Wno-uninitialized'? [-Werror,-Wunknown-warning-option] +[ 537s] error: unknown warning option '-Wno-lto-type-mismatch'; did you mean '-Wno-selector-type-mismatch'? [-Werror,-Wunknown-warning-option] +``` + +# 2、问题分析 + +`-Wno-maybe-uninitialized`和`-Wno-lto-type-mismatch`是gcc的编译器选项,而查阅资料得知,clang没有这两个选项 + +# 3、修改建议 + +clang构建时,不设置这两个选项 + +参考: + +[Fix prototype deprecated and expression result unused,as well rewrite spec to support clang build · Pull Request !99 · src-openEuler/libreswan - Gitee.com](https://gitee.com/src-openeuler/libreswan/pulls/99) \ No newline at end of file -- Gitee From f17cf077406debac4a79d50920d110917a4c7f80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=91=E6=B2=A7?= <1050706328@qq.com> Date: Tue, 17 Sep 2024 08:06:21 +0000 Subject: [PATCH 20/35] =?UTF-8?q?=E8=A1=A5=E5=85=85=20incompatible=20funct?= =?UTF-8?q?ion=20pointer=20types=E9=97=AE=E9=A2=98.md.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 云沧 <1050706328@qq.com> --- ...nction pointer types\351\227\256\351\242\230.md" | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git "a/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/\351\224\231\350\257\257\350\260\203\347\224\250\345\257\274\350\207\264\347\232\204incompatible function pointer types\351\227\256\351\242\230.md" "b/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/\351\224\231\350\257\257\350\260\203\347\224\250\345\257\274\350\207\264\347\232\204incompatible function pointer types\351\227\256\351\242\230.md" index fac3044..f91c821 100644 --- "a/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/\351\224\231\350\257\257\350\260\203\347\224\250\345\257\274\350\207\264\347\232\204incompatible function pointer types\351\227\256\351\242\230.md" +++ "b/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/\351\224\231\350\257\257\350\260\203\347\224\250\345\257\274\350\207\264\347\232\204incompatible function pointer types\351\227\256\351\242\230.md" @@ -1,6 +1,8 @@ # 1、问题现象 + 出自:https://gitee.com/src-openeuler/libevent (openEuler-24.03-LTS) + ```c [ 140s] test/regress.c:3707:2: error: incompatible function pointer types initializing 'testcase_fn' (aka 'void (*)(void *)') with an expression of type 'void (void)' [-Wincompatible-function-pointer-types] [ 140s] 3707 | BASIC(event_config_set_max_dispatch_interval, TT_FORK|TT_NEED_BASE), @@ -238,4 +240,13 @@ test_persistent_timeout(void) 把报错两处的BASIC改为LEGACY, -参考:[Fix function undeclared,incompatible pointer and parameter lack in 'add-testcases-for-event.c-apis.patch',support clang build · Pull Request !74 · src-openEuler/libevent - Gitee.com](https://gitee.com/src-openeuler/libevent/pulls/74) \ No newline at end of file +参考:[Fix function undeclared,incompatible pointer and parameter lack in 'add-testcases-for-event.c-apis.patch',support clang build · Pull Request !74 · src-openEuler/libevent - Gitee.com](https://gitee.com/src-openeuler/libevent/pulls/74) + +# 4、类似问题例子 + +出自:https://gitee.com/src-openeuler/libsecret (openEuler-24.03-LTS) + +[https://gitee.com/src-openeuler/libsecret/pulls/23](https://gitee.com/src-openeuler/libsecret/pulls/23) + +* **问题成因总结:** 使用GLib.Test.add\_data\_func时,参数要求为(const char \*testpath,gconstpointer test\_data,GTestDataFunc test\_func),实际为(const char \*testpath,GTestFunc test\_func),参数不匹配。 +* **修改建议:** 改为使用GLib.Test.add\_func,其参数要求为(const char \*testpath,GTestFunc test\_func) \ No newline at end of file -- Gitee From ef04dc36321eecdac4d61c1540c9de91c4f8d8bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=91=E6=B2=A7?= <1050706328@qq.com> Date: Tue, 17 Sep 2024 08:14:50 +0000 Subject: [PATCH 21/35] =?UTF-8?q?%changelog=20not=20in=20descending=20chro?= =?UTF-8?q?nological=20order=E9=97=AE=E9=A2=98.md.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 云沧 <1050706328@qq.com> --- ...ological order\351\227\256\351\242\230.md" | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 "LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/%changelog not in descending chronological order\351\227\256\351\242\230.md" diff --git "a/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/%changelog not in descending chronological order\351\227\256\351\242\230.md" "b/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/%changelog not in descending chronological order\351\227\256\351\242\230.md" new file mode 100644 index 0000000..d16d715 --- /dev/null +++ "b/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/%changelog not in descending chronological order\351\227\256\351\242\230.md" @@ -0,0 +1,35 @@ +# 1、问题现象 + +出自:https://gitee.com/src-openeuler/lvm2 (openEuler-24.03-LTS) + + +`[ 90s] error: %changelog not in descending chronological order` + +# 2、问题定位 + +## 2.1、问题定位分析 + +```c +* Wed Nov 22 2023 wangxiaomeng - 8:2.03.22-3 +- lvmlockd: add suport for loongarch64 + +* Tue Dec 19 2023 wangzhiqiang - 8:2.03.22-2 +- dm-event: release buffer on dm_event_get_version + +* Fri Nov 03 2023 liweigang - 8:2.03.22-1 +- update to version 2.03.22 +``` + +问题出在[lvmlockd: add suport for loongarch64 · dee4806 · 云沧/lvm2 - Gitee.com](https://gitee.com/yuncang123/lvm2/commit/dee4806fb29598db7cbd4d9abe56db348cc79baa)这个commit在`Tue Jan 9 2024`提交,而changelog里写的是`Wed Nov 22 2023`,导致其提交比上一个晚,但是changelog里写的日期比上一个早 + +## 2.2、问题总结及根因确认 + +changelog的日期应该按从上到下时间降序,本问题由于changelog中写的日期与实际提交日期大大不符导致 + +# 3、修改建议 + +将`Wed Nov 22 2023 wangxiaomeng - 8:2.03.22-3`的日期修改成commit对应的日期,即将`Wed Nov 22 2023`改为`Tue Jan 9 2024` + +参考: + +[fix 2 undeclared functions,and changelog format,support clang build · Pull Request !183 · src-openEuler/lvm2 - Gitee.com](https://gitee.com/src-openeuler/lvm2/pulls/183) \ No newline at end of file -- Gitee From 7f14d76c632c9c38062c0d3b3910fa6fca76506d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=91=E6=B2=A7?= <1050706328@qq.com> Date: Tue, 17 Sep 2024 08:28:47 +0000 Subject: [PATCH 22/35] =?UTF-8?q?=E8=A1=A5=E5=85=85=20call=20to=20undeclar?= =?UTF-8?q?ed=20function=E9=97=AE=E9=A2=98.md.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 云沧 <1050706328@qq.com> --- ... to undeclared function\351\227\256\351\242\230.md" | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git "a/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/call to undeclared function\351\227\256\351\242\230.md" "b/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/call to undeclared function\351\227\256\351\242\230.md" index a9bb5cb..6d5418e 100644 --- "a/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/call to undeclared function\351\227\256\351\242\230.md" +++ "b/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/call to undeclared function\351\227\256\351\242\230.md" @@ -23,4 +23,12 @@ # 3、修改建议 -补充打一个patch,在regress.c中#include "iocp-internal.h",参考:[Fix function undeclared,incompatible pointer and parameter lack in 'add-testcases-for-event.c-apis.patch',support clang build · Pull Request !74 · src-openEuler/libevent - Gitee.com](https://gitee.com/src-openeuler/libevent/pulls/74) \ No newline at end of file +补充打一个patch,在regress.c中#include "iocp-internal.h",参考:[Fix function undeclared,incompatible pointer and parameter lack in 'add-testcases-for-event.c-apis.patch',support clang build · Pull Request !74 · src-openEuler/libevent - Gitee.com](https://gitee.com/src-openeuler/libevent/pulls/74) + +# 4、类似问题例子 + +出自:https://gitee.com/src-openeuler/lvm2 (openEuler-24.03-LTS) + +[fix 2 undeclared functions,and changelog format,support clang build · Pull Request !183 · src-openEuler/lvm2 - Gitee.com](https://gitee.com/src-openeuler/lvm2/pulls/183) + +* **问题成因总结:**​[0010-bugfix-lvm2-fix-the-reuse-of-va_list.patch](https://gitee.com/src-openeuler/lvm2/blob/fb6a5827c6c2fbfb26e6e531fc29da497745de7d/0010-bugfix-lvm2-fix-the-reuse-of-va_list.patch)在libdm-common.c中调用vsyslog函数,但是没有包含其头文件syslog.h;[0012-lvm-code-reduce-cyclomatic-complexity.patch](https://gitee.com/src-openeuler/lvm2/blob/fb6a5827c6c2fbfb26e6e531fc29da497745de7d/0012-lvm-code-reduce-cyclomatic-complexity.patch)在dev-cache.c中调用gettimeofday函数,但是没有包含其头文件sys/time.h \ No newline at end of file -- Gitee From f7be3e9883e3108db02a07d4bac4b998ef709abd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=91=E6=B2=A7?= <1050706328@qq.com> Date: Tue, 17 Sep 2024 08:31:34 +0000 Subject: [PATCH 23/35] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20call=20to=20undeclar?= =?UTF-8?q?ed=20function=E9=97=AE=E9=A2=98.md.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 云沧 <1050706328@qq.com> --- .../call to undeclared function\351\227\256\351\242\230.md" | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git "a/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/call to undeclared function\351\227\256\351\242\230.md" "b/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/call to undeclared function\351\227\256\351\242\230.md" index 6d5418e..5c860c3 100644 --- "a/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/call to undeclared function\351\227\256\351\242\230.md" +++ "b/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/call to undeclared function\351\227\256\351\242\230.md" @@ -31,4 +31,4 @@ [fix 2 undeclared functions,and changelog format,support clang build · Pull Request !183 · src-openEuler/lvm2 - Gitee.com](https://gitee.com/src-openeuler/lvm2/pulls/183) -* **问题成因总结:**​[0010-bugfix-lvm2-fix-the-reuse-of-va_list.patch](https://gitee.com/src-openeuler/lvm2/blob/fb6a5827c6c2fbfb26e6e531fc29da497745de7d/0010-bugfix-lvm2-fix-the-reuse-of-va_list.patch)在libdm-common.c中调用vsyslog函数,但是没有包含其头文件syslog.h;[0012-lvm-code-reduce-cyclomatic-complexity.patch](https://gitee.com/src-openeuler/lvm2/blob/fb6a5827c6c2fbfb26e6e531fc29da497745de7d/0012-lvm-code-reduce-cyclomatic-complexity.patch)在dev-cache.c中调用gettimeofday函数,但是没有包含其头文件sys/time.h \ No newline at end of file +* **问题成因总结:** ​[0010-bugfix-lvm2-fix-the-reuse-of-va_list.patch](https://gitee.com/src-openeuler/lvm2/blob/fb6a5827c6c2fbfb26e6e531fc29da497745de7d/0010-bugfix-lvm2-fix-the-reuse-of-va_list.patch)在libdm-common.c中调用vsyslog函数,但是没有包含其头文件syslog.h;[0012-lvm-code-reduce-cyclomatic-complexity.patch](https://gitee.com/src-openeuler/lvm2/blob/fb6a5827c6c2fbfb26e6e531fc29da497745de7d/0012-lvm-code-reduce-cyclomatic-complexity.patch)在dev-cache.c中调用gettimeofday函数,但是没有包含其头文件sys/time.h \ No newline at end of file -- Gitee From 2e5d2c14505455297feaebe5647c2dfbfd983e60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=91=E6=B2=A7?= <1050706328@qq.com> Date: Wed, 18 Sep 2024 07:17:56 +0000 Subject: [PATCH 24/35] =?UTF-8?q?meson.build=E4=B8=ADcc.compiles=20returns?= =?UTF-8?q?=20unexpected=20false=E9=97=AE=E9=A2=98.md.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 云沧 <1050706328@qq.com> --- ...expected false\351\227\256\351\242\230.md" | 112 ++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 "LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/meson.build\344\270\255cc.compiles returns unexpected false\351\227\256\351\242\230.md" diff --git "a/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/meson.build\344\270\255cc.compiles returns unexpected false\351\227\256\351\242\230.md" "b/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/meson.build\344\270\255cc.compiles returns unexpected false\351\227\256\351\242\230.md" new file mode 100644 index 0000000..d76751e --- /dev/null +++ "b/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/meson.build\344\270\255cc.compiles returns unexpected false\351\227\256\351\242\230.md" @@ -0,0 +1,112 @@ +# 1、问题现象 + +出自:https://gitee.com/src-openeuler/lxc (openEuler-24.03-LTS) + + +```c +[ 112s] clang: warning: argument unused during compilation: '-fstack-clash-protection' [-Wunused-command-line-argument] +[ 112s] In file included from ../src/lxc/error.c:10: +[ 112s] ../src/lxc/log.h:310:6: error: conflicting types for 'strerror_r' +[ 112s] 310 | int strerror_r(int errnum, char *buf, size_t buflen); +[ 112s] | ^ +[ 112s] /usr/include/string.h:444:14: note: previous declaration is here +[ 112s] 444 | extern char *strerror_r (int __errnum, char *__buf, size_t __buflen) +[ 112s] | ^ +[ 112s] 1 error generated. +``` + +# 2、问题定位 + +## 2.1、问题定位分析 + +已同步提交上游PR:[fix possible clang compile error on AARCH by yuncang123 · Pull Request #4479 · lxc/lxc (github.com)](https://github.com/lxc/lxc/pull/4479) + +* 报错的地方在log.h + +```c +#if HAVE_STRERROR_R + #if STRERROR_R_CHAR_P + char *strerror_r(int errnum, char *buf, size_t buflen); + #else + int strerror_r(int errnum, char *buf, size_t buflen); + #endif +``` + +STRERROR_R_CHAR_P的取值定义在下段代码中: + +```c +have_func_strerror_r = cc.has_function('strerror_r', prefix: '#include ', args: '-D_GNU_SOURCE') +srcconf.set10('HAVE_STRERROR_R', have_func_strerror_r) + +have_func_strerror_r_char_p = false + +if have_func_strerror_r + code = ''' +#define _GNU_SOURCE +#include +int func (void) { + char error_string[256]; + char *ptr = strerror_r (-2, error_string, 256); + char c = *strerror_r (-2, error_string, 256); + return c != 0 && ptr != (void*) 0L; +} +''' + +have_func_strerror_r_char_p = cc.compiles(code, name : 'strerror_r() returns char *') +endif + +srcconf.set10('STRERROR_R_CHAR_P', have_func_strerror_r_char_p) +``` + +问题关键: + +```c +[ 94s] Checking if "strerror_r() returns char *" compiles: NO +``` + + +而这个结果本该是YES,因为openEuler-24.03-LTS中strerror_r的返回值类型就是char *没错。 + +问题出在cc.compiles结果出错: + +```c +cc.compiles(code, name : 'strerror_r() returns char *') +``` + +最后发现是由于`'-fstack-clash-protection'`在aarch中暂时并未支持,再加上默认开启了‘-Werror’,因此导致-Wunused-command-line-argument升级为error,导致编译结果为false + +## 2.2、关于meson中的Compiler properties + +详见:https://mesonbuild.com/Compiler-properties.html + +这里只简单介绍一下`compiler.compiles` + +```c +compiler = meson.get_compiler('c') +code = '''#include +void func() { printf("Compile me.\n"); } +''' +result = compiler.compiles(code, name : 'basic check') +``` + +`compiler = meson.get_compiler('c')`是获取c语言的编译器 + +`result = compiler.compiles(code, name : 'basic check')`如果编译器编译code通过,则返回true,反之返回false + +`name : 'basic check'`是可选参数选项 + +此外,还可以加入`args:`参数,这个参数的作用是给这一次`compiler.compiles`添加编译器选项 + +例如本修改法中,就是当编译器为clang时,将`cc.compiles(code, name : 'strerror_r() returns char *')`改为`cc.compiles(code, args : '-Wno-error=unused-command-line-argument', name : 'strerror_r() returns char *')`从而避免`'-fstack-clash-protection'`导致的error + +## 2.3、问题总结及根因确认 + +meson中的`compiler.compiles(code, name : 'basic check')`函数是用来测试code是否能够编译成功,本例使用该函数来测试strerror_r函数在当前系统中的返回值类型,然而由于aarch中没有实现`'-fstack-clash-protection'`,该编译器选项在Werror的影响下由warning升级成为了error,从而使`compiler.compiles`返回结果为false(这与测试strerror_r函数在当前系统中的返回值类型的本意是违背的)。 + +# 3、修改建议 + +当编译器为clang时,将`cc.compiles(code, name : 'strerror_r() returns char *')`改为`cc.compiles(code, args : '-Wno-error=unused-command-line-argument', name : 'strerror_r() returns char *')`从而避免`'-fstack-clash-protection'`导致的error + +参考: + +[backport:fix clang build error on AARCH64 · Pull Request !531 · src-openEuler/lxc - Gitee.com](https://gitee.com/src-openeuler/lxc/pulls/531) \ No newline at end of file -- Gitee From 8c4a22f3c172e4178b3084fad92ade3af33ec561 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=91=E6=B2=A7?= <1050706328@qq.com> Date: Thu, 19 Sep 2024 02:29:12 +0000 Subject: [PATCH 25/35] =?UTF-8?q?%changelog=20entries=20must=20start=20wit?= =?UTF-8?q?h=20*=E9=97=AE=E9=A2=98.md.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 云沧 <1050706328@qq.com> --- ...t start with *\351\227\256\351\242\230.md" | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 "LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/%changelog entries must start with *\351\227\256\351\242\230.md" diff --git "a/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/%changelog entries must start with *\351\227\256\351\242\230.md" "b/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/%changelog entries must start with *\351\227\256\351\242\230.md" new file mode 100644 index 0000000..829da24 --- /dev/null +++ "b/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/%changelog entries must start with *\351\227\256\351\242\230.md" @@ -0,0 +1,20 @@ +# 1、问题现象 + +出自:https://gitee.com/src-openeuler/zziplib (openEuler-24.03-LTS) + + +`[ 94s] error: %changelog entries must start with *` + +# 2、问题定位 + +原spec文件中changelog报错处: + +`-* Wed Jul 5 2023 dillon chen - 0.13.72-2` + +# 3、修改建议 + +删去最前面的`-`,每个changelog应该以*起始 + +参考: + +https://gitee.com/src-openeuler/zziplib/pulls/58 \ No newline at end of file -- Gitee From 3d79c9e5ae2db5e6be7bd0f5f8027e60f3180da0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=91=E6=B2=A7?= <1050706328@qq.com> Date: Thu, 19 Sep 2024 02:32:47 +0000 Subject: [PATCH 26/35] =?UTF-8?q?incompatible=20pointer-integer=20conversi?= =?UTF-8?q?on=E9=97=AE=E9=A2=98.md.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 云沧 <1050706328@qq.com> --- ...ger conversion\351\227\256\351\242\230.md" | 81 +++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 "LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/incompatible pointer-integer conversion\351\227\256\351\242\230.md" diff --git "a/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/incompatible pointer-integer conversion\351\227\256\351\242\230.md" "b/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/incompatible pointer-integer conversion\351\227\256\351\242\230.md" new file mode 100644 index 0000000..05dad67 --- /dev/null +++ "b/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/incompatible pointer-integer conversion\351\227\256\351\242\230.md" @@ -0,0 +1,81 @@ +# 1、问题现象 + +出自:https://gitee.com/src-openeuler/zziplib (openEuler-24.03-LTS) + + +`[ 99s] /home/abuild/rpmbuild/BUILD/zziplib-0.13.72/zzip/mmapped.c:664:11: error: incompatible pointer to integer conversion initializing 'off_t' (aka 'long') with an expression of type 'zzip_byte_t *' (aka 'unsigned char *') [-Wint-conversion]` + +`[ 99s] /home/abuild/rpmbuild/BUILD/zziplib-0.13.72/zzip/mmapped.c:685:24: error: incompatible integer to pointer conversion assigning to 'Bytef *' (aka 'unsigned char *') from 'off_t' (aka 'long') [-Wint-conversion]` + +# 2、问题定位分析与解决思路 + +## 2.1、问题定位 + +` off_t offset = zzip_file_header_to_data(header);` + +等号左边类型为`long`,右边为`unsigned char *` + + +` offset = zzip_extra_zip64_offset(zip64);` + +等号左边类型为`unsigned char *`(上面的初始化使它成为这个类型),等号右边为`long` + +## 2.2、问题分析 + +首先,上游社区的情况是:这个问题曾经有人提出过,目前上游社区的代码已经没有这个问题了。 + +### 按照时间顺序分析该问题来龙去脉, + +首先,A发现了这个问题并且提出Issue: + +[Build failure with Clang 15 (`error: incompatible pointer to integer conversion initializing 'off_t' (aka 'long') with an expression of type 'zzip_byte_t *' (aka 'unsigned char *')`) · Issue #140 · gdraheim/zziplib (github.com)](https://github.com/gdraheim/zziplib/issues/140) + +然后,B提出pr修复了这个Issue,并且被作者合入: + +[Fix incompatible pointer error by nvinson · Pull Request #141 · gdraheim/zziplib (github.com)](https://github.com/gdraheim/zziplib/pull/141) + +然而,作者本人认为这样的改动不够完美,不能够完全解决问题,于是重写了代码逻辑: + +[disable zzip_use_file_header_zip64_offset · gdraheim/zziplib@bf539bd (github.com)](https://github.com/gdraheim/zziplib/commit/bf539bd6a434f56f7ad7685fc0bc8496f652b5e8) + + +#### 单独回合最终解决问题的commit:[disable zzip_use_file_header_zip64_offset · gdraheim/zziplib@bf539bd (github.com)](https://github.com/gdraheim/zziplib/commit/bf539bd6a434f56f7ad7685fc0bc8496f652b5e8) + +会出现error:end没有定义以及几处warning + +![输入图片说明](https://foruda.gitee.com/images/1725096824495708622/2f4c0753_13034847.png "屏幕截图") + +因为oE社区这边软件包里的是这样的 + +![输入图片说明](https://foruda.gitee.com/images/1725096829734701348/acb700f2_13034847.png "屏幕截图") + +所以需要找到是哪个commit修改了这里 + + +#### 查看这个commit与社区版本差了几个commit,一并回合相关commit + +两个commit之间隔了5个commit + +![输入图片说明](https://foruda.gitee.com/images/1725096842107442652/8cd74b85_13034847.png "屏幕截图") + +#### commit:[#69 assert full zzip_file_header · gdraheim/zziplib@803f49a (github.com)](https://github.com/gdraheim/zziplib/commit/803f49aaae16b7f2899e4769afdfc673a21fa9e8)引入end变量,将其回合 + + +#### commit:[Merge pull request #150 from Schievel1/fix-incompat-pointers · gdraheim/zziplib@1db4fe9 (github.com)](https://github.com/gdraheim/zziplib/commit/1db4fe922266d55279265e0e11ff63fb692068a0)解决一处类型转换warning,将其回合 + + +#### 这三个commit只改格式,未改变功能,不考虑回合 + +![输入图片说明](https://foruda.gitee.com/images/1725096872545998012/88dd48f0_13034847.png "屏幕截图") + +## 2.3、问题总结及根因确认 + +源代码最初使用了不恰当的代码逻辑,产生了pointer与integer之间的不恰当类型转换,新的源码版本中author已经意识到问题并重写了代码,解决了问题。gcc对于类型转换的错误处理并不严格,而clang发现了错误,最终使其得以解决。 + +# 3、修改建议 + +回合上游pr以及相关commit:[#69 assert full zzip_file_header · gdraheim/zziplib@803f49a (github.com)](https://github.com/gdraheim/zziplib/commit/803f49aaae16b7f2899e4769afdfc673a21fa9e8)引入end;[Merge pull request #150 from Schievel1/fix-incompat-pointers · gdraheim/zziplib@1db4fe9 (github.com)](https://github.com/gdraheim/zziplib/commit/1db4fe922266d55279265e0e11ff63fb692068a0)解决一处类型转换warning;[disable zzip_use_file_header_zip64_offset · gdraheim/zziplib@bf539bd (github.com)](https://github.com/gdraheim/zziplib/commit/bf539bd6a434f56f7ad7685fc0bc8496f652b5e8)最终解决指针类型错误问题。 + +参考: + +https://gitee.com/src-openeuler/zziplib/pulls/58 \ No newline at end of file -- Gitee From b2bac9341955a75a21bcb1369ed40022e850fbab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=91=E6=B2=A7?= <1050706328@qq.com> Date: Fri, 20 Sep 2024 04:25:16 +0000 Subject: [PATCH 27/35] =?UTF-8?q?passing=20arguments=20to=20a=20function?= =?UTF-8?q?=20without=20a=20prototype=E9=97=AE=E9=A2=98.md.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 云沧 <1050706328@qq.com> --- ...ut a prototype\351\227\256\351\242\230.md" | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 "LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/passing arguments to a function without a prototype\351\227\256\351\242\230.md" diff --git "a/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/passing arguments to a function without a prototype\351\227\256\351\242\230.md" "b/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/passing arguments to a function without a prototype\351\227\256\351\242\230.md" new file mode 100644 index 0000000..1cc1e6a --- /dev/null +++ "b/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/passing arguments to a function without a prototype\351\227\256\351\242\230.md" @@ -0,0 +1,52 @@ +# 1、问题现象 + +出自:https://gitee.com/src-openeuler/opensc (openEuler-24.03-LTS) + + +```c +[ 100s] card-openpgp.c:1164:7: error: passing arguments to a function without a prototype is deprecated in all versions of C and is not supported in C2x [-Werror,-Wdeprecated-non-prototype] +[ 100s] 1164 | func(blob); +[ 100s] | ^ +[ 100s] 1 error generated. +``` + +# 2、问题定位 + +```c +/** + * Internal: iterate through the blob tree, calling a function for each blob. + */ +static void +pgp_iterate_blobs(pgp_blob_t *blob, void (*func)()) +{ + if (blob) { + pgp_blob_t *child = blob->files; + + while (child != NULL) { + pgp_blob_t *next = child->next; + + pgp_iterate_blobs(child, func); + child = next; + } + func(blob); + } +} +``` + +参数列表里func应该是一个不接受任何参数的函数的指针,而实际运用上传入了blob + +上游commit: + +[pgp: avoid calling functions without prototype · OpenSC/OpenSC@3f485ff (github.com)](https://github.com/OpenSC/OpenSC/commit/3f485ff28cecf0cdddecef369442df2efed80a99) + +更改了代码逻辑,弃用`pgp_iterate_blobs`函数,改为使用`pgp_free_blobs`函数 + +# 3、修改建议 + +回合上游commit,消除错误: + +[pgp: avoid calling functions without prototype · OpenSC/OpenSC@3f485ff (github.com)](https://github.com/OpenSC/OpenSC/commit/3f485ff28cecf0cdddecef369442df2efed80a99) + +参考: + +https://gitee.com/src-openeuler/opensc/pulls/79 \ No newline at end of file -- Gitee From 2b2b4618214b70a83d7e1e273840727491c875c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=91=E6=B2=A7?= <1050706328@qq.com> Date: Wed, 25 Sep 2024 06:44:41 +0000 Subject: [PATCH 28/35] =?UTF-8?q?add=20LLVM=20Parallel=20Universe=20Projec?= =?UTF-8?q?t/=E9=97=AE=E9=A2=98=E5=AE=9A=E4=BD=8D=E6=80=BB=E7=BB=93/'linke?= =?UTF-8?q?r'=20input=20unused=E9=97=AE=E9=A2=98.md.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 云沧 <1050706328@qq.com> --- ...' input unused\351\227\256\351\242\230.md" | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 "LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/'linker' input unused\351\227\256\351\242\230.md" diff --git "a/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/'linker' input unused\351\227\256\351\242\230.md" "b/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/'linker' input unused\351\227\256\351\242\230.md" new file mode 100644 index 0000000..ffdec17 --- /dev/null +++ "b/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/'linker' input unused\351\227\256\351\242\230.md" @@ -0,0 +1,51 @@ +# 1、问题现象 + +出自:https://gitee.com/src-openeuler/open-iscsi (openEuler-24.03-LTS) + + +```c +[ 102s] clang: error: -Wl,-z,relro: 'linker' input unused [-Werror,-Wunused-command-line-argument] +[ 102s] clang: error: -Wl,-z,now: 'linker' input unused [-Werror,-Wunused-command-line-argument] +[ 102s] clang: error: -lkmod: 'linker' input unused [-Werror,-Wunused-command-line-argument] +``` + +# 2、问题定位 + +open-iscsi.spec中: + +`%make_build OPTFLAGS="%{optflags} %{?__global_ldflags} -DUSE_KMOD -lkmod" LIB_DIR=%{_libdir}` + +在open-iscisi-2.1.5/Makefile中: + +```c +# Compatibility: parse old OPTFLAGS argument +ifdef OPTFLAGS +CFLAGS = $(OPTFLAGS) +endif +``` + + +也就是将`%{?__global_ldflags}`(即-Wl,-z,relro -Wl,-z,now)、`-lkmod`等链接器(linker)选项设置给了编译器CFLAGS,这在clang看来是多余的、无用的 + +# 3、修改建议 + +当toolchain为clang时,将`%{?__global_ldflags}`(即-Wl,-z,relro -Wl,-z,now)、`-lkmod`等链接器(linker)选项设置给LDFLAGS + +即将 + +```c +%make_build OPTFLAGS="%{optflags} %{?__global_ldflags} -DUSE_KMOD -lkmod" LIB_DIR=%{_libdir} +``` + +改为: + +```c +%if "%toolchain"=="clang" +CFLAGS="%{optflags} -DUSE_KMOD" \ +LDFLAGS="%{?__global_ldflags} -lkmod" \ +LIB_DIR=%{_libdir} +%make_build +%else +%make_build OPTFLAGS="%{optflags} %{?__global_ldflags} -DUSE_KMOD -lkmod" LIB_DIR=%{_libdir} +%endif +``` \ No newline at end of file -- Gitee From 08c24dadfe378a0b5ee23087eda0f937125701fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=91=E6=B2=A7?= <1050706328@qq.com> Date: Wed, 25 Sep 2024 06:46:47 +0000 Subject: [PATCH 29/35] =?UTF-8?q?header=20guard=20followed=20by=20#define?= =?UTF-8?q?=20of=20a=20different=20macro=E9=97=AE=E9=A2=98.md.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 云沧 <1050706328@qq.com> --- ...ifferent macro\351\227\256\351\242\230.md" | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 "LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/header guard followed by #define of a different macro\351\227\256\351\242\230.md" diff --git "a/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/header guard followed by #define of a different macro\351\227\256\351\242\230.md" "b/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/header guard followed by #define of a different macro\351\227\256\351\242\230.md" new file mode 100644 index 0000000..2ab448a --- /dev/null +++ "b/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/header guard followed by #define of a different macro\351\227\256\351\242\230.md" @@ -0,0 +1,24 @@ +# 1、问题现象 + +出自:https://gitee.com/src-openeuler/open-iscsi (openEuler-24.03-LTS) + + +```c +[ 89s] In file included from session_info.c:19: +[ 89s] ./iscsid_req.h:21:9: error: 'ISCSID_REQ_H_' is used as a header guard here, followed by #define of a different macro [-Werror,-Wheader-guard] +[ 89s] 21 | #ifndef ISCSID_REQ_H_ +[ 89s] | ^~~~~~~~~~~~~ +[ 89s] ./iscsid_req.h:22:9: note: 'ISCSID_REQ_H' is defined here; did you mean 'ISCSID_REQ_H_'? +[ 89s] 22 | #define ISCSID_REQ_H +[ 89s] | ^~~~~~~~~~~~ +[ 89s] | ISCSID_REQ_H_ +[ 89s] 1 error generated. +``` + +# 2、问题成因 + +前后名字不一致,少了个_,clang语法检测更加严格,因此发现问题 + +# 3、修改建议 + +回合上游commit:[fix: add usr/iscsid_req.h missinig underline (#431) · hanqingwu/open-iscsi@2989724 (github.com)](https://github.com/hanqingwu/open-iscsi/commit/29897249ab77739f6b233677d761e24705b33f6a) \ No newline at end of file -- Gitee From 0d0d548e4f2a1a4e367b4ee133de52804111b6a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=91=E6=B2=A7?= <1050706328@qq.com> Date: Wed, 25 Sep 2024 06:48:46 +0000 Subject: [PATCH 30/35] =?UTF-8?q?declaration=20will=20not=20be=20visible?= =?UTF-8?q?=20outside=20of=20this=20function=E9=97=AE=E9=A2=98.md.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 云沧 <1050706328@qq.com> --- ... this function\351\227\256\351\242\230.md" | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 "LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/declaration will not be visible outside of this function\351\227\256\351\242\230.md" diff --git "a/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/declaration will not be visible outside of this function\351\227\256\351\242\230.md" "b/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/declaration will not be visible outside of this function\351\227\256\351\242\230.md" new file mode 100644 index 0000000..05cd34b --- /dev/null +++ "b/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/declaration will not be visible outside of this function\351\227\256\351\242\230.md" @@ -0,0 +1,27 @@ +# 1、问题现象 + +出自:https://gitee.com/src-openeuler/open-iscsi (openEuler-24.03-LTS) + + +```c +[ 95s] In file included from discoveryd.c:31: +[ 95s] ./iface.h:61:29: error: declaration of 'struct iovec' will not be visible outside of this function [-Werror,-Wvisibility] +[ 95s] 61 | int iface_all, struct iovec *iovs); +[ 95s] | ^ +[ 95s] 1 error generated. +``` + +# 2、问题定位 + +iface.h + +```c +extern int iface_build_net_config(struct iface_rec *iface_primary, + int iface_all, struct iovec *iovs); +``` + +经过查询,struct iovec的定义在系统库 中,而iface.h中既没有对struct iovec的定义,也没有包含该头文件 + +# 3、修改建议 + +在iface.h头文件中#include \ No newline at end of file -- Gitee From d4a093a0d3451b42cc66163fe0ef3d97828e24ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=91=E6=B2=A7?= <1050706328@qq.com> Date: Wed, 25 Sep 2024 11:57:40 +0000 Subject: [PATCH 31/35] =?UTF-8?q?attribute=20declaration=20must=20precede?= =?UTF-8?q?=20definition=E9=97=AE=E9=A2=98.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 云沧 <1050706328@qq.com> --- ...ede definition\351\227\256\351\242\230.md" | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 "LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/attribute declaration must precede definition\351\227\256\351\242\230.md" diff --git "a/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/attribute declaration must precede definition\351\227\256\351\242\230.md" "b/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/attribute declaration must precede definition\351\227\256\351\242\230.md" new file mode 100644 index 0000000..4e415b1 --- /dev/null +++ "b/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/attribute declaration must precede definition\351\227\256\351\242\230.md" @@ -0,0 +1,56 @@ +# 1、问题现象 + +出自:https://gitee.com/src-openeuler/open-iscsi (openEuler-24.03-LTS) + + +```c +[ 93s] In file included from io.c:41: +[ 93s] In file included from ./iface.h:23: +[ 93s] In file included from ../libopeniscsiusr/libopeniscsiusr/libopeniscsiusr.h:30: +[ 93s] ../libopeniscsiusr/libopeniscsiusr/libopeniscsiusr_common.h:75:8: error: attribute declaration must precede definition [-Werror,-Wignored-attributes] +[ 93s] 75 | struct __DLL_EXPORT iscsi_session; +[ 93s] | ^ +[ 93s] ../libopeniscsiusr/libopeniscsiusr/libopeniscsiusr_common.h:64:38: note: expanded from macro '__DLL_EXPORT' +[ 93s] 64 | #define __DLL_EXPORT __attribute__ ((visibility ("default"))) +[ 93s] | ^ +[ 93s] ./initiator.h:198:16: note: previous definition is here +[ 93s] 198 | typedef struct iscsi_session { +[ 93s] | ^ +``` + +# 2、问题定位 + +## 2.1、问题定位分析 + +网上搜索该问题,发现问题出在头文件的顺序上 + +头文件"iface.h"中声明了struct iscsi_session且声明了__DLL_EXPORT(该宏展开为\_\_attribute\_\_ ((visibility ("default")))),"initiator.h"中定义了struct iscsi_session,clang要求"attribute declaration must precede definition"即带有attribute的声明要先于其定义 + +以io.c为例 + +```c +... +#include "types.h" +#include "iscsi_proto.h" +#include "iscsi_settings.h" +#include "initiator.h" +#include "iscsi_ipc.h" +#include "log.h" +#include "transport.h" +#include "idbm.h" +#include "iface.h" +#include "sysdeps.h" +... +``` + +问题就出在\#include "initiator.h"和\#include "iface.h"的顺序上 + +只要将\#include "iface.h"移动到\#include "initiator.h"之前就能解决报错 + +## 2.2、问题总结及根因确认 + +clang要求"attribute declaration must precede definition"即带有attribute的声明必须先于定义,在该问题情境中体现为头文件的顺序,\#include "iface.h"要先于\#include "initiator.h" + +# 3、修改建议 + +通过移动头文件顺序的方式,使带有attribute的声明先于其定义 \ No newline at end of file -- Gitee From 6b5294dd3ab54da93890915d6f8ced7655f4b24f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=91=E6=B2=A7?= <1050706328@qq.com> Date: Wed, 25 Sep 2024 12:06:45 +0000 Subject: [PATCH 32/35] =?UTF-8?q?implicit=20truncation=20from=20'int'=20to?= =?UTF-8?q?=20a=20one-bit=20wide=20bit-field=20changes=20value=20from=201?= =?UTF-8?q?=20to=20-1=E9=97=AE=E9=A2=98.md.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 云沧 <1050706328@qq.com> --- ...e from 1 to -1\351\227\256\351\242\230.md" | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 "LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/implicit truncation from 'int' to a one-bit wide bit-field changes value from 1 to -1\351\227\256\351\242\230.md" diff --git "a/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/implicit truncation from 'int' to a one-bit wide bit-field changes value from 1 to -1\351\227\256\351\242\230.md" "b/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/implicit truncation from 'int' to a one-bit wide bit-field changes value from 1 to -1\351\227\256\351\242\230.md" new file mode 100644 index 0000000..a5bae95 --- /dev/null +++ "b/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/implicit truncation from 'int' to a one-bit wide bit-field changes value from 1 to -1\351\227\256\351\242\230.md" @@ -0,0 +1,63 @@ +# 1、问题现象 + +出自:https://gitee.com/src-openeuler/open-iscsi (openEuler-24.03-LTS) + + +```c +[ 88s] mgmt_ipc.c:511:19: error: implicit truncation from 'int' to a one-bit wide bit-field changes value from 1 to -1 [-Werror,-Wsingle-bit-bitfield-constant-conversion] +[ 88s] 511 | qtask->allocated = 1; +[ 88s] | ^ ~ +[ 88s] 1 error generated. +``` + +# 2、问题定位 + +## 2.1、问题定位分析 + +qtask的类型为queue_task_t,而queue_task_t的定义在usr/initiator.h中: + +```c +typedef struct queue_task { + iscsi_conn_t *conn; + iscsiadm_req_t req; + iscsiadm_rsp_t rsp; + int mgmt_ipc_fd; + int allocated : 1; + /* Newer request types include a + * variable-length payload */ + void *payload; +} queue_task_t; +``` + +这个错误是由于在代码中存在一个隐式截断问题。试图将一个 `int` 类型的值(这里是 `1`)赋给一个一位宽的位域(allocated),但由于位域的宽度为1位,这样的操作可能会导致值从`1`被截断为`-1` + +## 2.2、关于位域(bit-field) + +有些信息在存储时,并不需要占用一个完整的字节,而只需占几个或一个二进制位。例如在存放一个开关量时,只有 0 和 1 两种状态,用 1 位二进位即可。为了节省存储空间,并使处理简便,C 语言又提供了一种数据结构,称为"位域"或"位段"。 + +所谓"位域"是把一个字节中的二进位划分为几个不同的区域,并说明每个区域的位数。每个域有一个域名,允许在程序中按域名进行操作。这样就可以把几个不同的对象用一个字节的二进制位域来表示。 + +详见:[C 位域 | 菜鸟教程 (runoob.com)](https://www.runoob.com/cprogramming/c-bit-fields.html) + +这里的allocated本意是利用位域来节省空间,只有0和1两种状态,但是错误地将其类型设定为了int,这就会出现隐式截断的问题,正确的做法是将其类型设定为unsigned int + +## 2.3、问题总结及根因确认 + +clang比gcc检查更加严格,检测出了给位域赋值时可能出现的隐式截断问题 + +# 3、修改建议 + +方案一: + +修改`int allocated : 1`为`unsigned int allocated : 1` + +参考: + +方案二: + +改为适用bool类型赋值,而不是1 + +修改`qtask->allocated = 1;`为`qtask->allocated = true;` + + +方案一能从根源解决问题,因此方案一更优 \ No newline at end of file -- Gitee From b85060f1b8278360a17a26d9e8e405b14c5bc617 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=91=E6=B2=A7?= <1050706328@qq.com> Date: Wed, 25 Sep 2024 12:07:18 +0000 Subject: [PATCH 33/35] =?UTF-8?q?unused-but-set-variable=E9=97=AE=E9=A2=98?= =?UTF-8?q?.md.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 云沧 <1050706328@qq.com> --- ...t-set-variable\351\227\256\351\242\230.md" | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 "LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/unused-but-set-variable\351\227\256\351\242\230.md" diff --git "a/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/unused-but-set-variable\351\227\256\351\242\230.md" "b/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/unused-but-set-variable\351\227\256\351\242\230.md" new file mode 100644 index 0000000..86a34c6 --- /dev/null +++ "b/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/unused-but-set-variable\351\227\256\351\242\230.md" @@ -0,0 +1,51 @@ +# 1、问题现象 + +出自:https://gitee.com/src-openeuler/open-iscsi (openEuler-24.03-LTS) + + +```c +[ 93s] discovery.c:698:6: error: variable 'num_targets' set but not used [-Werror,-Wunused-but-set-variable] +[ 93s] 698 | int num_targets = 0; +[ 93s] | ^ +[ 93s] 1 warning and 1 error generated. +``` + +# 2、问题定位 + +查找num_targets在全文中的用法可知, + +![35a0fa6693b9c3d98c2b19e8349f662](assets/35a0fa6693b9c3d98c2b19e8349f662-20240920120905-2m2wo34.png) + +该变量在定义之后只有两个自增的操作 + +# 3、修改建议 + +方案一: + +理论上,这里的num_targets只有自增操作,并没有被具体使用,所以是可以将这三处出现的地方删除的 + +方案二: + +clang开启Werror将`unused-but-set-variable`当做error,所以可以添加-Wno-error=unused-but-set-variable将error降级为warning,使llvm能够构建 + +# 4、类似问题例子 + +出自:https://gitee.com/src-openeuler/opensc (openEuler-24.03-LTS) + +[backport 1 commit,fix clang build error · Pull Request !79 · src-openEuler/opensc - Gitee.com](https://gitee.com/src-openeuler/opensc/pulls/79/files) + +```c +[ 117s] pkcs11-tool.c:7304:6: error: variable 'errors' set but not used [-Werror,-Wunused-but-set-variable] +[ 117s] 7304 | int errors = 0; +[ 117s] | ^ +[ 117s] 1 error generated. +[ 117s] make[3]: *** [Makefile:1356: pkcs11_tool-pkcs11-tool.o] Error 1 +[ 117s] make[3]: *** Waiting for unfinished jobs.... +[ 117s] cardos-tool.c:1146:6: error: variable 'action_count' set but not used [-Werror,-Wunused-but-set-variable] +[ 117s] 1146 | int action_count = 0; +[ 117s] | ^ +[ 117s] 1 error generated. +``` + +* **问题成因总结:** clang开启Werror将`unused-but-set-variable`当做error +* **修改建议:** 添加-Wno-error=unused-but-set-variable将error改为warning,使llvm能够构建 \ No newline at end of file -- Gitee From f4001bea57c2c039bdf32c728df04bde8e897cdd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=91=E6=B2=A7?= <1050706328@qq.com> Date: Wed, 25 Sep 2024 12:08:14 +0000 Subject: [PATCH 34/35] =?UTF-8?q?update=20LLVM=20Parallel=20Universe=20Pro?= =?UTF-8?q?ject/=E9=97=AE=E9=A2=98=E5=AE=9A=E4=BD=8D=E6=80=BB=E7=BB=93/unu?= =?UTF-8?q?sed-but-set-variable=E9=97=AE=E9=A2=98.md.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 云沧 <1050706328@qq.com> --- .../unused-but-set-variable\351\227\256\351\242\230.md" | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git "a/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/unused-but-set-variable\351\227\256\351\242\230.md" "b/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/unused-but-set-variable\351\227\256\351\242\230.md" index 86a34c6..e7ddfa5 100644 --- "a/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/unused-but-set-variable\351\227\256\351\242\230.md" +++ "b/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/unused-but-set-variable\351\227\256\351\242\230.md" @@ -12,11 +12,7 @@ # 2、问题定位 -查找num_targets在全文中的用法可知, - -![35a0fa6693b9c3d98c2b19e8349f662](assets/35a0fa6693b9c3d98c2b19e8349f662-20240920120905-2m2wo34.png) - -该变量在定义之后只有两个自增的操作 +查找num_targets在全文中的用法可知,该变量在定义之后只有两个自增的操作,除此之外并没有被实际使用过 # 3、修改建议 -- Gitee From 0d5d094be4c0998ee8204b9626e40d8d0c73b5ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=91=E6=B2=A7?= <1050706328@qq.com> Date: Wed, 25 Sep 2024 12:08:33 +0000 Subject: [PATCH 35/35] =?UTF-8?q?update=20LLVM=20Parallel=20Universe=20Pro?= =?UTF-8?q?ject/=E9=97=AE=E9=A2=98=E5=AE=9A=E4=BD=8D=E6=80=BB=E7=BB=93/unu?= =?UTF-8?q?sed-but-set-variable=E9=97=AE=E9=A2=98.md.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 云沧 <1050706328@qq.com> --- .../unused-but-set-variable\351\227\256\351\242\230.md" | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git "a/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/unused-but-set-variable\351\227\256\351\242\230.md" "b/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/unused-but-set-variable\351\227\256\351\242\230.md" index e7ddfa5..56a58b1 100644 --- "a/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/unused-but-set-variable\351\227\256\351\242\230.md" +++ "b/LLVM Parallel Universe Project/\351\227\256\351\242\230\345\256\232\344\275\215\346\200\273\347\273\223/unused-but-set-variable\351\227\256\351\242\230.md" @@ -12,7 +12,7 @@ # 2、问题定位 -查找num_targets在全文中的用法可知,该变量在定义之后只有两个自增的操作,除此之外并没有被实际使用过 +查找num_targets在全文中的用法可知,该变量在定义之后只有两处自增的操作,除此之外并没有被实际使用过 # 3、修改建议 -- Gitee