From: Ammar Faizi <ammarfaizi2@gnuweeb.org>
To: "Thomas Weißschuh" <linux@weissschuh.net>
Cc: Willy Tarreau <w@1wt.eu>, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 3/3] tools/nolibc: x86_64: wrap asm functions in functions
Date: Sat, 10 Aug 2024 19:12:25 +0700 [thread overview]
Message-ID: <ZrdZKcQ1SClUHWa1@biznet-home.integral.gnuweeb.org> (raw)
In-Reply-To: <20240810-nolibc-lto-v1-3-a86e514c7fc1@weissschuh.net>
On Sat, Aug 10, 2024 at 12:54:46PM +0200, Thomas Weißschuh wrote:
> +__attribute__((weak,unused,section(".text.nolibc_memmove")))
> +__nolibc_naked __no_stack_protector
> +void *memmove(void *dst __attribute__((unused)),
> + const void *src __attribute__((unused)),
> + size_t len __attribute__((unused)))
> +{
> + __asm__ volatile (
> + "movq %rdx, %rcx\n\t"
> + "movq %rdi, %rax\n\t"
> + "movq %rdi, %rdx\n\t"
> + "subq %rsi, %rdx\n\t"
> + "cmpq %rcx, %rdx\n\t"
> + "jb .Lbackward_copy\n\t"
> + "rep movsb\n\t"
> + "retq\n"
> + ".Lbackward_copy:"
> + "leaq -1(%rdi, %rcx, 1), %rdi\n\t"
> + "leaq -1(%rsi, %rcx, 1), %rsi\n\t"
> + "std\n\t"
> + "rep movsb\n\t"
> + "cld\n\t"
> + "retq\n"
> + );
> + __nolibc_naked_epilogue();
> +}
NAK for this patch.
This approach appears highly dangerous, particularly when the compiler
inlines the call. When using inline assembly within a function, it's
crucial to define proper constraints and a clobber list to ensure the
arguments are correctly bound to the inline assembly.
Moreover, as it stands, there is no indication to the compiler that the
inline assembly modifies registers such as %rax, %rdi, %rsi, %rdx, %rcx,
or "memory", which could lead to unpredictable behavior.
Unfortunately, I can't spend more time on this right now as I'm
currently traveling. I'll get back to it later when I'm in transit.
--
Ammar Faizi
next prev parent reply other threads:[~2024-08-10 12:18 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-10 10:54 [PATCH 0/3] tools/nolibc: LTO compatibility Thomas Weißschuh
2024-08-10 10:54 ` [PATCH 1/3] tools/nolibc: crt: mark _start_c() as used Thomas Weißschuh
2024-08-10 10:54 ` [PATCH 2/3] tools/nolibc: stackprotector: mark implicitly used symbols " Thomas Weißschuh
2024-08-10 10:54 ` [PATCH 3/3] tools/nolibc: x86_64: wrap asm functions in functions Thomas Weißschuh
2024-08-10 12:12 ` Ammar Faizi [this message]
2024-08-10 12:37 ` Thomas Weißschuh
2024-08-10 14:35 ` Willy Tarreau
2024-08-10 16:04 ` Thomas Weißschuh
2024-08-10 16:45 ` Thomas Weißschuh
2024-08-10 17:00 ` Willy Tarreau
2024-08-12 17:01 ` Thomas Weißschuh
2024-08-12 19:38 ` Willy Tarreau
2024-08-10 19:16 ` Ammar Faizi
2024-08-10 19:45 ` Willy Tarreau
2024-08-10 20:10 ` Ammar Faizi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZrdZKcQ1SClUHWa1@biznet-home.integral.gnuweeb.org \
--to=ammarfaizi2@gnuweeb.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@weissschuh.net \
--cc=w@1wt.eu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®