public inbox for newlib@sourceware.org
 help / color / mirror / Atom feed
* [Patch] Allow 4 byte enum size (-fno-short-enums) | Remove hard coded short enum flag from the build scripts?
@ 2016-08-28 14:31 Dennis Pahl
  2016-08-30  9:47 ` ARM-only " Corinna Vinschen
  0 siblings, 1 reply; 15+ messages in thread
From: Dennis Pahl @ 2016-08-28 14:31 UTC (permalink / raw)
  To: newlib; +Cc: d.pahl

Hi,

in my project I need the enum size to be 4 bytes. Therefore in order to 
get no linker compatibility warnings, I also require newlib to use 4 
bytes for its enums.

4 byte enums can be achieved by specifying the following compiler flag 
"-fno-short-enums". This flag works fine for the source code of my 
project. Newlib, however, has a problem with this flag due to some hard 
coded compiler invocations which include the opposite flag "-fshort-enums".

A look in the mailing list archive revealed, that there already has been 
a discussion about this problem 
(https://sourceware.org/ml/newlib/2013/msg00183.html). The final advice 
from Michael Bruck, who started the discussion, was to remove these hard 
coded flags entirely from the build script files. Is there a reason why 
this did not happen?

With the removed hard coded flags the enum size can be configured by 
specifying
CFLAGS_FOR_TARGET= '-fno-short-enums' or '-fshort-enums'
CXXFLAGS_FOR_TARGET='-fno-short-enums' or '-fshort-enums'

By following Michael Bruck's advice I was able to build newlib with the 
wanted enum size.

Dennis Pahl

---

Here a patch with my adaptations, which remove the hard coded compiler 
flags:

commit d52c0a49ab9503718701977af451e0cb9164c084
Author: Dennis Pahl <dennis@pahl.de>
Date:   Sun Aug 28 13:48:28 2016 +0200

     removed the fix configuration of short enums for some build files. 
It is more appropriate if the external configuration decides whether the 
compiled files have short enums or not.

diff --git a/newlib/libc/stdio/Makefile.am b/newlib/libc/stdio/Makefile.am
index ea23de6..2a77b7b 100644
--- a/newlib/libc/stdio/Makefile.am
+++ b/newlib/libc/stdio/Makefile.am
@@ -254,44 +254,44 @@ include $(srcdir)/../../Makefile.shared
  if NEWLIB_NANO_FORMATTED_IO
  # Rules compiling small-footprint nano-formatted-io implementation.
  $(lpfx)nano-vfprintf.$(oext): nano-vfprintf.c
-	$(LIB_COMPILE) -fshort-enums -c $(srcdir)/nano-vfprintf.c -o $@
+	$(LIB_COMPILE) -c $(srcdir)/nano-vfprintf.c -o $@

  $(lpfx)nano-vfprintf_i.$(oext): nano-vfprintf_i.c
-	$(LIB_COMPILE) -fshort-enums -c $(srcdir)/nano-vfprintf_i.c -o $@
+	$(LIB_COMPILE) -c $(srcdir)/nano-vfprintf_i.c -o $@

  $(lpfx)nano-vfprintf_float.$(oext): nano-vfprintf_float.c
-	$(LIB_COMPILE) -fshort-enums -c $(srcdir)/nano-vfprintf_float.c -o $@
+	$(LIB_COMPILE) -c $(srcdir)/nano-vfprintf_float.c -o $@

  $(lpfx)nano-svfprintf.$(oext): nano-vfprintf.c
-	$(LIB_COMPILE) -fshort-enums -DSTRING_ONLY -c 
$(srcdir)/nano-vfprintf.c -o $@
+	$(LIB_COMPILE) -DSTRING_ONLY -c $(srcdir)/nano-vfprintf.c -o $@
  endif

  # This rule is needed so that libtool compiles vfiprintf before vfprintf.
  # Otherwise libtool moves vfprintf.o and subsequently can't find it.

  $(lpfx)vfprintf.$(oext): vfprintf.c
-	$(LIB_COMPILE) -fshort-enums -c $(srcdir)/vfprintf.c -o $@
+	$(LIB_COMPILE) -c $(srcdir)/vfprintf.c -o $@

  $(lpfx)vfiprintf.$(oext): vfprintf.c
-	$(LIB_COMPILE) -fshort-enums -DINTEGER_ONLY -c $(srcdir)/vfprintf.c -o $@
+	$(LIB_COMPILE) -DINTEGER_ONLY -c $(srcdir)/vfprintf.c -o $@

  $(lpfx)svfprintf.$(oext): vfprintf.c
-	$(LIB_COMPILE) -fshort-enums -DSTRING_ONLY -c $(srcdir)/vfprintf.c -o $@
+	$(LIB_COMPILE) -DSTRING_ONLY -c $(srcdir)/vfprintf.c -o $@

  $(lpfx)svfiprintf.$(oext): vfprintf.c
-	$(LIB_COMPILE) -fshort-enums -DINTEGER_ONLY -DSTRING_ONLY -c 
$(srcdir)/vfprintf.c -o $@
+	$(LIB_COMPILE) -DINTEGER_ONLY -DSTRING_ONLY -c $(srcdir)/vfprintf.c -o $@

  $(lpfx)vfwprintf.$(oext): vfwprintf.c
-	$(LIB_COMPILE) -fshort-enums -c $(srcdir)/vfwprintf.c -o $@
+	$(LIB_COMPILE) -c $(srcdir)/vfwprintf.c -o $@

  $(lpfx)vfiwprintf.$(oext): vfwprintf.c
-	$(LIB_COMPILE) -fshort-enums -DINTEGER_ONLY -c $(srcdir)/vfwprintf.c -o $@
+	$(LIB_COMPILE) -DINTEGER_ONLY -c $(srcdir)/vfwprintf.c -o $@

  $(lpfx)svfwprintf.$(oext): vfwprintf.c
-	$(LIB_COMPILE) -fshort-enums -DSTRING_ONLY -c $(srcdir)/vfwprintf.c -o $@
+	$(LIB_COMPILE) -DSTRING_ONLY -c $(srcdir)/vfwprintf.c -o $@

  $(lpfx)svfiwprintf.$(oext): vfwprintf.c
-	$(LIB_COMPILE) -fshort-enums -DINTEGER_ONLY -DSTRING_ONLY -c 
$(srcdir)/vfwprintf.c -o $@
+	$(LIB_COMPILE) -DINTEGER_ONLY -DSTRING_ONLY -c $(srcdir)/vfwprintf.c -o $@

  if NEWLIB_NANO_FORMATTED_IO
  # Rules compiling small-footprint nano-formatted-io implementation.
diff --git a/newlib/libc/stdio/Makefile.in b/newlib/libc/stdio/Makefile.in
index 8ea5f0a..8a7acd3 100644
--- a/newlib/libc/stdio/Makefile.in
+++ b/newlib/libc/stdio/Makefile.in
@@ -1882,43 +1882,43 @@ docbook: $(DOCBOOK_OUT_FILES)

  # Rules compiling small-footprint nano-formatted-io implementation.
  @NEWLIB_NANO_FORMATTED_IO_TRUE@$(lpfx)nano-vfprintf.$(oext): 
nano-vfprintf.c
-@NEWLIB_NANO_FORMATTED_IO_TRUE@	$(LIB_COMPILE) -fshort-enums -c 
$(srcdir)/nano-vfprintf.c -o $@
+@NEWLIB_NANO_FORMATTED_IO_TRUE@	$(LIB_COMPILE) -c 
$(srcdir)/nano-vfprintf.c -o $@

  @NEWLIB_NANO_FORMATTED_IO_TRUE@$(lpfx)nano-vfprintf_i.$(oext): 
nano-vfprintf_i.c
-@NEWLIB_NANO_FORMATTED_IO_TRUE@	$(LIB_COMPILE) -fshort-enums -c 
$(srcdir)/nano-vfprintf_i.c -o $@
+@NEWLIB_NANO_FORMATTED_IO_TRUE@	$(LIB_COMPILE) -c 
$(srcdir)/nano-vfprintf_i.c -o $@

  @NEWLIB_NANO_FORMATTED_IO_TRUE@$(lpfx)nano-vfprintf_float.$(oext): 
nano-vfprintf_float.c
-@NEWLIB_NANO_FORMATTED_IO_TRUE@	$(LIB_COMPILE) -fshort-enums -c 
$(srcdir)/nano-vfprintf_float.c -o $@
+@NEWLIB_NANO_FORMATTED_IO_TRUE@	$(LIB_COMPILE) -c 
$(srcdir)/nano-vfprintf_float.c -o $@

  @NEWLIB_NANO_FORMATTED_IO_TRUE@$(lpfx)nano-svfprintf.$(oext): 
nano-vfprintf.c
-@NEWLIB_NANO_FORMATTED_IO_TRUE@	$(LIB_COMPILE) -fshort-enums 
-DSTRING_ONLY -c $(srcdir)/nano-vfprintf.c -o $@
+@NEWLIB_NANO_FORMATTED_IO_TRUE@	$(LIB_COMPILE) -DSTRING_ONLY -c 
$(srcdir)/nano-vfprintf.c -o $@

  # This rule is needed so that libtool compiles vfiprintf before vfprintf.
  # Otherwise libtool moves vfprintf.o and subsequently can't find it.

  $(lpfx)vfprintf.$(oext): vfprintf.c
-	$(LIB_COMPILE) -fshort-enums -c $(srcdir)/vfprintf.c -o $@
+	$(LIB_COMPILE) -c $(srcdir)/vfprintf.c -o $@

  $(lpfx)vfiprintf.$(oext): vfprintf.c
-	$(LIB_COMPILE) -fshort-enums -DINTEGER_ONLY -c $(srcdir)/vfprintf.c -o $@
+	$(LIB_COMPILE) -DINTEGER_ONLY -c $(srcdir)/vfprintf.c -o $@

  $(lpfx)svfprintf.$(oext): vfprintf.c
-	$(LIB_COMPILE) -fshort-enums -DSTRING_ONLY -c $(srcdir)/vfprintf.c -o $@
+	$(LIB_COMPILE) -DSTRING_ONLY -c $(srcdir)/vfprintf.c -o $@

  $(lpfx)svfiprintf.$(oext): vfprintf.c
-	$(LIB_COMPILE) -fshort-enums -DINTEGER_ONLY -DSTRING_ONLY -c 
$(srcdir)/vfprintf.c -o $@
+	$(LIB_COMPILE) -DINTEGER_ONLY -DSTRING_ONLY -c $(srcdir)/vfprintf.c -o $@

  $(lpfx)vfwprintf.$(oext): vfwprintf.c
-	$(LIB_COMPILE) -fshort-enums -c $(srcdir)/vfwprintf.c -o $@
+	$(LIB_COMPILE) -c $(srcdir)/vfwprintf.c -o $@

  $(lpfx)vfiwprintf.$(oext): vfwprintf.c
-	$(LIB_COMPILE) -fshort-enums -DINTEGER_ONLY -c $(srcdir)/vfwprintf.c -o $@
+	$(LIB_COMPILE) -DINTEGER_ONLY -c $(srcdir)/vfwprintf.c -o $@

  $(lpfx)svfwprintf.$(oext): vfwprintf.c
-	$(LIB_COMPILE) -fshort-enums -DSTRING_ONLY -c $(srcdir)/vfwprintf.c -o $@
+	$(LIB_COMPILE) -DSTRING_ONLY -c $(srcdir)/vfwprintf.c -o $@

  $(lpfx)svfiwprintf.$(oext): vfwprintf.c
-	$(LIB_COMPILE) -fshort-enums -DINTEGER_ONLY -DSTRING_ONLY -c 
$(srcdir)/vfwprintf.c -o $@
+	$(LIB_COMPILE) -DINTEGER_ONLY -DSTRING_ONLY -c $(srcdir)/vfwprintf.c -o $@

  # Rules compiling small-footprint nano-formatted-io implementation.
  @NEWLIB_NANO_FORMATTED_IO_TRUE@$(lpfx)nano-vfscanf.$(oext): nano-vfscanf.c
diff --git a/newlib/libc/stdlib/Makefile.am b/newlib/libc/stdlib/Makefile.am
index 2d45d10..5e134e3 100644
--- a/newlib/libc/stdlib/Makefile.am
+++ b/newlib/libc/stdlib/Makefile.am
@@ -307,7 +307,7 @@ $(lpfx)dtoa.$(oext): dtoa.c mprec.h
  $(lpfx)ldtoa.$(oext): ldtoa.c mprec.h
  $(lpfx)ecvtbuf.$(oext): ecvtbuf.c mprec.h
  $(lpfx)mbtowc_r.$(oext): mbtowc_r.c mbctype.h
-	$(LIB_COMPILE) -c -fshort-enums $(srcdir)/mbtowc_r.c -o $@
+	$(LIB_COMPILE) -c $(srcdir)/mbtowc_r.c -o $@

  $(lpfx)mprec.$(oext): mprec.c mprec.h
  $(lpfx)strtod.$(oext): strtod.c mprec.h
diff --git a/newlib/libc/stdlib/Makefile.in b/newlib/libc/stdlib/Makefile.in
index 466ab6d..88a0db5 100644
--- a/newlib/libc/stdlib/Makefile.in
+++ b/newlib/libc/stdlib/Makefile.in
@@ -1560,7 +1560,7 @@ $(lpfx)dtoa.$(oext): dtoa.c mprec.h
  $(lpfx)ldtoa.$(oext): ldtoa.c mprec.h
  $(lpfx)ecvtbuf.$(oext): ecvtbuf.c mprec.h
  $(lpfx)mbtowc_r.$(oext): mbtowc_r.c mbctype.h
-	$(LIB_COMPILE) -c -fshort-enums $(srcdir)/mbtowc_r.c -o $@
+	$(LIB_COMPILE) -c $(srcdir)/mbtowc_r.c -o $@

  $(lpfx)mprec.$(oext): mprec.c mprec.h
  $(lpfx)strtod.$(oext): strtod.c mprec.h

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

end of thread, other threads:[~2016-08-31 16:04 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-28 14:31 [Patch] Allow 4 byte enum size (-fno-short-enums) | Remove hard coded short enum flag from the build scripts? Dennis Pahl
2016-08-30  9:47 ` ARM-only " Corinna Vinschen
2016-08-30 12:45   ` Joel Sherrill
2016-08-30 13:07   ` Richard Earnshaw (lists)
2016-08-30 18:23     ` Corinna Vinschen
2016-08-30 13:17   ` Schwarz, Konrad
2016-08-30 18:28     ` Corinna Vinschen
2016-08-30 23:26       ` Pavel Pisa
2016-08-31  7:56       ` Schwarz, Konrad
2016-08-31 11:15         ` Richard Earnshaw (lists)
2016-08-31 11:36           ` Schwarz, Konrad
2016-08-31 12:37             ` Richard Earnshaw (lists)
2016-08-31 12:44               ` Schwarz, Konrad
2016-08-31 14:33                 ` Richard Earnshaw (lists)
2016-08-31 16:04                   ` Richard Earnshaw (lists)

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