public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Alejandro Colomar <alx.manpages@gmail.com>
To: libc-alpha@sourceware.org
Cc: Florian Weimer <fweimer@redhat.com>, JeanHeyd Meneide <wg14@soasis.org>
Subject: Re: [PATCH] inttypes.h: imaxabs(3): Implement as a macro
Date: Tue, 13 Sep 2022 17:34:38 +0200	[thread overview]
Message-ID: <045b7ab3-4a82-0d1e-f364-81286abc24ba@gmail.com> (raw)
In-Reply-To: <20220913151853.153311-1-alx.manpages@gmail.com>


[-- Attachment #1.1: Type: text/plain, Size: 2567 bytes --]

Hi Florian,

On 9/13/22 17:18, Alex Colomar wrote:
> Functions using the [u]intmax_t types have a problem: ABI.
> 
> The [u]intmax_t types were designed so that users could blindly
> use them to work with whatever is the biggest size for a given
> architecture.  But this is problematic to implement.  These days,
> ABI stability is very important, and programs compiled a specific
> version of glibc should continue working with newer glibc
> releases.  Of course, that means that future glibc versions can't
> change the types of functions, or the functions would be
> incompatible.
> 
> So, we cannot really change the (linker) signature of functions;
> not even of those using [u]intmax_t.
> 
> A solution to that problem is to use macros, and not real
> functions.  That way, the program really links against whatever
> function works with the compile-time maximum width type, be it
> long or long long, and the program will be bonded to the ABI of
> long or long long, but will know nothing about intmax_t.
> 
> We still need a linker symbol with the name imaxabs(), for old
> programs linked against old glibc versions, and also for
> compatibility with an interpretation of the ISO C standard that
> says that imaxabs(3) is a function.  But the standard knows
> nothing about ABI or a linker, so a macro that evaluates to a
> differently-named function is not a straight violation, but rather
> stepping through the line without crossing it, AFAIK.
> 
> This implementation with C11 _Generic() is one that I used for the
> new _Generic(3) manual page.  It allows treating the macro as a
> function, and to take pointers to it.  And it allows to more
> easily understand the definition of the macro, without needing
> to parse the ifdefs.  It makes it easier to parse with tools like
> grepc(1):
> 
> $ grepc -k __PRI64_PREFIX inttypes.h
> inttypes.h:44:#  define __PRI64_PREFIX	"l"
> inttypes.h:47:#  define __PRI64_PREFIX	"ll"
> $ grepc -k imaxabs inttypes.h
> inttypes.h:290:#define imaxabs  _Generic(INTMAX_C(0), long: labs, long long: llabs)
> 
> If glibc can't use C11 features in public headers, then usual
> ifdefs could be used.
> 
> Cc: Florian Weimer <fweimer@redhat.com>
> Cc: JeanHeyd Meneide <wg14@soasis.org>
> Signed-off-by: Alex Colomar <alx.manpages@gmail.com>
> ---

My plan, if this is welcome, is to get rid of most traces of [u]intmax_t 
in the ABI, so I'd continue with similar patches for other functions and 
symbols.

Cheers,

Alex

-- 
<http://www.alejandro-colomar.es/>

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  parent reply	other threads:[~2022-09-13 15:34 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-13 15:18 Alex Colomar
2022-09-13 15:28 ` Alejandro Colomar
2022-09-13 15:34 ` Alejandro Colomar [this message]
2022-09-13 18:27 ` Joseph Myers
2022-09-13 18:47   ` Paul Eggert
2022-09-13 19:30     ` Joseph Myers
2022-09-13 20:59       ` Paul Eggert
2022-09-13 22:43   ` Alejandro Colomar
2022-09-13 22:56     ` Joseph Myers
2022-09-13 23:43       ` Alejandro Colomar
2022-09-14 16:41         ` Joseph Myers
2022-09-14 19:03           ` JeanHeyd Meneide
2022-09-15 12:33             ` Alejandro (Alex) Colomar

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=045b7ab3-4a82-0d1e-f364-81286abc24ba@gmail.com \
    --to=alx.manpages@gmail.com \
    --cc=fweimer@redhat.com \
    --cc=libc-alpha@sourceware.org \
    --cc=wg14@soasis.org \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).