Products > Programming
The spread of "Functional Programming"
<< < (7/7)
paulca:

--- Quote from: brucehoult on December 05, 2024, 11:34:18 pm ---
--- Quote from: paulca on December 05, 2024, 04:59:13 pm ---While "textbook" C will perform a full push of arguments onto the stack + return address and then jump

--- End quote ---

On what?

Not on amd64 / x86_64. Only the return address is pushed, by the hardware of the JSR instruction (sadly), the caller pushes nothing.

That "full push of arguments onto the stack + return address" stuff is only on CPUs (and their ABI) designed in the 1970s or before, 45 years ago.

--- End quote ---

Okay. I'm either very out of date (a lot more than expected) or I'm confusing myself with something else.

What about buffer overflow exploits?  Some of those overrun the buffer to overwrites the function return address and direct it to other injected code.  I thought that was only possible when you have a fixed sized array on the stack?  Or maybe I am confusing myself between "stack" and "where there modern compilers 'stages' things.

coppice:

--- Quote from: brucehoult on December 06, 2024, 12:04:29 am ---
--- Quote from: SiliconWizard on December 05, 2024, 11:39:21 pm ---Wasn't it the Pascal convention for the caller to push arguments & return address on the stack rather than the callee?

--- End quote ---
Languages don't have physical calling conventions, only compilers do (and OSes and standard libraries).

--- End quote ---
Well, it isn't usually compilers these days. Its almost always some ABI spec that everyone follows for the particular hardware. However, there is a sense where languages do have a calling convention. C from day one allowed for variable numbers of arguments. That won't work with the way most Pascal compilers handle arguments, so the language does impose some things on the calling convention.
paulca:

--- Quote from: coppice on December 06, 2024, 11:40:10 am ---
--- Quote from: brucehoult on December 06, 2024, 12:04:29 am ---
--- Quote from: SiliconWizard on December 05, 2024, 11:39:21 pm ---Wasn't it the Pascal convention for the caller to push arguments & return address on the stack rather than the callee?

--- End quote ---
Languages don't have physical calling conventions, only compilers do (and OSes and standard libraries).

--- End quote ---
Well, it isn't usually compilers these days. Its almost always some ABI spec that everyone follows for the particular hardware. However, there is a sense where languages do have a calling convention. C from day one allowed for variable numbers of arguments. That won't work with the way most Pascal compilers handle arguments, so the language does impose some things on the calling convention.

--- End quote ---

How does the ELF binary format get involved?  So C code is not created as a monolithic block.  Functions can be "First class" and exist in global scope in isolation.  A single function can be stored in a .o or a .a etc.

What I was thinking was this specification which defines function formal prototypes for linkage and ... well integration with the rest of the OS.  Obviously the main() method has to have a contract with the OS to get launched and it's process setup and called. 

I suppose I was under the impression that also governed the generic contract for all functions and declarations. 

If you want to take your random single function .a file and wrap it into a .so dynamic loaded library it's going to have to obey some form of standard.  Maybe that does not in anyway govern how arguments and return values are passed or copied.

That is another consideration.  If the argument is passed by value and is not a "register" sized element.  How and where is space allocated for these, if not on the stack?
SiliconWizard:

--- Quote from: coppice on December 06, 2024, 11:40:10 am ---
--- Quote from: brucehoult on December 06, 2024, 12:04:29 am ---
--- Quote from: SiliconWizard on December 05, 2024, 11:39:21 pm ---Wasn't it the Pascal convention for the caller to push arguments & return address on the stack rather than the callee?

--- End quote ---
Languages don't have physical calling conventions, only compilers do (and OSes and standard libraries).

--- End quote ---
Well, it isn't usually compilers these days. Its almost always some ABI spec that everyone follows for the particular hardware. However, there is a sense where languages do have a calling convention. C from day one allowed for variable numbers of arguments. That won't work with the way most Pascal compilers handle arguments, so the language does impose some things on the calling convention.

--- End quote ---

Yep. Sure that was intially defined by compilers, but it more or less became a convention. You're right it tied to the ABI of a given target.

The Pascal calling convention is listed in the x86 calling conventions, for instance: https://en.wikipedia.org/wiki/X86_calling_conventions
they indeed say that it was based on the convention used by Turbo Pascal compilers. It was similar on CP/M (so the Z80/8080). And yes, it did prevent the implementation of variable arguments.
Navigation
Message Index
Previous page
There was an error while thanking
Thanking...

Go to full version
Powered by SMFPacks Advanced Attachments Uploader Mod