Menu

#71 Linking issues on gcc v10

v0.8.6
open
nobody
None
1
2020-06-17
2020-06-17
No

Hello,
I encountered some linking issues on gcc in version 10.

[pzydziak@pzydziak bacnet-stack-0.8.6]$ make
make -s -C lib all
../src/bvlc.c: In function 'bvlc_bdt_restore_local':
../src/bvlc.c:163:13: warning: implicit declaration of function 'memcpy' [-Wimplicit-function-declaration]
  163 |             memcpy(BBMD_Table, BBMD_Table_tmp, sizeof(BBMD_TABLE_ENTRY) * MAX_BBMD_ENTRIES);
      |             ^~~~~~
../src/bvlc.c:163:13: warning: incompatible implicit declaration of built-in function 'memcpy'
../src/bvlc.c:46:1: note: include '<string.h>' or provide a declaration of 'memcpy'
   45 | #include "debug.h"
  +++ |+#include <string.h>
   46 | 
../src/bvlc.c: In function 'bvlc_internet_to_bacnet_address':
../src/bvlc.c:214:9: warning: incompatible implicit declaration of built-in function 'memcpy'
  214 |         memcpy(&src->mac[0], &sin->sin_addr.s_addr, 4);
      |         ^~~~~~
../src/bvlc.c:214:9: note: include '<string.h>' or provide a declaration of 'memcpy'
../src/bvlc.c: In function 'bvlc_encode_bip_address':
../src/bvlc.c:247:9: warning: incompatible implicit declaration of built-in function 'memcpy'
  247 |         memcpy(&pdu[0], &address->s_addr, 4);
      |         ^~~~~~
../src/bvlc.c:247:9: note: include '<string.h>' or provide a declaration of 'memcpy'
../src/bvlc.c: In function 'bvlc_decode_bip_address':
../src/bvlc.c:271:9: warning: incompatible implicit declaration of built-in function 'memcpy'
  271 |         memcpy(&address->s_addr, &pdu[0], 4);
      |         ^~~~~~
../src/bvlc.c:271:9: note: include '<string.h>' or provide a declaration of 'memcpy'
../src/bvlc.c: In function 'bvlc_encode_address_entry':
../src/bvlc.c:298:9: warning: incompatible implicit declaration of built-in function 'memcpy'
  298 |         memcpy(&pdu[len], &mask->s_addr, 4);
      |         ^~~~~~
../src/bvlc.c:298:9: note: include '<string.h>' or provide a declaration of 'memcpy'
../src/bvlc.c: In function 'bvlc_create_bdt':
../src/bvlc.c:756:13: warning: incompatible implicit declaration of built-in function 'memcpy'
  756 |             memcpy(&BBMD_Table[i].dest_address.s_addr, &npdu[pdu_offset], 4);
      |             ^~~~~~
../src/bvlc.c:756:13: note: include '<string.h>' or provide a declaration of 'memcpy'
../src/bvlc.c: In function 'bvlc_send_mpdu':
../src/bvlc.c:889:5: warning: implicit declaration of function 'memset' [-Wimplicit-function-declaration]
  889 |     memset(&(bvlc_dest.sin_zero), '\0', 8);
      |     ^~~~~~
../src/bvlc.c:889:5: warning: incompatible implicit declaration of built-in function 'memset'
../src/bvlc.c:889:5: note: include '<string.h>' or provide a declaration of 'memset'
../src/bvlc.c: In function 'bvlc_bdt_forward_npdu':
../src/bvlc.c:965:17: warning: implicit declaration of function 'inet_ntoa' [-Wimplicit-function-declaration]
  965 |                 inet_ntoa(bip_dest.sin_addr), ntohs(bip_dest.sin_port));
      |                 ^~~~~~~~~
../src/bvlc.c: In function 'bvlc_send_pdu':
../src/bvlc.c:1574:5: warning: incompatible implicit declaration of built-in function 'memcpy'
 1574 |     memcpy(&mtu[mtu_len], pdu, pdu_len);
      |     ^~~~~~
../src/bvlc.c:1574:5: note: include '<string.h>' or provide a declaration of 'memcpy'
make -s -C demo all
   text    data     bss     dec     hex filename
 132299   17540  416896  566735   8a5cf bacrp
/usr/bin/ld: main.o: in function `main':
main.c:(.text.startup+0x25a): undefined reference to `bacapp_parse_application_data'
collect2: error: ld returned 1 exit status
make[2]: *** [Makefile:20: bacwp] Error 1
make[1]: *** [Makefile:76: writeprop.all] Error 2
make: *** [Makefile:65: demos] Error 2
[pzydziak@pzydziak bacnet-stack-0.8.6]$ 

I have found this in gcc changelog, what seems to be a source of a problem.

C language issues
Default to -fno-common
A common mistake in C is omitting extern when declaring a global variable in a header file. If the header is included by several files it results in multiple definitions of the same variable. In previous GCC versions this error is ignored. GCC 10 defaults to -fno-common, which means a linker error will now be reported. To fix this, use extern in header files when declaring global variables, and ensure each global is defined in exactly one C file. If tentative definitions of particular variables need to be placed in a common block, attribute((common)) can be used to force that behavior even in code compiled without -fcommon. As a workaround, legacy C code where all tentative definitions should be placed into a common block can be compiled with -fcommon.
int x; // tentative definition - avoid in header files
extern int y; // correct declaration in a header file

I was able to fix it temporarly by adding this:

  @@ -45,8 +45,8 @@ OPTIMIZATION = -O0
 DEBUGGING = -g -DDEBUG_ENABLED=1
 endif
 # put all the flags together
-CFLAGS := -Wall $(DEBUGGING) $(OPTIMIZATION) $(INCLUDES) $(DEFINES)
-LFLAGS := -Wl,$(BACNET_LIB),$(SYSTEM_LIB)
+CFLAGS := -Wall $(DEBUGGING) $(OPTIMIZATION) $(INCLUDES) $(DEFINES) -fcommon
+LFLAGS := -Wl,$(BACNET_LIB),$(SYSTEM_LIB) -fcommon

 .EXPORT_ALL_VARIABLES:

My environment:

gcc version 10.1.0 (GCC) 
GNU ld (GNU Binutils) 2.34.0

Additional note:
When make -s -C lib is executed the generated libbacnetstack.a seems to not include bip_* functions, which also cased a bit o problems when i wanted to build and link liblary solely.

[pzydziak@pzydziak bacnet-stack-0.8.6]$ make clean
make -s -C lib clean
make -s -C demo clean
make -s -C demo/router clean
make -s -C demo/router-ipv6 clean
make -s -C demo/gateway clean
[pzydziak@pzydziak bacnet-stack-0.8.6]$ make -s -C lib
../demo/handler/dlenv.c: In function dlenv_register_as_foreign_device:
../demo/handler/dlenv.c:153:13: warning: implicit declaration of function inet_ntoa [-Wimplicit-function-declaration]
  153 |             inet_ntoa(addr), bbmd_port, bbmd_timetolive_seconds);
      |             ^~~~~~~~~
[pzydziak@pzydziak bacnet-stack-0.8.6]$ cd lib/
[pzydziak@pzydziak lib]$ readelf -a ./libbacnet.a | grep bip_cleanup
[pzydziak@pzydziak lib]$ 

Discussion

Anonymous
Anonymous

Add attachments
Cancel