#3384 assigned enhancement

Prefer int for int32_t

Reported by: Sebastian Huber Owned by: Sebastian Huber
Priority: normal Milestone: 5.1
Component: tool/gcc Version:
Severity: normal Keywords:
Cc: Blocked By:
Blocking:

Description

Common systems like Linux and FreeBSD define int32_t to int. This means a lot of third party code works well in these cases:

#include <stdint.h>

void f(int32_t);

void f(int);

void g(int32_t *);

void h(void)
{
        int i;
        g(&i);
}

On RTEMS you get however in C

test.c:5:6: error: conflicting types for 'f'
 void f(int);
      ^
test.c:3:6: note: previous declaration of 'f' was here
 void f(int32_t);
      ^
test.c: In function 'h':
test.c:12:4: warning: passing argument 1 of 'g' from incompatible pointer type [-Wincompatible-pointer-types]
  g(&i);
    ^
test.c:7:6: note: expected 'int32_t * {aka long int *}' but argument is of type 'int *'
 void g(int32_t *);

and C++

test.c: In function 'void h()':
test.c:12:4: error: invalid conversion from 'int*' to 'int32_t* {aka long int*}' [-fpermissive]
  g(&i);
    ^~
test.c:7:6: note:   initializing argument 1 of 'void g(int32_t*)'
 void g(int32_t *);
      ^

This is due to a Newlib speciality which uses long for int32_t if long is a 32-bit type. To ease the use of third party software in RTEMS we should override this option and use int for int32_t just like the standard host operating systems (e.g. Linux and FreeBSD). Only a small GCC patch is required to do this:

diff --git a/gcc/config/rtems.h b/gcc/config/rtems.h
index 439199d4cbb..9b1408efe6f 100644
--- a/gcc/config/rtems.h
+++ b/gcc/config/rtems.h
@@ -48,3 +48,7 @@
  -latomic -lc -lgcc --end-group %{!qnolinkcmds: -T linkcmds%s}}}"
 
 #define TARGET_POSIX_IO
+
+/* Use int for int32_t (see stdint-newlib.h).  */
+#undef STDINT_LONG32
+#define STDINT_LONG32 0

Change History (7)

comment:1 Changed on Apr 9, 2018 at 1:39:53 PM by Joel Sherrill

Just to keep it clean, what if int is 16 bits on the target?

comment:2 Changed on Apr 9, 2018 at 1:46:46 PM by Sebastian Huber

See newlib-stdint.h in GCC sources:

[...]
#define INT32_TYPE (STDINT_LONG32 ? "long int" : INT_TYPE_SIZE == 32 ? "int" : SHORT_TYPE_SIZE == 32 ? "short int" : CHAR_TYPE_SIZE == 32 ? "signed char" : 0)
[...]

So, 16-bit targets should not use this option.

comment:4 Changed on Jun 14, 2018 at 5:23:35 AM by Sebastian Huber

Summary: Change int32_t to intPrefer int for int32_t

comment:5 Changed on Dec 11, 2018 at 7:39:39 AM by Sebastian Huber <sebastian.huber@…>

In b4e80fb/rtems-source-builder:

5: Update GCC 7.3.0 to 7.4.0

Update #3384.

comment:6 Changed on Dec 13, 2018 at 10:34:46 AM by Sebastian Huber <sebastian.huber@…>

In 258129e/rtems-source-builder:

5: Fix x86_64 GCC 7.4.0 build

Update #3384.

comment:7 Changed on Jan 29, 2019 at 8:22:22 AM by Sebastian Huber <sebastian.huber@…>

In 4f3a253/rtems:

psxtmtests: Fix format warnings

Update #3384.

Note: See TracTickets for help on using tickets.