mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Alastair Houghton <ahoughton@apple.com>
To: musl@lists.openwall.com
Subject: Re: [musl] __MUSL__ macro
Date: Fri, 07 Jul 2023 08:14:11 +0100	[thread overview]
Message-ID: <ADA97FB8-5654-4DBB-AE27-0055885439F3@apple.com> (raw)
In-Reply-To: <168864586814.64499.13397704850676744237@alexps.local>

On 6 Jul 2023, at 13:17, Alex Xu <alex_y_xu@yahoo.ca> wrote:
> 
>> Examples include the use of `union`s in `pthread_mutex_t` et al (which means that we can’t write a C++ `constexpr` function that returns one, even if all it does is return `PTHREAD_MUTEX_INITIALIZER`),
> 
> The issue is that some of the members are volatile, not the union
> itself.

...

Arguing about the details of individual issues is an unnecessary distraction, honestly.  They were just OTOH examples of oddities that we’ve come across so far, and yes, I agree that in some cases there are potentially better fixes for them than preprocessor shenanigans - and where those are available I’m totally onboard with doing that instead, because I *entirely agree* that it’s better to avoid a huge mass of `#if` conditions in code.  There’s a very good chance that any I add in the various places I might be interested in adding them will end up being my responsibility to maintain, so that, if nothing else, is a good motivation for minimising them.

>> or the fact that `dladdr()` is a no-op when statically linked.
> 
> When statically linked, the dynamic linking interface doesn't work at
> all though? And furthermore, even if it did, what would it return? If
> you're (once again) trying to do stack traces manually, try libunwind?

:-D Oh, the irony.  One of the places where this behaviour turns out to be a problem is *in the tests for libunwind*.  (That can be solved in another way without resorting to macros, however.)

> I don't understand, don't you know at compile time whether you're
> linking statically or dynamically?

Not always, no (see situation 2 below).

> Configure-time checks for specific functionality are a standard part of
> writing portable C code. Preprocessor checks for specific platforms lead
> to ifdef swamps that are still not portable to any platforms not
> initially considered.

There are two situations where the lack of macros is absolutely a problem and there isn’t a sane workaround.

1. You’re cross compiling and the thing you’re interested in is *runtime* behaviour, so configure-style checks simply aren’t an option.  In a cross-compilation situation the only thing they can test is that a program will *build*; they can’t test its behaviour since you don’t necessarily have anywhere to run it.

2. You’re in a header-only library, particularly one where the final environment you’re running in wasn’t available at whatever configuration time you had, assuming you had one at all.  A really good example of this is the built-in headers in Clang or GCC, but the problem also applies to things like STL or Boost.

> On 6 Jul 2023, at 17:26, Szabolcs Nagy <nsz@port70.net> wrote:
> 
> the problem is not that the usage is wrong, but that
> these can change between different versions of musl
> (within abi constraints) and header changes can be
> backported by distros.
> 
> so __MUSL__ cannot solve these issues.


That’s why `__MUSL__` should evaluate to the major version number and `__MUSL_MINOR__` to the minor version number, and why we should have `__MUSL_PREREQ()`, just like Glibc, which, by the way, has the exact same problems you raise (things can change, and distros can backport things).

If some third-party package wishes to test `__MUSL__`, it’s up to the maintainers of that package to make sure that they perform appropriate version checks.  And yes, if they’re working around a bug or musl changes its behaviour to add a feature that wasn’t there, they may have to update their code from `#ifndef __MUSL__` to `#if __MUSL_PREREQ(x,y)` or similar.  Package maintainers that make these kinds of tests are used to having to do that and if they’re willing to accept macro-based tests, then they’ll be well aware of the cost of doing so.

The alternative to adding these isn’t “lots of non-buggy support for musl”.  It’s “less support for musl”, because there are awkward corner cases where it just isn’t possible to do things any other way.

Kind regards,

Alastair.


  parent reply	other threads:[~2023-07-07  7:14 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-06 10:48 Alastair Houghton
2023-07-06 12:17 ` Alex Xu
2023-07-06 16:26   ` Szabolcs Nagy
2023-07-07  7:14   ` Alastair Houghton [this message]
2023-07-07  7:30     ` A. Wilcox
2023-07-07  8:24       ` Alastair Houghton
2023-07-07 11:20     ` Laurent Bercot
2023-07-07 11:45     ` Jeffrey Walton
2023-07-07 13:53     ` Rich Felker
2023-07-07 14:18       ` Alastair Houghton
2023-07-07 12:47 ` Rich Felker
2023-07-07 13:14   ` Alastair Houghton
2023-07-07 14:19     ` Markus Wichmann
2023-07-07 14:26       ` Markus Wichmann
2023-07-07 14:46       ` Alastair Houghton
2023-07-07 15:02       ` Andrew Bell
2023-07-07 15:19         ` Markus Wichmann
2023-07-07 15:24           ` Andrew Bell
2023-07-07 15:34           ` Alastair Houghton
2023-07-07 15:45             ` Rich Felker
2023-07-07 15:58               ` Alastair Houghton
2023-07-07 15:05     ` i262jq

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=ADA97FB8-5654-4DBB-AE27-0055885439F3@apple.com \
    --to=ahoughton@apple.com \
    --cc=musl@lists.openwall.com \
    /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.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).