flat assembler
Message board for the users of flat assembler.

Index > Linux > ABI to the drain

Author
Thread Post new topic Reply to topic
sylware



Joined: 23 Oct 2020
Posts: 371
Location: Marseille/France
sylware 17 Apr 2023, 11:14
I did notice that, internally, I don't respect the sysv ABI anymore for function call at all.

Since I do syscalls I tend to always keep the argument registers (rdi/rsi/rdx...) available and actually use the sysv ABI callee-saved (rbx/rbp/r12...) registers as argument of my "internal functions".

What about you people? Similar register management strategy? I know this strategy is "fluid" and very context dependent, but I am talking roughly.
Post 17 Apr 2023, 11:14
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 19869
Location: In your JS exploiting you and your system
revolution 17 Apr 2023, 12:06
We don't use the SYSV ABI in any of our code except to interface with external libraries.

Nor do we use the MS version FASTCALL.

We use what could be equivalent to STDCALL, but modified for 64-bit.

The macro we use to setup the SYSV call parameters is scary. To comply with the placements of arguments is mindbogglingly complex IMO. Ints going into one place and floats into another, and overage and "large" components going to a third place. With various random alignment requirements included to "make it faster". It was a paper-faster, rather than a real-world-faster. On paper it might look okay, in functioning code the story is no so clear.

We found that in real-world running code all the extra complexity of stack aligning and argument swizzling gave absolutely no advantage over a much simpler STDCALL-style stack. So we decided to not bother adding all the extra complexity for no gain. Useless extra requirements apparently.
Post 17 Apr 2023, 12:06
View user's profile Send private message Visit poster's website Reply with quote
Furs



Joined: 04 Mar 2016
Posts: 2341
Furs 17 Apr 2023, 18:21
I use custom calling conventions in most cases. Usually generic one, but sometimes one that fits a specific task to avoid having to spill or move registers. I don't care about simplicity, because if I did, I wouldn't be using assembly. I have a big gripe with the stack alignment for SYSV ABI (and I despite the Microsoft ABI).

BTW, I don't write most code in asm, but I do interface with my own code still with custom calls with compiler plugin magic in C++.

I say C++ but I use it mostly in spirit of C and asm, just some extra nice functionality (e.g. constexpr for stuff evaluated at compile time, classes for better syntax for objects (but never inheritance!), etc).
Post 17 Apr 2023, 18:21
View user's profile Send private message Reply with quote
sylware



Joined: 23 Oct 2020
Posts: 371
Location: Marseille/France
sylware 18 Apr 2023, 09:50
Note: assembly is dead simple, I was coding assembly in my teenage years. It is just something that most people don't want to do.

I think you meant assembly is less comfy as it requires more work upfront than a high level language (and this is irrelevant for a LOT of system components), but I would bet that many here dislike the dependency on those grotesquely and absurdely massive compilers (basically gcc and sometimes clang) and some syntaxes which are on the same grade (c++ being the "best" example but C is already waaaaaay too much).

Actually, this dependency is so much toxic in the end and on the long run, this is a sensible reason to code only assembly...
Post 18 Apr 2023, 09:50
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 19869
Location: In your JS exploiting you and your system
revolution 18 Apr 2023, 10:35
Furs wrote:
I don't care about simplicity ...
Complexity is the worst IMO.

It makes it harder to find bugs. It makes it harder to understand bugs. It makes it harder to fix bugs. It makes for more bugs, latent bugs, obscure bugs, and heisenbugs.
Post 18 Apr 2023, 10:35
View user's profile Send private message Visit poster's website Reply with quote
Furs



Joined: 04 Mar 2016
Posts: 2341
Furs 18 Apr 2023, 14:15
Don't get me wrong, it's not like I aim for complexity purposefully. But simplicity is not my main goal when I code. If I had to choose between two identical pieces of code, but one is simpler, obviously I choose simplicity.

BTW, complexity is bad in many cases even for other reasons, so I aim for simplicity implicitly, while aiming for other goals instead. For example: code bloat.
Post 18 Apr 2023, 14:15
View user's profile Send private message Reply with quote
sylware



Joined: 23 Oct 2020
Posts: 371
Location: Marseille/France
sylware 18 Apr 2023, 17:53
Complexity has to be dealed on a case by case basis and must embrace the whole system.

Don't listen to the song of those who propose "simplicity" as it usually only moves some complexity away into what ends up being some accute toxic dependency... (like a compiler with super complex syntax...).

Don't fool yourself.
Post 18 Apr 2023, 17:53
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 19869
Location: In your JS exploiting you and your system
revolution 18 Apr 2023, 19:00
There is a fundamental difference between offloading complexity and eliminating complexity.

For example: One can offload the complexity of robust date/time computations to a library function to handle all the special cases for us. But that doesn't eliminate the complexity of the underlying calculations. The calculations still have to be done, just that they are done by a black box.

Compared to: One can eliminate the complexity of SYSV parameter passing rules by not using them, and instead use a regularised system without special cases.
Post 18 Apr 2023, 19:00
View user's profile Send private message Visit poster's website Reply with quote
sylware



Joined: 23 Oct 2020
Posts: 371
Location: Marseille/France
sylware 18 Apr 2023, 19:58
@revolution yep, this is what I meant. And we know now where the path of the black box leads...

oh... and a black box can be open source...
Post 18 Apr 2023, 19:58
View user's profile Send private message Reply with quote
DimonSoft



Joined: 03 Mar 2010
Posts: 1228
Location: Belarus
DimonSoft 19 Apr 2023, 21:56
revolution wrote:
We found that in real-world running code all the extra complexity of stack aligning and argument swizzling gave absolutely no advantage over a much simpler STDCALL-style stack. So we decided to not bother adding all the extra complexity for no gain. Useless extra requirements apparently.

So similar to what I used to say to my students on the topic for years (with a few specific examples and related explanations). Good to know I’m not the only one who sees the king is naked.
Post 19 Apr 2023, 21:56
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2023, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.