All of lore.kernel.org
 help / color / mirror / Atom feed
* Why is there conflicting information out there for asmlinkage ?
@ 2020-05-06 12:51 Sreyan Chakravarty
  2020-05-06 16:27 ` arshad hussain
  2020-05-06 18:34 ` Valentin Vidić
  0 siblings, 2 replies; 3+ messages in thread
From: Sreyan Chakravarty @ 2020-05-06 12:51 UTC (permalink / raw)
  To: kernelnewbies


[-- Attachment #1.1: Type: text/plain, Size: 1408 bytes --]

I thought that all C programs normally use the stack for function calls.
That's why in most languages if you are stuck in an infinite recursion you
get a "Stack Overflow Error".

If that is true, then what is so special about asmlinkage, it tells the
program to look for variables in the stack rather than registers. The
runtime does not look for values in the register in the first place.

The asmlinkage tag is one other thing that we should observe about this
> simple function. This is a #define for some gcc magic that tells the
> compiler that the function should not expect to find any of its arguments
> in registers (a common optimization), but only on the CPU's stack.


What's even more strange is that when you learn that it is implemented
using regparam in x86.
https://qr.ae/pNy1wL

The documentation for regparam is as follows:
https://gcc.gnu.org/onlinedocs/gcc/x86-Function-Attributes.html#x86-Function-Attributes


> On x86-32 targets, the regparm attribute causes the compiler to pass
> arguments number one to number if they are of integral type in registers
> EAX, EDX, and ECX instead of on the stack. Functions that take a variable
> number of arguments continue to be passed all of their arguments on the
> stack.


It says just the opposite.

What is going on ? Which is correct the stack or the registers ?

Why is there conflicting info out there ?
-- 
Regards,
Sreyan Chakravarty

[-- Attachment #1.2: Type: text/html, Size: 2708 bytes --]

[-- Attachment #2: Type: text/plain, Size: 170 bytes --]

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Why is there conflicting information out there for asmlinkage ?
  2020-05-06 12:51 Why is there conflicting information out there for asmlinkage ? Sreyan Chakravarty
@ 2020-05-06 16:27 ` arshad hussain
  2020-05-06 18:34 ` Valentin Vidić
  1 sibling, 0 replies; 3+ messages in thread
From: arshad hussain @ 2020-05-06 16:27 UTC (permalink / raw)
  To: Sreyan Chakravarty; +Cc: kernelnewbies

On Wed, May 6, 2020 at 6:24 PM Sreyan Chakravarty <sreyan32@gmail.com> wrote:
>
> I thought that all C programs normally use the stack for function calls. That's why in most languages if you are stuck in an infinite recursion you get a "Stack Overflow Error".
>
> If that is true, then what is so special about asmlinkage, it tells the program to look for variables in the stack rather than registers. The runtime does not look for values in the register in the first place.
>
>> The asmlinkage tag is one other thing that we should observe about this simple function. This is a #define for some gcc magic that tells the compiler that the function should not expect to find any of its arguments in registers (a common optimization), but only on the CPU's stack.
>
>
> What's even more strange is that when you learn that it is implemented using regparam in x86.
> https://qr.ae/pNy1wL
>
> The documentation for regparam is as follows:
> https://gcc.gnu.org/onlinedocs/gcc/x86-Function-Attributes.html#x86-Function-Attributes
>>
>> On x86-32 targets, the regparm attribute causes the compiler to pass arguments number one to number if they are of integral type in registers EAX, EDX, and ECX instead of on the stack. Functions that take a variable number of arguments continue to be passed all of their arguments on the stack.
>
>
> It says just the opposite.
>
> What is going on ? Which is correct the stack or the registers ?
>
> Why is there conflicting info out there ?
> --
> Regards,
> Sreyan Chakravarty
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies@kernelnewbies.org
> https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

My 2 cents... asmlinkage expands to regparam(0). This limits all
arguments to be passed on stack.

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Why is there conflicting information out there for asmlinkage ?
  2020-05-06 12:51 Why is there conflicting information out there for asmlinkage ? Sreyan Chakravarty
  2020-05-06 16:27 ` arshad hussain
@ 2020-05-06 18:34 ` Valentin Vidić
  1 sibling, 0 replies; 3+ messages in thread
From: Valentin Vidić @ 2020-05-06 18:34 UTC (permalink / raw)
  To: kernelnewbies

On Wed, May 06, 2020 at 06:21:54PM +0530, Sreyan Chakravarty wrote:
> I thought that all C programs normally use the stack for function calls.
> That's why in most languages if you are stuck in an infinite recursion you
> get a "Stack Overflow Error".

Not really, depends on the calling convention used. For example:

  https://en.wikipedia.org/wiki/X86_calling_conventions#System_V_AMD64_ABI

first six parameters are passed using registers.

For system calls it is similar:

  http://man7.org/linux/man-pages/man2/syscall.2.html

-- 
Valentin

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-05-06 18:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-06 12:51 Why is there conflicting information out there for asmlinkage ? Sreyan Chakravarty
2020-05-06 16:27 ` arshad hussain
2020-05-06 18:34 ` Valentin Vidić

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.