On Debian Jessie, I get the warnings below when compiling core/cfg/cfg_ctx.c of Kamailio 5.0. If I remove -Wall, the warnings do not show up, but that is not a solution.
-- Juha
---------------------------------------------------------------------- gcc -funroll-loops -Wcast-align -m64 -minline-all-stringops -falign-loops -ftree-vectorize -fno-strict-overflow -Wall -D_FORTIFY_SOURCE=2 -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -DVERSION_NODATE -DNAME='"sip-proxy"' -DVERSION='"5.0.0-b14"' -DARCH='"x86_64"' -DOS='linux_' -DOS_QUOTED='"linux"' -DCOMPILER='"gcc 4.9.2"' -D__CPU_x86_64 -D__OS_linux -DSER_VER=5000000 -DCFG_DIR='"/etc/sip-proxy/"' -DRUN_DIR='"/var/run/sip-proxy"' -DPKG_MALLOC -DSHM_MEM -DSHM_MMAP -DDNS_IP_HACK -DUSE_MCAST -DUSE_TCP -DDISABLE_NAGLE -DHAVE_RESOLV_RES -DUSE_DNS_CACHE -DUSE_DNS_FAILOVER -DUSE_DST_BLACKLIST -DUSE_NAPTR -DWITH_XAVP -DMEM_JOIN_FREE -DMEM_JOIN_FREE -DF_MALLOC -DQ_MALLOC -DTLSF_MALLOC -DUSE_TLS -DTLS_HOOKS -DUSE_CORE_STATS -DSTATISTICS -DMALLOC_STATS -DWITH_AS_SUPPORT -DUSE_SCTP -DFAST_LOCK -DADAPTIVE_WAIT -DADAPTIVE_WAIT_LOOPS=1024 -DCC_GCC_LIKE_ASM -DHAVE_GETHOSTBYNAME2 -DHAVE_UNION_SEMUN -DHAVE_SCHED_YIELD -DHAVE_MSG_NOSIGNAL -DHAVE_MSGHDR_MSG_CONTROL -DHAVE_ALLOCA_H -DHAVE_TIMEGM -DHAVE_SCHED_SETSCHEDULER -DHAVE_IP_MREQN -DUSE_RAW_SOCKS -DHAVE_EPOLL -DHAVE_SIGIO_RT -DSIGINFO64_WORKARROUND -DUSE_FUTEX -DHAVE_SELECT -c core/cfg/cfg_ctx.c -o core/cfg/cfg_ctx.o -MMD -MP core/cfg/cfg_ctx.c: In function cfg_set_now: core/cfg/cfg_ctx.c:485:5: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing] group_inst = (cfg_group_inst_t *)translate_pointer((char *)new_array, ^ core/cfg/cfg_ctx.c:489:5: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing] CFG_GROUP_META(block, group)->array = new_array; ^ core/cfg/cfg_ctx.c:559:4: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing] if (block && (CFG_GROUP_META(block, group)->array != CFG_GROUP_META(*cfg_global, group)->array)) ^ core/cfg/cfg_ctx.c:559:4: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing] core/cfg/cfg_ctx.c:560:5: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing] new_array = CFG_GROUP_META(block, group)->array; ^ core/cfg/cfg_ctx.c:579:5: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing] replaced[i] = CFG_GROUP_META(*cfg_global, group)->array; ^ core/cfg/cfg_ctx.c: In function cfg_commit: core/cfg/cfg_ctx.c:1120:5: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing] if (!(CFG_GROUP_META(block, group)->array = ^ core/cfg/cfg_ctx.c:1128:5: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing] replaced[replaced_num] = CFG_GROUP_META(*cfg_global, group)->array; ^ core/cfg/cfg_ctx.c:1180:5: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing] && (CFG_GROUP_META(block, changed->group)->array != CFG_GROUP_META(*cfg_global, changed->group)->array) ^ core/cfg/cfg_ctx.c:1180:5: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing] core/cfg/cfg_ctx.c:1185:5: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing] replaced[replaced_num] = CFG_GROUP_META(*cfg_global, group)->array; ^ core/cfg/cfg_ctx.c:1220:4: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing] if (CFG_GROUP_META(block, group)->array ^ core/cfg/cfg_ctx.c:1221:5: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing] && (CFG_GROUP_META(block, group)->array != CFG_GROUP_META(*cfg_global, group)->array) ^ core/cfg/cfg_ctx.c:1221:5: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing] core/cfg/cfg_ctx.c:1223:5: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing] shm_free(CFG_GROUP_META(block, group)->array); ^ core/cfg/cfg_ctx.c: In function cfg_add_group_inst: core/cfg/cfg_ctx.c:1577:2: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing] CFG_GROUP_META(block, group)->array = new_array; ^ core/cfg/cfg_ctx.c:1578:2: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing] CFG_GROUP_META(block, group)->num++; ^ core/cfg/cfg_ctx.c:1580:2: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing] if (CFG_GROUP_META(*cfg_global, group)->array) { ^ core/cfg/cfg_ctx.c:1589:3: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing] replaced[0] = CFG_GROUP_META(*cfg_global, group)->array; ^ core/cfg/cfg_ctx.c: In function cfg_del_group_inst: core/cfg/cfg_ctx.c:1673:2: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing] CFG_GROUP_META(block, group)->array = new_array; ^ core/cfg/cfg_ctx.c:1674:2: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing] CFG_GROUP_META(block, group)->num--; ^ core/cfg/cfg_ctx.c:1676:2: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing] if (CFG_GROUP_META(*cfg_global, group)->array) { ^ core/cfg/cfg_ctx.c:1687:5: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing] && (*(char **)(group_inst->vars + var->offset) != NULL) ^ core/cfg/cfg_ctx.c:1705:6: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing] && (*(char **)(group_inst->vars + var->offset) != NULL) ^ core/cfg/cfg_ctx.c:1707:6: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing] replaced[num] = *(char **)(group_inst->vars + var->offset); ^ core/cfg/cfg_ctx.c:1713:3: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing] replaced[num] = CFG_GROUP_META(*cfg_global, group)->array; ^
I just did a test again, Debian Jessie, -Wall is there, the result doesn't show any warning like you report. It is just make as we have it default in the Makefiles:
``` kamailio-dev$ make Q=0 make -C src/ make[1]: Entering directory '/home/porto/work/sip/esr/kamailio-dev/src' Makefile.defs defs skipped gcc -g -funroll-loops -Wcast-align -m64 -minline-all-stringops -falign-loops -ftree-vectorize -fno-strict-overflow -Wall -DNAME='"kamailio"' -DVERSION='"5.1.0-dev1"' -DARCH='"x86_64"' -DOS='linux_' -DOS_QUOTED='"linux"' -DCOMPILER='"gcc 4.9.2"' -D__CPU_x86_64 -D__OS_linux -DSER_VER=5001000 -DCFG_DIR='"/tmp/kamailio-dev/etc/kamailio/"' -DRUN_DIR='"/var/run/kamailio/"' -DPKG_MALLOC -DSHM_MEM -DSHM_MMAP -DDNS_IP_HACK -DUSE_MCAST -DUSE_TCP -DDISABLE_NAGLE -DHAVE_RESOLV_RES -DUSE_DNS_CACHE -DUSE_DNS_FAILOVER -DUSE_DST_BLACKLIST -DUSE_NAPTR -DWITH_XAVP -DMEM_JOIN_FREE -DF_MALLOC -DQ_MALLOC -DTLSF_MALLOC -DDBG_SR_MEMORY -DUSE_TLS -DTLS_HOOKS -DUSE_CORE_STATS -DSTATISTICS -DMALLOC_STATS -DWITH_AS_SUPPORT -DUSE_SCTP -DFAST_LOCK -DADAPTIVE_WAIT -DADAPTIVE_WAIT_LOOPS=1024 -DCC_GCC_LIKE_ASM -DHAVE_GETHOSTBYNAME2 -DHAVE_UNION_SEMUN -DHAVE_SCHED_YIELD -DHAVE_MSG_NOSIGNAL -DHAVE_MSGHDR_MSG_CONTROL -DHAVE_ALLOCA_H -DHAVE_TIMEGM -DHAVE_SCHED_SETSCHEDULER -DHAVE_IP_MREQN -DHAVE_EPOLL -DHAVE_SIGIO_RT -DSIGINFO64_WORKARROUND -DUSE_FUTEX -DHAVE_SELECT -c core/cfg/cfg_ctx.c -o core/cfg/cfg_ctx.o -MMD -MP gcc -m64 -Wl,-O2 -Wl,-E main.o core/core_cmd.o core/xavp.o core/basex.o core/rvalue.o core/str.o core/io_wait.o core/action.o core/bit_count.o core/tsend.o core/tcp_stats.o core/socket_info.o core/locking.o core/counters.o core/select_core.o core/lvalue.o core/dset.o core/data_lump_rpl.o core/udp_server.o core/kemi.o core/md5utils.o core/atomic_ops.o core/timer.o core/tcp_options.o core/tcp_main.o core/id.o core/stun.o core/pass_fd.o core/crc.o core/script_cb.o core/switch.o core/usr_avp.o core/forward.o core/nonsip_hooks.o core/mod_fix.o core/sip_msg_clone.o core/qvalue.o core/ut.o core/md5.o core/srapi.o core/sr_module.o core/pt.o core/stats.o core/cfg_parser.o core/bit_scan.o core/raw_listener.o core/msg_translator.o core/local_timer.o core/receive.o core/proxy.o core/ver.o core/select_buf.o core/ppcfg.o core/select.o core/lock_ops.o core/ip_addr.o core/pv_core.o core/hash_func.o core/signals.o core/cfg_core.o core/async_task.o core/re.o core/data_lump.o core/flags.o core/shm_init.o core/error.o core/sock_ut.o core/tls_hooks.o core/str_list.o core/pvapi.o core/sctp_core.o core/dprint.o core/fmsg.o core/endianness.o core/raw_sock.o core/timer_proc.o core/daemonize.o core/sr_compat.o core/events.o core/dns_func.o core/resolve.o core/modparam.o core/tcp_read.o core/route.o core/dns_cache.o core/dst_blacklist.o core/strutils.o core/route_struct.o core/rpc_lookup.o core/mem/dl_malloc.o core/mem/pkg.o core/mem/mem.o core/mem/f_malloc.o core/mem/memtest.o core/mem/shm.o core/mem/ll_malloc.o core/mem/shm_mem.o core/mem/tlsf_malloc.o core/mem/sf_malloc.o core/mem/q_malloc.o core/parser/parse_uri.o core/parser/parse_disposition.o core/parser/parse_body.o core/parser/parse_methods.o core/parser/parse_from.o core/parser/parser_f.o core/parser/parse_sipifmatch.o core/parser/parse_require.o core/parser/parse_rpid.o core/parser/parse_allow.o core/parser/parse_supported.o core/parser/parse_content.o core/parser/parse_hname2.o core/parser/msg_parser.o core/parser/parse_identity.o core/parser/parse_subscription_state.o core/parser/parse_fline.o core/parser/parse_to.o core/parser/hf.o core/parser/parse_refer_to.o core/parser/parse_cseq.o core/parser/parse_nameaddr.o core/parser/parse_via.o core/parser/parse_expires.o core/parser/parse_ppi_pai.o core/parser/parse_identityinfo.o core/parser/parse_rr.o core/parser/parse_param.o core/parser/parse_retry_after.o core/parser/parse_date.o core/parser/parse_addr_spec.o core/parser/parse_hostport.o core/parser/parse_event.o core/parser/parse_privacy.o core/parser/parse_diversion.o core/parser/parse_option_tags.o core/parser/digest/param_parser.o core/parser/digest/digest_parser.o core/parser/digest/digest.o core/parser/contact/contact.o core/parser/contact/parse_contact.o core/parser/sdp/sdp.o core/parser/sdp/sdp_helpr_funcs.o core/rand/fastrand.o core/rand/isaac/rand.o core/cfg/cfg_struct.o core/cfg/cfg_select.o core/cfg/cfg_ctx.o core/cfg/cfg.o core/cfg/cfg_script.o core/lex.yy.o core/cfg.tab.o -ldl -lresolv -o kamailio ```
Daniel-Constantin Mierla writes:
I just did a test again, Debian Jessie, -Wall is there, the result doesn't show any warning like you report. It is just make as we have it default in the Makefiles:
I don't get any warnings either if I run the same command as you:
/usr/src/orig/kamailio/src$ gcc -g -funroll-loops -Wcast-align -m64 -minline-all-stringops -falign-loops -ftree-vectorize -fno-strict-overflow -Wall -DNAME='"kamailio"' -DVERSION='"5.1.0-dev1"' -DARCH='"x86_64"' -DOS='linux_' -DOS_QUOTED='"linux"' -DCOMPILER='"gcc 4.9.2"' -D__CPU_x86_64 -D__OS_linux -DSER_VER=5001000 -DCFG_DIR='"/tmp/kamailio-dev/etc/kamailio/"' -DRUN_DIR='"/var/run/kamailio/"' -DPKG_MALLOC -DSHM_MEM -DSHM_MMAP -DDNS_IP_HACK -DUSE_MCAST -DUSE_TCP -DDISABLE_NAGLE -DHAVE_RESOLV_RES -DUSE_DNS_CACHE -DUSE_DNS_FAILOVER -DUSE_DST_BLACKLIST -DUSE_NAPTR -DWITH_XAVP -DMEM_JOIN_FREE -DF_MALLOC -DQ_MALLOC -DTLSF_MALLOC -DDBG_SR_MEMORY -DUSE_TLS -DTLS_HOOKS -DUSE_CORE_STATS -DSTATISTICS -DMALLOC_STATS -DWITH_AS_SUPPORT -DUSE_SCTP -DFAST_LOCK -DADAPTIVE_WAIT -DADAPTIVE_WAIT_LOOPS=1024 -DCC_GCC_LIKE_ASM -DHAVE_GETHOSTBYNAME2 -DHAVE_UNION_SEMUN -DHAVE_SCHED_YIELD -DHAVE_MSG_NOSIGNAL -DHAVE_MSGHDR_MSG_CONTROL -DHAVE_ALLOCA_H -DHAVE_TIMEGM -DHAVE_SCHED_SETSCHEDULER -DHAVE_IP_MREQN -DHAVE_EPOLL -DHAVE_SIGIO_RT -DSIGINFO64_WORKARROUND -DUSE_FUTEX -DHAVE_SELECT -c core/cfg/cfg_ctx.c -o core/cfg/cfg_ctx.o -MMD -MP
But I have -O2 param and if I add it to your command, I get the warnings:
/usr/src/orig/kamailio/src$ gcc -g -O2 -funroll-loops -Wcast-align -m64 -minline-all-stringops -falign-loops -ftree-vectorize -fno-strict-overflow -Wall -DNAME='"kamailio"' -DVERSION='"5.1.0-dev1"' -DARCH='"x86_64"' -DOS='linux_' -DOS_QUOTED='"linux"' -DCOMPILER='"gcc 4.9.2"' -D__CPU_x86_64 -D__OS_linux -DSER_VER=5001000 -DCFG_DIR='"/tmp/kamailio-dev/etc/kamailio/"' -DRUN_DIR='"/var/run/kamailio/"' -DPKG_MALLOC -DSHM_MEM -DSHM_MMAP -DDNS_IP_HACK -DUSE_MCAST -DUSE_TCP -DDISABLE_NAGLE -DHAVE_RESOLV_RES -DUSE_DNS_CACHE -DUSE_DNS_FAILOVER -DUSE_DST_BLACKLIST -DUSE_NAPTR -DWITH_XAVP -DMEM_JOIN_FREE -DF_MALLOC -DQ_MALLOC -DTLSF_MALLOC -DDBG_SR_MEMORY -DUSE_TLS -DTLS_HOOKS -DUSE_CORE_STATS -DSTATISTICS -DMALLOC_STATS -DWITH_AS_SUPPORT -DUSE_SCTP -DFAST_LOCK -DADAPTIVE_WAIT -DADAPTIVE_WAIT_LOOPS=1024 -DCC_GCC_LIKE_ASM -DHAVE_GETHOSTBYNAME2 -DHAVE_UNION_SEMUN -DHAVE_SCHED_YIELD -DHAVE_MSG_NOSIGNAL -DHAVE_MSGHDR_MSG_CONTROL -DHAVE_ALLOCA_H -DHAVE_TIMEGM -DHAVE_SCHED_SETSCHEDULER -DHAVE_IP_MREQN -DHAVE_EPOLL -DHAVE_SIGIO_RT -DSIGINFO64_WORKARROUND -DUSE_FUTEX -DHAVE_SELECT -c core/cfg/cfg_ctx.c -o core/cfg/cfg_ctx.o -MMD -MP core/cfg/cfg_ctx.c: In function ‘cfg_set_now’: core/cfg/cfg_ctx.c:485:5: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing] group_inst = (cfg_group_inst_t *)translate_pointer((char *)new_array, ^ ...
-- Juha
If people want to play with extra compiler flags it is ok, perhaps there are other flags that can throw more warnings. At least for myself, I have to time to hunt all those options in gcc/clang and see which reported warnings are valid or not. I consider that the default compile flags are the ones we have to report to. Anything else should be more like an enhancement, not an issue.
Again, any dev that wants to jump and investigate such reports with different compiler flags are more than welcome to do and contribute fixes if they find something to sort out.
Daniel-Constantin Mierla writes:
If people want to play with extra compiler flags it is ok, perhaps there are other flags that can throw more warnings.
OK. I have not added -O2 flag. It must be standard flag setting when building Debian packages.
-- Juha
-O2 flags comes from this line in debian/rules:
CC_EXTRA_OPTS += $(shell dpkg-buildflags --get CFLAGS)
which gives:
$ dpkg-buildflags --get CFLAGS -g -O2 -fstack-protector-strong -Wformat -Werror=format-security
In order to avoid the warnings, something needs to be changed in rules file to override the default value -O2;
So I would argue that this is not an enhancement request but a bug in debian/rules. I don't know how to change this back to a bug issue.
@juha-h I'm responsable of debian/rules adding ``DEB_CFLAGS_MAINT_STRIP=-O2`` will remove -O2 from the flags
I will take care, thanks for reporting
Closed #1004 via 6ba9900f3c83bbd68ef868a8910590f6c9fbe88f.