The Airliner unit test system appears to link multiple copies of the same object file when building tests, relying on the linker to silently discard one of the copies. I believe doing so is undefined behaviour, as multiple definitions of the symbols in that object are given. [^1]
Consider an example from the mm-ut unit tests; in particular, the file mm_app_test.c. The file is compiled once:
/usr/bin/ld: ./.tmp-kcc-h49pwzks/libmm-ut_no_symtab-native.a(native-tu-41.o): in function `MM_APP_TEST_CFE_ES_ExitAppHook':
mm_app_test.c:(.text+0x0): multiple definition of `MM_APP_TEST_CFE_ES_ExitAppHook'; ./.tmp-kcc-h49pwzks/native-tu-1.o:mm_app_test.c:(.text+0x0): first defined here
The offending symbol (MM_APP_TEST_CFE_ES_ExitAppHook) does indeed exist in both the static library and the mm_app_test.c.o object file:
$ cd /airliner/build/bebop2/kcc/target/target/apps/mm
$ nm CMakeFiles/mm-ut.dir/__/unit_test/mm_app_test.c.o | grep MM_APP_TEST_CFE_ES_ExitAppHook
0000000000000000 r .L__func__.MM_APP_TEST_CFE_ES_ExitAppHook
0000000000000000 T MM_APP_TEST_CFE_ES_ExitAppHook
$ nm libmm-ut_no_symtab.a | grep MM_APP_TEST_CFE_ES_ExitAppHook
0000000000000000 r .L__func__.MM_APP_TEST_CFE_ES_ExitAppHook
0000000000000000 T MM_APP_TEST_CFE_ES_ExitAppHook
[^1]: Note that the compiler invocations below use the Runtime Verification kcc tool; I can provide further context on this if needed, but it produces faithful native binaries using Clang, which also include additional instrumentation code.
The Airliner unit test system appears to link multiple copies of the same object file when building tests, relying on the linker to silently discard one of the copies. I believe doing so is undefined behaviour, as multiple definitions of the symbols in that object are given. [^1]
Consider an example from the
mm-ut
unit tests; in particular, the filemm_app_test.c
. The file is compiled once:then subsequently linked into a static archive
libmm-ut_no_symtab.a
:The file is then rebuilt with the only difference being the
-Dmm_ut_EXPORTS
flag:Finally, the two different objects are compiled into the
mm-ut
executable:We then see a number of linker errors like:
The offending symbol (
MM_APP_TEST_CFE_ES_ExitAppHook
) does indeed exist in both the static library and themm_app_test.c.o
object file:My full build log is here: mm.txt
[^1]: Note that the compiler invocations below use the Runtime Verification
kcc
tool; I can provide further context on this if needed, but it produces faithful native binaries using Clang, which also include additional instrumentation code.