public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] endian.h: Define unsigned fixed-width integer types [BZ #31749]
@ 2024-06-11  8:45 Collin Funk
  2024-06-11 13:04 ` Joseph Myers
  2024-06-11 16:24 ` [PATCH v2] " Collin Funk
  0 siblings, 2 replies; 8+ messages in thread
From: Collin Funk @ 2024-06-11  8:45 UTC (permalink / raw)
  To: libc-alpha; +Cc: Collin Funk

The upcoming POSIX revision requires that uint16_t, uint32_t, and
uint64_t are defined in endian.h.  Optionally all symbols from
<stdint.h> may be defined.

This patch includes <bits/stdint-uintn.h> which defines the required
types and uint8_t.  This allows glibc to pass Gnulib's checks.

Signed-off-by: Collin Funk <collin.funk1@gmail.com>
---
 string/endian.h            | 3 +++
 string/test-endian-types.c | 1 -
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/string/endian.h b/string/endian.h
index fd20a2b198..1c5829d248 100644
--- a/string/endian.h
+++ b/string/endian.h
@@ -31,6 +31,9 @@
 #endif
 
 #if defined __USE_MISC && !defined __ASSEMBLER__
+/* Define uintN_t types.  */
+#include <bits/stdint-uintn.h>
+
 /* Conversion interfaces.  */
 # include <bits/byteswap.h>
 # include <bits/uintn-identity.h>
diff --git a/string/test-endian-types.c b/string/test-endian-types.c
index a0ff971f24..fa624e39c2 100644
--- a/string/test-endian-types.c
+++ b/string/test-endian-types.c
@@ -17,7 +17,6 @@
    <https://www.gnu.org/licenses/>.  */
 
 #include <endian.h>
-#include <stdint.h>
 
 int i;
 uint16_t u16;
-- 
2.45.2


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] endian.h: Define unsigned fixed-width integer types [BZ #31749]
  2024-06-11  8:45 [PATCH] endian.h: Define unsigned fixed-width integer types [BZ #31749] Collin Funk
@ 2024-06-11 13:04 ` Joseph Myers
  2024-06-11 14:58   ` Collin Funk
  2024-06-11 16:24 ` [PATCH v2] " Collin Funk
  1 sibling, 1 reply; 8+ messages in thread
From: Joseph Myers @ 2024-06-11 13:04 UTC (permalink / raw)
  To: Collin Funk; +Cc: libc-alpha

On Tue, 11 Jun 2024, Collin Funk wrote:

>  #if defined __USE_MISC && !defined __ASSEMBLER__
> +/* Define uintN_t types.  */
> +#include <bits/stdint-uintn.h>
> +

__USE_MISC is not defined for any standard POSIX version.

Do you know the _POSIX_C_SOURCE value in the 2024 edition of POSIX (the 
most recent version I have is the February draft, which still has it as 
20yymmL; the HTML edition hasn't been published yet)?  We need to set up 
(in features.h) and document (in creature.texi) support for the new 
_XOPEN_SOURCE and _POSIX_C_SOURCE values, with associated internal 
conditions __GLIBC_USE (XOPEN2024) and __GLIBC_USE (POSIX2024), and go 
through all the changes in the new edition of POSIX, making sure that 
header declarations appear under appropriate conditions (or, as 
applicable, no longer appear for strict conformance with the latest 
version, in the case of any declarations that POSIX has removed) and that 
new features in general are properly implemented in glibc.

*In this particular case*, since <endian.h> wasn't in any previous version 
of POSIX, we don't actually need those conditionals - we could just remove 
__USE_MISC conditions around everything defined for the header in the new 
POSIX version (making sure to adjust the spaces after "#" accordingly for 
the removed #if level), and define the types in question unconditionally.

-- 
Joseph S. Myers
josmyers@redhat.com


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] endian.h: Define unsigned fixed-width integer types [BZ #31749]
  2024-06-11 13:04 ` Joseph Myers
@ 2024-06-11 14:58   ` Collin Funk
  2024-06-11 15:09     ` Joseph Myers
  0 siblings, 1 reply; 8+ messages in thread
From: Collin Funk @ 2024-06-11 14:58 UTC (permalink / raw)
  To: Joseph Myers; +Cc: libc-alpha

Hi Joseph,

Joseph Myers <josmyers@redhat.com> writes:

> On Tue, 11 Jun 2024, Collin Funk wrote:
>
>>  #if defined __USE_MISC && !defined __ASSEMBLER__
>> +/* Define uintN_t types.  */
>> +#include <bits/stdint-uintn.h>
>> +
>
> __USE_MISC is not defined for any standard POSIX version.
>
> Do you know the _POSIX_C_SOURCE value in the 2024 edition of POSIX (the 
> most recent version I have is the February draft, which still has it as 
> 20yymmL; the HTML edition hasn't been published yet)?

No, I was using the February draft PDF as well.  I checked <features.h>
and didn't see a definition so I just left it behind __USE_MISC for the
time being.

> *In this particular case*, since <endian.h> wasn't in any previous version 
> of POSIX, we don't actually need those conditionals - we could just remove 
> __USE_MISC conditions around everything defined for the header in the new 
> POSIX version (making sure to adjust the spaces after "#" accordingly for 
> the removed #if level), and define the types in question unconditionally.

Sounds good, I can submit a revised patch.

Is the !defined __ASSEMBLER__ safe to remove?  It looks like perhaps
this header was at some point used in assembly code for constant macro
definitions without the functions.  Not sure if this is still the case
or if it should be worried about.

Collin

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] endian.h: Define unsigned fixed-width integer types [BZ #31749]
  2024-06-11 14:58   ` Collin Funk
@ 2024-06-11 15:09     ` Joseph Myers
  2024-06-11 15:16       ` Collin Funk
  0 siblings, 1 reply; 8+ messages in thread
From: Joseph Myers @ 2024-06-11 15:09 UTC (permalink / raw)
  To: Collin Funk; +Cc: libc-alpha

On Tue, 11 Jun 2024, Collin Funk wrote:

> Is the !defined __ASSEMBLER__ safe to remove?  It looks like perhaps
> this header was at some point used in assembly code for constant macro
> definitions without the functions.  Not sure if this is still the case
> or if it should be worried about.

That's the sort of thing that would best be tested with 
build-many-glibcs.py to see if any configurations are using <endian.h> 
(possibly indirectly) in assembly source at present.  It appears the 
original addition of that check was because of a use in SH strlen.S, which 
was removed in commit 3ce2865f93d42f4721d58088dd6ab1dac06ea85b "SH: 
Replace <endian.h> usage with pre-processor macros.", but maybe there are 
other places still relying on it in assembly source.

-- 
Joseph S. Myers
josmyers@redhat.com


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] endian.h: Define unsigned fixed-width integer types [BZ #31749]
  2024-06-11 15:09     ` Joseph Myers
@ 2024-06-11 15:16       ` Collin Funk
  0 siblings, 0 replies; 8+ messages in thread
From: Collin Funk @ 2024-06-11 15:16 UTC (permalink / raw)
  To: Joseph Myers; +Cc: libc-alpha

Joseph Myers <josmyers@redhat.com> writes:

> That's the sort of thing that would best be tested with 
> build-many-glibcs.py to see if any configurations are using <endian.h> 
> (possibly indirectly) in assembly source at present.  It appears the 
> original addition of that check was because of a use in SH strlen.S, which 
> was removed in commit 3ce2865f93d42f4721d58088dd6ab1dac06ea85b "SH: 
> Replace <endian.h> usage with pre-processor macros.", but maybe there are 
> other places still relying on it in assembly source.

Thanks for the advice.  I'll do some testing and send an updated patch.

Collin

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v2] endian.h: Define unsigned fixed-width integer types [BZ #31749]
  2024-06-11  8:45 [PATCH] endian.h: Define unsigned fixed-width integer types [BZ #31749] Collin Funk
  2024-06-11 13:04 ` Joseph Myers
@ 2024-06-11 16:24 ` Collin Funk
  2024-06-11 17:00   ` Paul Eggert
  1 sibling, 1 reply; 8+ messages in thread
From: Collin Funk @ 2024-06-11 16:24 UTC (permalink / raw)
  To: libc-alpha; +Cc: josmyers, Collin Funk

The #ifdef __ASSEMBLER__ is required since sysdeps/unix/sysv/linux/sysdep.h
includes <endian.h> which is then included by assembly files.  It seems
that most assembly uses the pre-defined macros by GCC now so it *could*
be removed there.  But this method remains compatible with assembly code
that assumes <endian.h> can be included like previous versions of glibc.
-- 8< --

The upcoming POSIX revision requires that uint16_t, uint32_t, and
uint64_t are defined in endian.h.  Optionally all symbols from
<stdint.h> may be defined.

This patch includes <bits/stdint-uintn.h> which defines the required
types and uint8_t.  This allows glibc to pass Gnulib's checks.

Signed-off-by: Collin Funk <collin.funk1@gmail.com>
---
 string/endian.h            | 15 ++++++++-------
 string/test-endian-types.c |  1 -
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/string/endian.h b/string/endian.h
index fd20a2b198..32001761c8 100644
--- a/string/endian.h
+++ b/string/endian.h
@@ -23,14 +23,15 @@
 /* Get the definitions of __*_ENDIAN, __BYTE_ORDER, and __FLOAT_WORD_ORDER.  */
 #include <bits/endian.h>
 
-#ifdef __USE_MISC
-# define LITTLE_ENDIAN	__LITTLE_ENDIAN
-# define BIG_ENDIAN	__BIG_ENDIAN
-# define PDP_ENDIAN	__PDP_ENDIAN
-# define BYTE_ORDER	__BYTE_ORDER
-#endif
+#define LITTLE_ENDIAN	__LITTLE_ENDIAN
+#define BIG_ENDIAN	__BIG_ENDIAN
+#define PDP_ENDIAN	__PDP_ENDIAN
+#define BYTE_ORDER	__BYTE_ORDER
+
+#ifndef __ASSEMBLER__
+/* Define uintN_t types.  */
+# include <bits/stdint-uintn.h>
 
-#if defined __USE_MISC && !defined __ASSEMBLER__
 /* Conversion interfaces.  */
 # include <bits/byteswap.h>
 # include <bits/uintn-identity.h>
diff --git a/string/test-endian-types.c b/string/test-endian-types.c
index a0ff971f24..fa624e39c2 100644
--- a/string/test-endian-types.c
+++ b/string/test-endian-types.c
@@ -17,7 +17,6 @@
    <https://www.gnu.org/licenses/>.  */
 
 #include <endian.h>
-#include <stdint.h>
 
 int i;
 uint16_t u16;
-- 
2.45.2


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] endian.h: Define unsigned fixed-width integer types [BZ #31749]
  2024-06-11 16:24 ` [PATCH v2] " Collin Funk
@ 2024-06-11 17:00   ` Paul Eggert
  2024-06-15  9:53     ` Collin Funk
  0 siblings, 1 reply; 8+ messages in thread
From: Paul Eggert @ 2024-06-11 17:00 UTC (permalink / raw)
  To: Collin Funk, libc-alpha; +Cc: josmyers

These patches look good to me.

Reviewed-by: Paul Eggert <eggert@cs.ucla.edu>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] endian.h: Define unsigned fixed-width integer types [BZ #31749]
  2024-06-11 17:00   ` Paul Eggert
@ 2024-06-15  9:53     ` Collin Funk
  0 siblings, 0 replies; 8+ messages in thread
From: Collin Funk @ 2024-06-15  9:53 UTC (permalink / raw)
  To: Paul Eggert, libc-alpha; +Cc: josmyers

Hi Paul,

On 6/11/24 10:00 AM, Paul Eggert wrote:
> These patches look good to me.
> 
> Reviewed-by: Paul Eggert <eggert@cs.ucla.edu>

This patch causes the CI to fail the conform tests. Now that
__USE_MISC is removed netinet/in.h, and other files that include it,
show LITTLE_ENDIAN, be16toh, etc. It appears the header is only used
to check __BYTE_ORDER so I think including <bits/endian.h> there would
solve the issue.

Also, I'm not sure how things are done in glibc so feel free to push
the change if it is okay. :)

Collin

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2024-06-15  9:53 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-11  8:45 [PATCH] endian.h: Define unsigned fixed-width integer types [BZ #31749] Collin Funk
2024-06-11 13:04 ` Joseph Myers
2024-06-11 14:58   ` Collin Funk
2024-06-11 15:09     ` Joseph Myers
2024-06-11 15:16       ` Collin Funk
2024-06-11 16:24 ` [PATCH v2] " Collin Funk
2024-06-11 17:00   ` Paul Eggert
2024-06-15  9:53     ` Collin Funk

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).