Subject: Saving arguments on the stack

From: "Knittel, Brian" <[email-masked]>
Date: Mon, 21 Nov 2005 18:59:20 -0800

Hi,

I'd like to force the compiler to store arguments on the stack with otherwise optimized code.

I found a refernce in the archives (form 2001) for using -0 (no optimization). Has anyone found another way to do this?

Thanks,

--Brian

---

From: "Kevin D. Kissell" <[email-masked]>
Date: Tue, 22 Nov 2005 09:53:10 +0100

> I found a refernce in the archives (form 2001) for using -0 (no optimization). Has anyone found another way to do this?

If I recall correctly, if you specify -g to enable debugger support,
the subroutine prologues store the arguments into their stack slots,
even if a higher level of optimization is otherwise specified.

		Regards,

		Kevin K.

---

From: Nigel Stephens <[email-masked]>
Date: Tue, 22 Nov 2005 11:21:13 +0000

Kevin D. Kissell wrote:

>> I found a refernce in the archives (form 2001) for using -0 (no 
>> optimization). Has anyone found another way to do this?
>
>

'Fraid not: the -g option only adds debug info to the object file, it 
shouldn't alter the generated code. Using -O0 will certainly store 
everything on the stack, but it also won't be "with otherwise optimized 
code".

Nigel

---

From: Ralf Baechle <[email-masked]>
Date: Tue, 22 Nov 2005 11:24:17 +0000

> everything on the stack, but it also won't be "with otherwise optimized 

And the kernel won't build without optimization - but that's FAQ since
10 years.

  Ralf

---

From: Ralf Baechle <[email-masked]>
Date: Tue, 22 Nov 2005 11:38:01 +0000

> I found a refernce in the archives (form 2001) for using -0 (no optimization). Has anyone found another way to do this?

-O is optimization - same as -O1.

Gcc will save all arguments to the stack for variadic functions (like:
int printf(const char *fmt, ...)) when using somewhat older compiler - I
think before gcc 3.2 or so.  Newer compilers will only save argument
one and up.  Maybe that's good enough?

  Ralf

---

From: "Maciej W. Rozycki" <[email-masked]>
Date: Tue, 22 Nov 2005 11:39:28 +0000 (GMT)

> And the kernel won't build without optimization - but that's FAQ since

 Well, with "__attribute__((always_inline))" available and actually used 
already, perhaps this requirement could be relaxed nowadays...

  Maciej

---

From: Ralf Baechle <[email-masked]>
Date: Tue, 22 Nov 2005 12:27:03 +0000

> already, perhaps this requirement could be relaxed nowadays...

There were functions in the network stack that intensionally were
declared extern inline to make sure the compiler won't be able to outline
that function unnoticed.  I just grepped for it and can't find it
anymore, must be a relativly recent improvment.

We also rely on the compiler eleminating calls to certain functions
entirely, for example to __xchg_called_with_bad_pointer().

  Ralf

---

From: Dominic Sweetman <[email-masked]>
Date: Tue, 22 Nov 2005 12:41:06 +0000

Brian,

> > with otherwise optimized code.

Sounds like you're out of luck.  Perhaps you'd do better to go one
step back and explain what you're trying to do?

--
Dominic Sweetman
MIPS Technologies

---

From: "Maciej W. Rozycki" <[email-masked]>
Date: Tue, 22 Nov 2005 14:03:12 +0000 (GMT)

> entirely, for example to __xchg_called_with_bad_pointer().

 Well, that's exactly what "__attribute__((always_inline))" does -- either
inline or fail; the latter AFAIK only happening if the function's body is
unavailable to the current compilation unit.  That happens regardless of 
any optimization settings.

  Maciej