Tool/software: TI C/C++ Compiler
Hello there,
I want to use strings (the linux command) to obtain version and git information from an executable.
With GCC it works when adding the following lines to the sourcecode.
main.c:
#include <stdint.h>
const char* version_string = "#_#_ Version info - version 0.1 built on (2017-10-09 11:19:00) _#_#";
int main(void){
/*
* SOME CODE HERE.
*/
}
I can then use:
$ strings my_executable.out | grep "#_#"
To obtain the version string information.
However, when i compile the same source file using the TI compiler the string gets removed in the object file.
When I use the variable in some dummy function the compiler does not remove it and i can obtain it using strings, however we do not want dead code.
I have tried adding volatile, static, __attribute__((used)) but none of these give any difference.
I am using these compile flags (from inside CCS):
-mv7R4 --code_state=32 --float_support=VFPv3D16 -me -Ooff --opt_for_speed=1 --include_path="${CG_TOOL_ROOT}/include" --include_path="${workspace_loc:/${ProjName}/include}" -g --symdebug:dwarf_version=3 --c99 --printf_support=minimal --diag_warning=225 --diag_wrap=off --display_error_number --enum_type=packed --abi=eabi
These are the link options, however as the string is also not present in the object file I do not assume that the linker causes any troubles.
-m"${ProjName}.map" --heap_size=0x800 --stack_size=0x800 -i"${CG_TOOL_ROOT}/lib" -i"${CG_TOOL_ROOT}/include" --reread_libs --diag_wrap=off --display_error_number --warn_sections --xml_link_info="${ProjName}_linkInfo.xml" --rom_model --unused_section_elimination=off
I am using version v16.9.0.LTS.
So now the question is can I add a compile/link flag to prevent the compiler/linker from removing this variable?
Thanks in advance :)
Karel