public inbox for newlib@sourceware.org
 help / color / mirror / Atom feed
From: Dennis Pahl <dennis@pahl.de>
To: newlib@sourceware.org
Cc: d.pahl@pilz.de
Subject: [Patch] Allow 4 byte enum size (-fno-short-enums) | Remove hard coded short enum flag from the build scripts?
Date: Sun, 28 Aug 2016 14:31:00 -0000	[thread overview]
Message-ID: <86388ac2-70e3-2a15-a021-cab3b0dea9fe@pahl.de> (raw)

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

             reply	other threads:[~2016-08-28 14:31 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-28 14:31 Dennis Pahl [this message]
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)

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=86388ac2-70e3-2a15-a021-cab3b0dea9fe@pahl.de \
    --to=dennis@pahl.de \
    --cc=d.pahl@pilz.de \
    --cc=newlib@sourceware.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).