mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@libc.org>
To: musl@lists.openwall.com
Subject: Re: the size of the int type
Date: Fri, 15 Jan 2016 16:33:14 -0500	[thread overview]
Message-ID: <20160115213313.GH238@brightrain.aerifal.cx> (raw)
In-Reply-To: <CAD+Cw=cpuWsDf9R44zNx5-96nd6FB=MoNsekBNVUbBo-_eCv_w@mail.gmail.com>

On Fri, Jan 15, 2016 at 04:01:12PM -0500, Max Ruttenberg wrote:
> Hi,
> 
> I'm wondering if there's any code in musl that makes assumptions on the
> size of the "int" type.
> 
> I only ask because I'm debating how my compiler (which targets a machine
> with a 64-bit word size) should define the int type. Ideally I'd like to
> break as little library code as possible.

The musl headers "assume" int is 32-bit in the sense that 32-bit types
are defined in the top-level headers with 'int' or 'unsigned' rather
than being arch-specific/bits-headers-level. This is not a so much a
code-level assumption as a simplification of the headers, but it's not
one where I'd want to introduce extra gratuitous abstraction upstream.
If int is not 32-bit, then you can't define both 16-bit and 32-bit
types ([u]int{16,32}_t) without needing a nonstandard (extended)
integer type for at least one of them since short is the only standard
type that's smaller.

In addition, futex-related code sort of assumes int is 32-bit. There's
code that treats 'bit 31 set' and 'negative' as equivalent conditions,
code that uses hard-coded bits of the futex word (both for private
purposes and to match kernel ABI for robust mutexes, etc.), and
perhaps other issues. This code would need additional abstraction to
support other-than-32-bit int.

Finally, making int larger than 64-bit would break a lot of
application code. While modern applications are written with the
understanding that default promotions cause arithmetic on [u]int8_t
and [u]int16_t to actually happen as signed arithmetic in type int,
everybody (wrongly, from a portability standpoint) assumes uint32_t
arithmetic is actually unsigned arithmetic and wraps as expected. If
int were higher-rank than uint32_t, such arithmetic would happen as
signed int, and overflows would be undefined behavior, not wrapping.
Lots of other nasty issues with default promotions arise too.

So in summary, I think making int 64-bit is a bad idea, and not
something I'd want to make the effort to support upstream in musl.
LP64 is the "right" model for 64-bit ABIs.

Rich


      parent reply	other threads:[~2016-01-15 21:33 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-15 21:01 Max Ruttenberg
2016-01-15 21:11 ` Josiah Worcester
2016-01-15 21:19   ` Max Ruttenberg
2016-01-16 11:09   ` croco
2016-01-16 13:09     ` Jens Gustedt
2016-01-18 15:22       ` Max Ruttenberg
2016-01-15 21:33 ` Rich Felker [this message]

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=20160115213313.GH238@brightrain.aerifal.cx \
    --to=dalias@libc.org \
    --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).