Re: [PATCH 3/3] tools/nolibc: x86_64: wrap asm functions in functions

From: Ammar Faizi
Date: Sat Aug 10 2024 - 16:10:49 EST


On Sat, Aug 10, 2024 at 09:45:45PM +0200, Willy Tarreau wrote:
> The constraints are trivial, the problem is that they're not supposed to
> be used in a naked function. I tried, as you can guess. gcc accepted
> them without complaining but clang not at all. However what's interesting
> is that the compiler being aware of our unability to inform it about the
> clobber list, it did consider everything clobbered and saved the registers
> in the caller in this case. That does make sense, otherwise it would be
> impossible to use asm in naked functions. However we need to restrict
> this use case to true naked functions, not the ones we were doing ourselves
> before the existence of the naked attribute.

Ah, I get it now. Apparently, my ignorance of naked functions led to,
well, not knowing about naked functions. I didn't know about the naked
attribute.

Yeah, clang indeed throws errors while GCC does not:

```
<source>:24:10: error: parameter references not allowed in naked functions
24 | : "+D"(dst), "+S"(src), "+c"(len), "=a"(rax)
| ^
<source>:4:16: note: attribute is here
4 | __attribute__((naked))
| ^
<source>:7:2: error: non-ASM statement in naked function is not supported
7 | void *rax;
| ^
<source>:4:16: note: attribute is here
4 | __attribute__((naked))
| ^
2 errors generated.
Compiler returned: 1
```

For now, I'll wait for your discussion with Thomas to resolve this
issue. And yes, I agree that we should find a solution that doesn't
require maintaining two different versions.

--
Ammar Faizi