mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Thomas Weißschuh" <linux@weissschuh.net>
To: Willy Tarreau <w@1wt.eu>
Cc: Ammar Faizi <ammarfaizi2@gnuweeb.org>, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 3/3] tools/nolibc: x86_64: wrap asm functions in functions
Date: Sat, 10 Aug 2024 18:45:19 +0200	[thread overview]
Message-ID: <17ed9bf5-64da-418e-b40e-6e3d40c67769@t-8ch.de> (raw)
In-Reply-To: <384a1d29-13ca-4e4b-b4b7-2a99e3fdb01b@t-8ch.de>

On 2024-08-10 18:04:36+0000, Thomas Weißschuh wrote:
> On 2024-08-10 16:35:56+0000, Willy Tarreau wrote:

<snip>

> > Also I'm wondering why there are errors about memcpy and memmove being
> > already defined with -flto, because these ones are marked "weak". Maybe
> > we need to add something else, that gcc emits with the functions when
> > using lto ?
> 
> I think normally .weak would only be resolved by the linker.
> What happens here is that the assembler is already presented with
> duplicate definitions which it is not prepared to handle.
> (See below for an example)
> 
> It works on gcc without -flto and on clang with and without -flto.
> It seems like a compiler bug to me. If you agree I'll open a ticket
> against GCC.
> Then we can fix only the label to make it work on clang and wait for a
> fixed GCC.

Iff we really want to support it, we could do use naked where available
and fall back to toplevel asm otherwise.
This should work on newer compilers and older ones without -flto.
It looks horrible though.

  #define NOLIBC_ARCH_HAS_MEMSET
  void *memset(void *dst, int c, size_t len);
  
  #if __nolibc_has_attribute(naked)

  __attribute__((weak,naked))
  void *memset(void *dst __attribute__((unused)), int c __attribute__((unused)), size_t len __attribute__((unused))) {

  #else

  __asm__ (
  ".section .text.nolibc_memset\n"
  ".weak memset\n"
  "memset:\n"
  );

  #endif

  __asm__ (
  	"xchgl %eax, %esi\n\t"
  	"movq  %rdx, %rcx\n\t"
  	"pushq %rdi\n\t"
  	"rep stosb\n\t"
  	"popq  %rax\n\t"
  	"retq\n"
  );

  #if __nolibc_has_attribute(naked)
  }
  #endif

(Or some impenetrable macro wrapper abstraction thereof)

The memcpy / memmove combination could be split up into one real
function and one C inline wrapper and then the same pattern would apply.

But to be honest I'd be fine with not supporting -flto on GCC.


Thomas

  reply	other threads:[~2024-08-10 16:45 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
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 [this message]
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=17ed9bf5-64da-418e-b40e-6e3d40c67769@t-8ch.de \
    --to=linux@weissschuh.net \
    --cc=ammarfaizi2@gnuweeb.org \
    --cc=linux-kernel@vger.kernel.org \
    --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®