Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A function stops being inline. Any explanation?

Tags:

c++

c

stack

gcc

inline

I have a code of the following structure:

void foo1(uint32_t *num_failures)
{
   ...
}

void foo2(uint32_t *num_failures)
{
   ...
}

void foo3(uint32_t *num_failures)
{
   ...
}

void test()
{
   uint32_t num_failures = 0;
   foo1(&num_failures);
   foo2(&num_failures);
   foo3(&num_failures);
}

Now, what I did was add the following instruction to foo1():

void foo1(uint32_t *num_failures)
{
   ...
   (*num_failures)++;
}

And suddenly I see that stack size printed from inside foo2() is larger by 36 bytes.

I did an objdump and greped for <symbols>. Yielding the following:

Before the change:

...
00004e08 <test>:

After the change:

...
00004e08 <foo2>:
00005588 <test>:

So I guess the function foo2 stopped being inline.

  1. Am I correct?
  2. Any explanation why that happened?
  3. What happened to foo3() after the change? Did it become inline inside foo2() or inside test()?

Not sure if required: I'm using gcc for arc processor.

like image 863
Elad Weiss Avatar asked Nov 08 '22 17:11

Elad Weiss


1 Answers

After learning some more on the subject, and seeing some lectures by Chandler Caruth, I would say the compiler decides almost indeterministicly where to inline the code. Especially when not givinig it any 'inline' hints, as in my case.

like image 189
Elad Weiss Avatar answered Nov 15 '22 04:11

Elad Weiss