From: Willy Tarreau <w@1wt.eu>
To: "Thomas Weißschuh" <thomas@t-8ch.de>
Cc: "Thomas Weißschuh" <linux@weissschuh.net>,
"Shuah Khan" <shuah@kernel.org>,
linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org
Subject: Re: [PATCH 04/12] tools/nolibc: use attribute((naked)) if available
Date: Sun, 4 Aug 2024 05:47:45 +0200 [thread overview]
Message-ID: <20240804034745.GA30236@1wt.eu> (raw)
In-Reply-To: <d5c952c9-e7f6-4a01-9e43-2b19b586a95b@t-8ch.de>
On Sat, Aug 03, 2024 at 10:55:07PM +0200, Thomas Weißschuh wrote:
> Aug 3, 2024 20:33:11 Willy Tarreau <w@1wt.eu>:
>
> > On Sat, Aug 03, 2024 at 08:28:08PM +0200, Thomas Weißschuh wrote:
> >>> I think that it can resolve to roughly this:
> >>>
> >>> #if defined(__has_attribute) && __has_attribute(naked)
> >>> # define __entrypoint __attribute__((naked))
> >>> # define __entrypoint_epilogue()
> >>> #else
> >>> # define __entrypoint __attribute__((optimize("Os", "omit-frame-pointer")))
> >>> # define __entrypoint_epilogue() __builtin_unreachable()
> >>> #endif
> >>
> >> We would need to duplicate the define for the
> >> !defined(__has_attribute) case.
> >
> > I don't understand why. Above both are tested on the first line.
> > Am I missing something ?
>
> This specifically does not work [0]:
>
> a result, combining the two tests into a single expression as shown
> below would only be valid with a compiler that supports the operator but not
> with others that don't.
Ah I didn't remember about that one, thanks for the reference. Indeed
it's annoying then.
We have a similar construct in compiler.h:
#if defined(__has_attribute)
# if __has_attribute(no_stack_protector)
# define __no_stack_protector __attribute__((no_stack_protector))
# else
# define __no_stack_protector __attribute__((__optimize__("-fno-stack-protector")))
# endif
#else
# define __no_stack_protector __attribute__((__optimize__("-fno-stack-protector")))
#endif /* defined(__has_attribute) */
Maybe it would be a good opportunity to have our own macro so as to
simplify such tests:
#if defined(__has_attribute)
# define nolibc_has_attribute(x) __has_attribute(x)
#else
# define nolibc_has_attribute(x) 0
#endif
#if nolibc_has_attribute(no_stack_protector)
# define __no_stack_protector __attribute__((no_stack_protector))
#else
# define __no_stack_protector __attribute__((__optimize__("-fno-stack-protector"
#endif
Then:
#if nolibc_has_attribute(naked)
# define __entrypoint __attribute__((naked))
# define __entrypoint_epilogue()
#else
# define __entrypoint __attribute__((optimize("Os", "omit-frame-pointer")))
# define __entrypoint_epilogue() __builtin_unreachable()
#endif
It's as you want. Either we take your #undef-based solution or we take
this opportunity to clean up as above. I'm fine with both.
Thanks!
Willy
next prev parent reply other threads:[~2024-08-04 3:47 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-28 10:09 [PATCH 00/12] tools/nolibc: improve LLVM/clang support Thomas Weißschuh
2024-07-28 10:09 ` [PATCH 01/12] tools/nolibc: use clang-compatible asm syntax in arch-arm.h Thomas Weißschuh
2024-07-28 10:09 ` [PATCH 02/12] tools/nolibc: limit powerpc stack-protector workaround to GCC Thomas Weißschuh
2024-07-28 10:09 ` [PATCH 03/12] tools/nolibc: move entrypoint specifics to compiler.h Thomas Weißschuh
2024-08-03 9:22 ` Willy Tarreau
2024-08-03 18:26 ` Thomas Weißschuh
2024-07-28 10:09 ` [PATCH 04/12] tools/nolibc: use attribute((naked)) if available Thomas Weißschuh
2024-08-03 9:25 ` Willy Tarreau
2024-08-03 18:28 ` Thomas Weißschuh
2024-08-03 18:32 ` Willy Tarreau
2024-08-03 20:55 ` Thomas Weißschuh
2024-08-04 3:47 ` Willy Tarreau [this message]
2024-07-28 10:09 ` [PATCH 05/12] selftests/nolibc: report failure if no testcase passed Thomas Weißschuh
2024-07-28 10:10 ` [PATCH 06/12] selftests/nolibc: avoid passing NULL to printf("%s") Thomas Weißschuh
2024-08-03 9:33 ` Willy Tarreau
2024-08-03 18:29 ` Thomas Weißschuh
2024-08-03 18:33 ` Willy Tarreau
2024-07-28 10:10 ` [PATCH 07/12] selftests/nolibc: determine $(srctree) first Thomas Weißschuh
2024-08-03 9:40 ` Willy Tarreau
2024-08-04 15:55 ` Thomas Weißschuh
2024-07-28 10:10 ` [PATCH 08/12] selftests/nolibc: setup objtree without Makefile.include Thomas Weißschuh
2024-07-28 10:10 ` [PATCH 09/12] selftests/nolibc: add support for LLVM= parameter Thomas Weißschuh
2024-08-03 9:45 ` Willy Tarreau
2024-08-04 15:59 ` Thomas Weißschuh
2024-07-28 10:10 ` [PATCH 10/12] selftests/nolibc: add cc-option compatible with clang cross builds Thomas Weißschuh
2024-07-28 10:10 ` [PATCH 11/12] selftests/nolibc: run-tests.sh: avoid overwriting CFLAGS_EXTRA Thomas Weißschuh
2024-07-28 10:10 ` [PATCH 12/12] selftests/nolibc: run-tests.sh: allow building through LLVM Thomas Weißschuh
2024-07-29 19:26 ` [PATCH 00/12] tools/nolibc: improve LLVM/clang support Shuah Khan
2024-07-29 19:27 ` Shuah Khan
2024-08-03 9:50 ` Willy Tarreau
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=20240804034745.GA30236@1wt.eu \
--to=w@1wt.eu \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux@weissschuh.net \
--cc=shuah@kernel.org \
--cc=thomas@t-8ch.de \
/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