Local variable in a C function is not getting created in stack when its compiled with GCC

Hi,

I am working in UEFI EDK2 Bios source. We created a platform related new package in the EDK2 source. I find a strange issue with the platform related code we added.

When I did source level debugging I noticed the
local variable in a C function is not getting created in stack when its compiled with GCC.

The same UEFI code when compiled with visual studio then local variable in a C function is getting created in stack.

I am executing this code on a Simulation environment where I can see the Stack Base, all segment registers, Current executing code, memory etc..

Its Multi core system but only Boot Strap processors in enabled

Any suggestions?

Thanks,
Divya R

Depending on how the code is optimized, the variable may be put on the stack, or might only exist in a register, or might not exist at all (i.e. pruning unused things, building constants into instructions for variables which do not change, etc).

Thanks Corona,

I have created a variable for a structure. And this variable is getting updated.
the code segment region address is assigned to the Variable.

I am surprised why a code segment address is assigned to a local variable.

When this local variable is getting updated its corrupting the code in Code segment, and system boot is failing.

It is difficult to diagnose problems in code we haven't seen. If you show us the original code and the modifications you have made to it, we would have a MUCH better chance of helping you.

Thanks Don Cragun.

Sorry I cannot share the source its confidential.

Thanks,
Divya

Although uncommon, I've seen variables (constants) allocated in the code segment, admittedly some (decent) time ago. And, updating it shouldn't corrupt the code nor crash the boot, provided it's size is respected and no adjacent memory is overwritten. Checksums of the code could fail, but they are done upfront, usually, before an update occurred. Or, do you have an unmet condition with the new value and no error handler for such?

Trampolines are required when booting SMP machines with multiple CPUs. When the OS is initializing, only one bootstrap CPU runs. Then an embedded function ( a trampoline) is invoked. The function and variables are in the code not the stack. The function inits the remaining CPU's.

What you describe sounds like that is what may be happening.