When I run gcc with the -g option, this enables me to see some c code when I run the executable with objdump.
I have a program that has a sections of code in #if blocks. When I run gcc with -g and run objdump it displays c code from the #ifs that should not be included.
For example with the following c code:
#define ENABLED 0
#if ENABLED
startSomething();
#endif
When compiled with gcc -g
, the call to the startSomething function is included in the objdump output.
Section of objdump output:
261c: 1c19 adds r1, r3, #0
261e: f7fe f9a1 bl 964 <init>
}
startSomething();
#else
Is this expected behaviour? I would have thought that if the call to startSomething() and the actual function definition of startSomething is wrapped in #if ENABLED
then it shouldn't be included and gcc should just cut that out.
Is there a way for gcc/objdump to pay more attention to the preprocessor #ifs so I don't get code in the objdump that will never get executed?
Thanks for your help.
EDIT: Additionally I know that this function is not getting executed when actually running the code. So I know I haven't set ENABLED somewhere else.
EDIT 2: A good observation is that the objdump isn't actually outputting any asm instructions related to the function call. So it seems to just be incorrectly including the function call c block there related to the function call.