Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix compiling warnings on fedora40 #1515

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

zhijianli88
Copy link
Contributor

@zhijianli88 zhijianli88 commented Nov 12, 2024

Recently, I updated my host to fedora40 and rebuilt the rdma-core. The compiler complained a few warnings.
gcc: gcc (GCC) 14.2.1 20240912 (Red Hat 14.2.1-3)

make -C build 2>&1 | grep -i -A3 -B1 warning
[ 37%] Building C object librdmacm/CMakeFiles/rspreload.dir/preload.c.o
/home/lizhijian/rdma-core/librdmacm/preload.c:1175:5: warning: no previous prototype for ‘__fxstat’ [-Wmissing-prototypes]
 1175 | int __fxstat(int ver, int socket, struct stat *buf)
      |     ^~~~~~~~
[ 37%] Linking C shared module ../lib/librspreload.so
--
/home/lizhijian/rdma-core/providers/mlx5/dr_vports.c: In function ‘dr_vports_table_del_wire’:
/home/lizhijian/rdma-core/providers/mlx5/dr_vports.c:247:36: warning: ‘prev’ may be used uninitialized [-Wmaybe-uninitialized]
  247 |                         prev->next = vport->next;
      |                         ~~~~~~~~~~~^~~~~~~~~~~~~
/home/lizhijian/rdma-core/providers/mlx5/dr_vports.c:231:43: note: ‘prev’ was declared here
--
/home/lizhijian/rdma-core/libibnetdisc/ibnetdisc_cache.c: In function ‘_rebuild_nodes’:
/home/lizhijian/rdma-core/libibnetdisc/ibnetdisc_cache.c:560:36: warning: ‘calloc’ sizes specified with ‘sizeof’ in the earlier argument and not in the later argument [-Wcalloc-transposed-args]
  560 |                       calloc(sizeof(*node->ports), node->numports + 1))) {
      |                                    ^
/home/lizhijian/rdma-core/libibnetdisc/ibnetdisc_cache.c:560:36: note: earlier argument should specify number of elements, later size of each element
--
/home/lizhijian/rdma-core/build/pyverbs/providers/mlx5/mlx5dv.c: In function ‘__pyx_pf_7pyverbs_9providers_4mlx5_6mlx5dv_10WqeCtrlSeg___init__’:
/home/lizhijian/rdma-core/build/pyverbs/providers/mlx5/mlx5dv.c:48608:53: warning: ‘calloc’ sizes specified with ‘sizeof’ in the earlier argument and not in the later argument [-Wcalloc-transposed-args]
48608 |   __pyx_v_self->__pyx_base.segment = calloc((sizeof(struct mlx5_wqe_ctrl_seg)), 1);
      |                                                     ^~~~~~
/home/lizhijian/rdma-core/build/pyverbs/providers/mlx5/mlx5dv.c:48608:53: note: earlier argument should specify number of elements, later size of each element
/home/lizhijian/rdma-core/build/pyverbs/providers/mlx5/mlx5dv.c: In function ‘__pyx_pf_7pyverbs_9providers_4mlx5_6mlx5dv_10WqeDataSeg___init__’:
/home/lizhijian/rdma-core/build/pyverbs/providers/mlx5/mlx5dv.c:50301:53: warning: ‘calloc’ sizes specified with ‘sizeof’ in the earlier argument and not in the later argument [-Wcalloc-transposed-args]
50301 |   __pyx_v_self->__pyx_base.segment = calloc((sizeof(struct mlx5_wqe_data_seg)), 1);
      |                                                     ^~~~~~
/home/lizhijian/rdma-core/build/pyverbs/providers/mlx5/mlx5dv.c:50301:53: note: earlier argument should specify number of elements, later size of each element
At top level:
cc1: note: unrecognized command-line option ‘-Wno-unknown-warning-option’ may have been intended to silence earlier diagnostics
cc1: note: unrecognized command-line option ‘-Wno-unknown-warning’ may have been intended to silence earlier diagnostics
[ 82%] Linking C shared library ../../../python/pyverbs/providers/mlx5/mlx5dv.cpython-312-x86_64-linux-gnu.so
[ 82%] Built target mlx5dv.cpython-312-x86_64-linux-gnu
[ 83%] Linking C shared library ../../../python/pyverbs/providers/mlx5/mlx5dv_crypto.cpython-312-x86_64-linux-gnu.so
--
/home/lizhijian/rdma-core/librdmacm/examples/cmtime.c: In function ‘main’:
/home/lizhijian/rdma-core/librdmacm/examples/cmtime.c:993:31: warning: ‘calloc’ sizes specified with ‘sizeof’ in the earlier argument and not in the later argument [-Wcalloc-transposed-args]
  993 |         nodes = calloc(sizeof *nodes, iter);
      |                               ^
/home/lizhijian/rdma-core/librdmacm/examples/cmtime.c:993:31: note: earlier argument should specify number of elements, later size of each element

Thi PR intends to fix them.

This patch addresses a compiler warning indicating that the 'prev'
variable may be used uninitialized in the function
dr_vports_table_del_wire. Although this warning is a false positive,
it is important to resolve it to prevent potential confusion and
maintain code quality.

The 'while (vport)' loop is intended to start from the second element
of the linked list, as the first element is already checked by a
preceding condition. By initializing 'prev' to the first element
and 'vport' to 'prev->next', we ensure that the loop logic remains
correct and the warning is eliminated.

This change does not alter the functionality of the code but enhances
its clarity and robustness by ensuring all variables are properly
initialized before use.

Signed-off-by: Li Zhijian <[email protected]>
This commit fixes a compiler warning related to the use of calloc.
```
libibnetdisc/ibnetdisc_cache.c:560:36: warning: ‘calloc’ sizes specified with ‘sizeof’ in the earlier argument and not in the later argument [-Wcalloc-transposed-args]
  560 |                       calloc(sizeof(*node->ports), node->numports + 1))) {
      |                                    ^
libibnetdisc/ibnetdisc_cache.c:560:36: note: earlier argument should specify number of elements, later size of each element
```

The warning was due to transposed arguments in the calloc call, where the
number of elements and the size of each element were specified in the wrong
order.

The correct order for calloc's arguments is:
void *calloc(size_t nmemb, size_t size)

Signed-off-by: Li Zhijian <[email protected]>
This commit fixes a compiler warning related to the use of calloc.
```
librdmacm/examples/cmtime.c:993:31: warning: ‘calloc’ sizes specified with ‘sizeof’ in the earlier argument and not in the later argument [-Wcalloc-transposed-args]
  993 |         nodes = calloc(sizeof *nodes, iter);
      |                               ^
librdmacm/examples/cmtime.c:993:31: note: earlier argument should specify number of elements, later size of each element

```

The warning was due to transposed arguments in the calloc call,
where the number of elements and the size of each element were
specified in the wrong order.

The correct order for calloc's arguments is:
void *calloc(size_t nmemb, size_t size)

Signed-off-by: Li Zhijian <[email protected]>
This commit fixes a compiler warning related to the use of calloc.
```
rdma-core/build/pyverbs/providers/mlx5/mlx5dv.c: In function ‘__pyx_pf_7pyverbs_9providers_4mlx5_6mlx5dv_10WqeCtrlSeg___init__’:
rdma-core/build/pyverbs/providers/mlx5/mlx5dv.c:48608:53: warning: ‘calloc’ sizes specified with ‘sizeof’ in the earlier argument and not in the later argument [-Wcalloc-transposed-args]
48608 |   __pyx_v_self->__pyx_base.segment = calloc((sizeof(struct mlx5_wqe_ctrl_seg)), 1);
      |                                                     ^~~~~~
rdma-core/build/pyverbs/providers/mlx5/mlx5dv.c:48608:53: note: earlier argument should specify number of elements, later size of each element
rdma-core/build/pyverbs/providers/mlx5/mlx5dv.c: In function ‘__pyx_pf_7pyverbs_9providers_4mlx5_6mlx5dv_10WqeDataSeg___init__’:
rdma-core/build/pyverbs/providers/mlx5/mlx5dv.c:50301:53: warning: ‘calloc’ sizes specified with ‘sizeof’ in the earlier argument and not in the later argument [-Wcalloc-transposed-args]
50301 |   __pyx_v_self->__pyx_base.segment = calloc((sizeof(struct mlx5_wqe_data_seg)), 1);
      |                                                     ^~~~~~
rdma-core/build/pyverbs/providers/mlx5/mlx5dv.c:50301:53: note: earlier argument should specify number of elements, later size of each element

```

The warning was due to transposed arguments in the calloc call,
where the number of elements and the size of each element were
specified in the wrong order.

The correct order for calloc's arguments is:
void *calloc(size_t nmemb, size_t size)

Signed-off-by: Li Zhijian <[email protected]>
@zhijianli88 zhijianli88 changed the title Fix compiling warnings Fix compiling warnings on fedora40 Nov 13, 2024
Copy link
Contributor Author

@zhijianli88 zhijianli88 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's believed that there is something wrong/BUG in ccache

  1. let's open the compiling command with make VERBOSE=1
cd /home/lizhijian/rdma-core/build/librdmacm && cc -DVERBS_DEBUG -Drspreload_EXPORTS -I/home/lizhijian/rdma-core/build/include -I/usr/include/libnl3 -I/usr/include/drm -Wall -Wextra -Wno-sign-compare -Wno-unused-parameter -Wmissing-prototypes -Wmissing-declarations -Wwrite-strings -Wformat=2 -Wcast-function-type -Wformat-nonliteral -Wdate-time -Wnested-externs -Wshadow -Wstrict-prototypes -Wold-style-definition -Wredundant-decls -O2 -g -DNDEBUG -std=gnu11 -fPIC -MD -MT librdmacm/CMakeFiles/rspreload.dir/preload.c.o -MF CMakeFiles/rspreload.dir/preload.c.o.d -o CMakeFiles/rspreload.dir/preload.c.o -c /home/lizhijian/rdma-core/librdmacm/preload.c
/home/lizhijian/rdma-core/librdmacm/preload.c:1175:5: warning: no previous prototype for ‘__fxstat’ [-Wmissing-prototypes]
 1175 | int __fxstat(int ver, int socket, struct stat *buf)
      |     ^~~~~~~~
  1. check what is the default cc
# whereis cc
cc: /usr/bin/cc /usr/lib64/ccache/cc
# which cc
/usr/lib64/ccache/cc

We can see, it's a built-in command of the ccache.

  1. change the cc to GCC version, it works well
cd /home/lizhijian/rdma-core/build/librdmacm && /usr/bin/cc -DVERBS_DEBUG -Drspreload_EXPORTS -I/home/lizhijian/rdma-core/build/include -I/usr/include/libnl3 -I/usr/include/drm -Wall -Wextra -Wno-sign-compare -Wno-unused-parameter -Wmissing-prototypes -Wmissing-declarations -Wwrite-strings -Wformat=2 -Wcast-function-type -Wformat-nonliteral -Wdate-time -Wnested-externs -Wshadow -Wstrict-prototypes -Wold-style-definition -Wredundant-decls -O2 -g -DNDEBUG -std=gnu11 -fPIC -MD -MT librdmacm/CMakeFiles/rspreload.dir/preload.c.o -MF CMakeFiles/rspreload.dir/preload.c.o.d -o CMakeFiles/rspreload.dir/preload.c.o -c /home/lizhijian/rdma-core/librdmacm/preload.c
<no warning>
  1. pre-complie the C to extend all the includes and macros, and then build it with ccache cc, it also works
# pre-complie
build/librdmacm# /usr/lib64/ccache/cc -DVERBS_DEBUG -Drspreload_EXPORTS -I/home/lizhijian/rdma-core/build/include -I/usr/include/libnl3 -I/usr/include/drm -Wall -Wextra -Wno-sign-compare -Wno-unused-parameter -Wmissing-prototypes -Wmissing-declarations -Wwrite-strings -Wformat=2 -Wcast-function-type -Wformat-nonliteral -Wdate-time -Wnested-externs -Wshadow -Wstrict-prototypes -Wold-style-definition -Wredundant-decls -O2 -g -DNDEBUG -std=gnu11 -fPIC -MD -MT librdmacm/CMakeFiles/rspreload.dir/preload.c.o -MF CMakeFiles/rspreload.dir/preload.c.o.d -c /home/lizhijian/rdma-core/librdmacm/preload.c -E -o preload.i


# compile to object file
build/librdmacm# /usr/lib64/ccache/cc -DVERBS_DEBUG -Drspreload_EXPORTS -I/home/lizhijian/rdma-core/build/include -I/usr/include/libnl3 -I/usr/include/drm -Wall -Wextra -Wno-sign-compare -Wno-unused-parameter -Wmissing-prototypes -Wmissing-declarations -Wwrite-strings -Wformat=2 -Wcast-function-type -Wformat-nonliteral -Wdate-time -Wnested-externs -Wshadow -Wstrict-prototypes -Wold-style-definition -Wredundant-decls -O2 -g -DNDEBUG -std=gnu11 -fPIC -MD -MT librdmacm/CMakeFiles/rspreload.dir/preload.c.o -MF CMakeFiles/rspreload.dir/preload.c.o.d -c preload.i -o preload.i.o

So, it's believed that there is something wrong in the ccache cc

@zhijianli88
Copy link
Contributor Author

zhijianli88 commented Nov 14, 2024

It's believed that there is something wrong/BUG in ccache

  1. let's open the compiling command with make VERBOSE=1
cd /home/lizhijian/rdma-core/build/librdmacm && cc -DVERBS_DEBUG -Drspreload_EXPORTS -I/home/lizhijian/rdma-core/build/include -I/usr/include/libnl3 -I/usr/include/drm -Wall -Wextra -Wno-sign-compare -Wno-unused-parameter -Wmissing-prototypes -Wmissing-declarations -Wwrite-strings -Wformat=2 -Wcast-function-type -Wformat-nonliteral -Wdate-time -Wnested-externs -Wshadow -Wstrict-prototypes -Wold-style-definition -Wredundant-decls -O2 -g -DNDEBUG -std=gnu11 -fPIC -MD -MT librdmacm/CMakeFiles/rspreload.dir/preload.c.o -MF CMakeFiles/rspreload.dir/preload.c.o.d -o CMakeFiles/rspreload.dir/preload.c.o -c /home/lizhijian/rdma-core/librdmacm/preload.c
/home/lizhijian/rdma-core/librdmacm/preload.c:1175:5: warning: no previous prototype for ‘__fxstat’ [-Wmissing-prototypes]
 1175 | int __fxstat(int ver, int socket, struct stat *buf)
      |     ^~~~~~~~

Droped the fixing __fxstat patch because it's not rdma-core's problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant