public inbox for newlib@sourceware.org
 help / color / mirror / Atom feed
* sys-include/newlib.h
@ 2016-12-09 15:42 Jon Beniston
  2016-12-09 19:07 ` sys-include/newlib.h Jeff Johnston
  0 siblings, 1 reply; 12+ messages in thread
From: Jon Beniston @ 2016-12-09 15:42 UTC (permalink / raw)
  To: newlib

Hi,

I'm compiling newlib 2.4.0 with gcc 6.1 configured as a cross compiler. In
order for some gcc libc support to be built, I need to configure with
--with-headers=/path/newlib/libc/include/

This results in the .h files from that directory being copied to
target/sys-include. GCC's built in search path searches target/sys-include
before target/include. This results in a bit of a problem when compiling C++
code, as target/sys-include/newlib.h differs from target/include/newlib.h

target/sys-include/newlib.h is an otherwise empty file that just says:

/* dummy file for external tools to use.  Real file is created by
   newlib configuration. */

Whereas target/include/newlib.h includes the newlib configuration macros,
such as:

#define _HAVE_LONG_DOUBLE 1

This causes an error "'::strtold' has not been declared"  when compiling C++
code, as the prototype for this function in stdlib.h, depends on this macro:

#ifdef _HAVE_LONG_DOUBLE
extern long double strtold (const char *__restrict, char **__restrict);
#endif /* _HAVE_LONG_DOUBLE */

Which is not defined as  target/sys-include/newlib.h is included instead of
target/include/newlib.h

The same applies to _newlib_version.h too.

And ideas on the best way to resolve this? Is it a gcc or newlib problem or
user error?

Thanks,
Jon

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

* Re: sys-include/newlib.h
  2016-12-09 15:42 sys-include/newlib.h Jon Beniston
@ 2016-12-09 19:07 ` Jeff Johnston
  2016-12-09 20:47   ` sys-include/newlib.h Jon Beniston
  0 siblings, 1 reply; 12+ messages in thread
From: Jeff Johnston @ 2016-12-09 19:07 UTC (permalink / raw)
  To: Jon Beniston; +Cc: newlib

Hi Jon,

What you are trying is unsupported.  Newlib configuration needs to run.
Have you tried --with-newlib?  You might need to add a configure-target-newlib
or all-target-newlib target to your configure call.  

-- Jeff J.

----- Original Message -----
> Hi,
> 
> I'm compiling newlib 2.4.0 with gcc 6.1 configured as a cross compiler. In
> order for some gcc libc support to be built, I need to configure with
> --with-headers=/path/newlib/libc/include/
> 
> This results in the .h files from that directory being copied to
> target/sys-include. GCC's built in search path searches target/sys-include
> before target/include. This results in a bit of a problem when compiling C++
> code, as target/sys-include/newlib.h differs from target/include/newlib.h
> 
> target/sys-include/newlib.h is an otherwise empty file that just says:
> 
> /* dummy file for external tools to use.  Real file is created by
>    newlib configuration. */
> 
> Whereas target/include/newlib.h includes the newlib configuration macros,
> such as:
> 
> #define _HAVE_LONG_DOUBLE 1
> 
> This causes an error "'::strtold' has not been declared"  when compiling C++
> code, as the prototype for this function in stdlib.h, depends on this macro:
> 
> #ifdef _HAVE_LONG_DOUBLE
> extern long double strtold (const char *__restrict, char **__restrict);
> #endif /* _HAVE_LONG_DOUBLE */
> 
> Which is not defined as  target/sys-include/newlib.h is included instead of
> target/include/newlib.h
> 
> The same applies to _newlib_version.h too.
> 
> And ideas on the best way to resolve this? Is it a gcc or newlib problem or
> user error?
> 
> Thanks,
> Jon
> 
> 

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

* RE: sys-include/newlib.h
  2016-12-09 19:07 ` sys-include/newlib.h Jeff Johnston
@ 2016-12-09 20:47   ` Jon Beniston
  2016-12-09 21:18     ` sys-include/newlib.h Jeff Johnston
  2016-12-12 11:03     ` sys-include/newlib.h Sebastian Huber
  0 siblings, 2 replies; 12+ messages in thread
From: Jon Beniston @ 2016-12-09 20:47 UTC (permalink / raw)
  To: newlib; +Cc: 'Jeff Johnston'

Hi Jeff,

> What you are trying is unsupported.  Newlib configuration needs to run.
> Have you tried --with-newlib?  You might need to add a
> configure-target-newlib or all-target-newlib target to your configure call.  

I'm not sure what you mean by newlib configuration needs to run. I thought it was, and that's what is generating target/include/newlib.h (which has the correct values generate by configure).

Yes, I'm using --with-newlib. This is with newlib & gcc source trees merged, so they configure and build together. 

Do you mean --with-headers is unsupported? If I don't use that, then inhibit_libc=true is set in gcc/Makefile, and things like gprof support aren't built.

Here's the code from gcc/configure.ac

if { { test x$host != x$target && test "x$with_sysroot" = x ; } ||
       test x$with_newlib = xyes ; } &&
     { test "x$with_headers" = xno || test ! -f "$target_header_dir/stdio.h"; } ; then
       inhibit_libc=true

Is that not saying it needs to be set?

Thanks,
Jon
 

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

* Re: sys-include/newlib.h
  2016-12-09 20:47   ` sys-include/newlib.h Jon Beniston
@ 2016-12-09 21:18     ` Jeff Johnston
  2016-12-10  0:05       ` sys-include/newlib.h Jon Beniston
  2016-12-12 11:03     ` sys-include/newlib.h Sebastian Huber
  1 sibling, 1 reply; 12+ messages in thread
From: Jeff Johnston @ 2016-12-09 21:18 UTC (permalink / raw)
  To: Jon Beniston; +Cc: newlib

I did not know you were specifying --with-newlib, but should have surmised it.

What isn't supported is specifying headers from the newlib source directory (i.e.
unconfigured headers) and expecting to properly compile code.  Is it possible
to point to an empty directory to skirt the inhibit_libc check and use the target/include
headers that you say are on the include path and built as part of configuration?

-- Jeff J.

----- Original Message -----
> Hi Jeff,
> 
> > What you are trying is unsupported.  Newlib configuration needs to run.
> > Have you tried --with-newlib?  You might need to add a
> > configure-target-newlib or all-target-newlib target to your configure call.
> 
> I'm not sure what you mean by newlib configuration needs to run. I thought it
> was, and that's what is generating target/include/newlib.h (which has the
> correct values generate by configure).
> 
> Yes, I'm using --with-newlib. This is with newlib & gcc source trees merged,
> so they configure and build together.
> 
> Do you mean --with-headers is unsupported? If I don't use that, then
> inhibit_libc=true is set in gcc/Makefile, and things like gprof support
> aren't built.
> 
> Here's the code from gcc/configure.ac
> 
> if { { test x$host != x$target && test "x$with_sysroot" = x ; } ||
>        test x$with_newlib = xyes ; } &&
>      { test "x$with_headers" = xno || test ! -f "$target_header_dir/stdio.h";
>      } ; then
>        inhibit_libc=true
> 
> Is that not saying it needs to be set?
> 
> Thanks,
> Jon
>  
> 
> 

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

* RE: sys-include/newlib.h
  2016-12-09 21:18     ` sys-include/newlib.h Jeff Johnston
@ 2016-12-10  0:05       ` Jon Beniston
  2016-12-12 18:54         ` sys-include/newlib.h Jeff Johnston
  0 siblings, 1 reply; 12+ messages in thread
From: Jon Beniston @ 2016-12-10  0:05 UTC (permalink / raw)
  To: newlib; +Cc: 'Jeff Johnston'

Hi Jeff,

>  Is it possible to point to an empty directory to skirt the inhibit_libc check

No, as stdio.h needs to exist there ($target_header_dir gets set to --with_headers value)

if { { test x$host != x$target && test "x$with_sysroot" = x ; } ||
       test x$with_newlib = xyes ; } &&
     { test "x$with_headers" = xno || test ! -f "$target_header_dir/stdio.h"; } ; then
       inhibit_libc=true

And creating a dummy stdio.h doesn't work, as that then gets installed in sys-include and used.

> and use the target/include headers that you say are on the include path

For a clean build, these only exist after newlib is built and installed though. Does that mean GCC needs to be built twice?

Thanks,
Jon

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

* Re: sys-include/newlib.h
  2016-12-09 20:47   ` sys-include/newlib.h Jon Beniston
  2016-12-09 21:18     ` sys-include/newlib.h Jeff Johnston
@ 2016-12-12 11:03     ` Sebastian Huber
  2016-12-12 11:30       ` sys-include/newlib.h Jon Beniston
  1 sibling, 1 reply; 12+ messages in thread
From: Sebastian Huber @ 2016-12-12 11:03 UTC (permalink / raw)
  To: Jon Beniston, newlib; +Cc: 'Jeff Johnston'

On 09/12/16 21:47, Jon Beniston wrote:
> Hi Jeff,
>
>> >What you are trying is unsupported.  Newlib configuration needs to run.
>> >Have you tried --with-newlib?  You might need to add a
>> >configure-target-newlib or all-target-newlib target to your configure call.
> I'm not sure what you mean by newlib configuration needs to run. I thought it was, and that's what is generating target/include/newlib.h (which has the correct values generate by configure).
>
> Yes, I'm using --with-newlib. This is with newlib & gcc source trees merged, so they configure and build together.

Did you place a link to the Newlib sources into your GCC source tree, e.g.

newlib -> ../newlib-git/newlib

? You need link to the newlib subdirectory inside the Newlib source tree.

-- 
Sebastian Huber, embedded brains GmbH

Address : Dornierstr. 4, D-82178 Puchheim, Germany
Phone   : +49 89 189 47 41-16
Fax     : +49 89 189 47 41-09
E-Mail  : sebastian.huber@embedded-brains.de
PGP     : Public key available on request.

Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.

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

* RE: sys-include/newlib.h
  2016-12-12 11:03     ` sys-include/newlib.h Sebastian Huber
@ 2016-12-12 11:30       ` Jon Beniston
  2016-12-12 11:33         ` sys-include/newlib.h Sebastian Huber
  0 siblings, 1 reply; 12+ messages in thread
From: Jon Beniston @ 2016-12-12 11:30 UTC (permalink / raw)
  To: 'Sebastian Huber', newlib; +Cc: 'Jeff Johnston'

Hi Sebastian,

>Did you place a link to the Newlib sources into your GCC source tree, e.g.
>
>newlib -> ../newlib-git/newlib

Yes. Newlib builds and configures ok. The problem seems to be that the full libgcc needs newlib to already be configured / installed.

Regards,
Jon


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

* Re: sys-include/newlib.h
  2016-12-12 11:30       ` sys-include/newlib.h Jon Beniston
@ 2016-12-12 11:33         ` Sebastian Huber
  2016-12-12 11:47           ` sys-include/newlib.h Jon Beniston
  0 siblings, 1 reply; 12+ messages in thread
From: Sebastian Huber @ 2016-12-12 11:33 UTC (permalink / raw)
  To: Jon Beniston, newlib; +Cc: 'Jeff Johnston'



On 12/12/16 12:30, Jon Beniston wrote:
> Hi Sebastian,
>
>> Did you place a link to the Newlib sources into your GCC source tree, e.g.
>>
>> newlib -> ../newlib-git/newlib
> Yes. Newlib builds and configures ok. The problem seems to be that the full libgcc needs newlib to already be configured / installed.

In your original mail you mention a C++ problem. Which libgcc file needs 
something from Newlib?

-- 
Sebastian Huber, embedded brains GmbH

Address : Dornierstr. 4, D-82178 Puchheim, Germany
Phone   : +49 89 189 47 41-16
Fax     : +49 89 189 47 41-09
E-Mail  : sebastian.huber@embedded-brains.de
PGP     : Public key available on request.

Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.

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

* RE: sys-include/newlib.h
  2016-12-12 11:33         ` sys-include/newlib.h Sebastian Huber
@ 2016-12-12 11:47           ` Jon Beniston
  2016-12-12 12:21             ` sys-include/newlib.h Sebastian Huber
  0 siblings, 1 reply; 12+ messages in thread
From: Jon Beniston @ 2016-12-12 11:47 UTC (permalink / raw)
  To: 'Sebastian Huber', newlib; +Cc: 'Jeff Johnston'

Hi Sebastian,

> In your original mail you mention a C++ problem. Which libgcc file needs something from Newlib?

When configuring gcc, the variable inhibit_libc in gcc/Makefile will be set to true, unless either --with-headers is used to point to newlib/libc/include or target headers are already installed (i.e. newlib has already been configured, built and installed).

inhibit_libc affects how various functions in libgcc/libgcc2.c, libgcc/libgcov and libgcc/unwing-sjlj.c are built.

The problem with using --with-headers, is that newlib/libc/include/newlib.h is empty (i.e. it's not the version generated by configure) and the root configure scripts copies this to target/sys-include. So if you then try to compile C++ code later on, you end up with this empty version of newlib.h being used, instead of the configure generated version in target/include - and this means some required #defines are missing and consequentially prototypes needed from newlib by cstdlib are missing.

Regards,
Jon


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

* Re: sys-include/newlib.h
  2016-12-12 11:47           ` sys-include/newlib.h Jon Beniston
@ 2016-12-12 12:21             ` Sebastian Huber
  0 siblings, 0 replies; 12+ messages in thread
From: Sebastian Huber @ 2016-12-12 12:21 UTC (permalink / raw)
  To: Jon Beniston, newlib; +Cc: 'Jeff Johnston'

On 12/12/16 12:47, Jon Beniston wrote:
> Hi Sebastian,
>
>> >In your original mail you mention a C++ problem. Which libgcc file needs something from Newlib?
> When configuring gcc, the variable inhibit_libc in gcc/Makefile will be set to true, unless either --with-headers is used to point to newlib/libc/include or target headers are already installed (i.e. newlib has already been configured, built and installed).
>
> inhibit_libc affects how various functions in libgcc/libgcc2.c, libgcc/libgcov and libgcc/unwing-sjlj.c are built.
>
> The problem with using --with-headers, is that newlib/libc/include/newlib.h is empty (i.e. it's not the version generated by configure) and the root configure scripts copies this to target/sys-include. So if you then try to compile C++ code later on, you end up with this empty version of newlib.h being used, instead of the configure generated version in target/include - and this means some required #defines are missing and consequentially prototypes needed from newlib by cstdlib are missing.

Thanks for your explanation. Looks like a tough problem.

-- 
Sebastian Huber, embedded brains GmbH

Address : Dornierstr. 4, D-82178 Puchheim, Germany
Phone   : +49 89 189 47 41-16
Fax     : +49 89 189 47 41-09
E-Mail  : sebastian.huber@embedded-brains.de
PGP     : Public key available on request.

Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.

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

* Re: sys-include/newlib.h
  2016-12-10  0:05       ` sys-include/newlib.h Jon Beniston
@ 2016-12-12 18:54         ` Jeff Johnston
  2018-12-13 12:16           ` sys-include/newlib.h jon
  0 siblings, 1 reply; 12+ messages in thread
From: Jeff Johnston @ 2016-12-12 18:54 UTC (permalink / raw)
  To: Jon Beniston; +Cc: newlib



----- Original Message -----
> Hi Jeff,
> 
> >  Is it possible to point to an empty directory to skirt the inhibit_libc
> >  check
> 
> No, as stdio.h needs to exist there ($target_header_dir gets set to
> --with_headers value)
> 
> if { { test x$host != x$target && test "x$with_sysroot" = x ; } ||
>        test x$with_newlib = xyes ; } &&
>      { test "x$with_headers" = xno || test ! -f "$target_header_dir/stdio.h";
>      } ; then
>        inhibit_libc=true
> 
> And creating a dummy stdio.h doesn't work, as that then gets installed in
> sys-include and used.
> 
> > and use the target/include headers that you say are on the include path
> 
> For a clean build, these only exist after newlib is built and installed
> though. Does that mean GCC needs to be built twice?
> 

What you want to do isn't currently supported in a single configure/build.  If you can't
override flags for the gcc build, you will have to do more than one build.  Otherwise,
if you can override flags, you could try a configure-target-newlib, change into newlib
directory and do a make stmp-targ-include, then add the flags
to the all-gcc make call to point to the newlib target includes.

-- Jeff J.

> Thanks,
> Jon
> 
> 

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

* RE: sys-include/newlib.h
  2016-12-12 18:54         ` sys-include/newlib.h Jeff Johnston
@ 2018-12-13 12:16           ` jon
  0 siblings, 0 replies; 12+ messages in thread
From: jon @ 2018-12-13 12:16 UTC (permalink / raw)
  To: newlib

 Hi Jeff,
 
>> >  Is it possible to point to an empty directory to skirt the 
>> > inhibit_libc  check
>> 
>> No, as stdio.h needs to exist there ($target_header_dir gets set to 
>> --with_headers value)
>> 
>> if { { test x$host != x$target && test "x$with_sysroot" = x ; } ||
>>        test x$with_newlib = xyes ; } &&
>>      { test "x$with_headers" = xno || test ! -f "$target_header_dir/stdio.h";
>>      } ; then
>>        inhibit_libc=true
>> 
> And creating a dummy stdio.h doesn't work, as that then gets installed 
> in sys-include and used.
> 
> > and use the target/include headers that you say are on the include 
> > path
>> 
>> For a clean build, these only exist after newlib is built and 
>> installed though. Does that mean GCC needs to be built twice?
>> 
>
>What you want to do isn't currently supported in a single configure/build.  

It seems that inhibt_libc still gets set even if I build gcc for a second time using --with-headers, because $target_header_dir/stdio.h does not exist, as $target_header_dir is target/sys-include, rather than target/include (and target/sys-include is only created if --with-headers=dir had been used for the first gcc build, but we can't do that because that creates a empty newlib.h file in there).

If for the second build of gcc, I pass --with-headers=/path/to/target/include instead of just --with-headers then inhibit_lib gets set to false as I want, but gcc/configure copies all of target/include to target/sys-include, which isn't ideal as I then have duplicate directories and any subsequent updates to target/include are hidden as target/sys-include is at the head of gcc's search path.

Deleting target/sys-include after it's built is a possibility, but seems a bit hacky. Should the test for ! -f "$target_header_dir/stdio.h" be changed/omitted instead? Is there a better procedure to build the libraries?

Cheers,
Jon



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

end of thread, other threads:[~2018-12-12 12:24 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-12-09 15:42 sys-include/newlib.h Jon Beniston
2016-12-09 19:07 ` sys-include/newlib.h Jeff Johnston
2016-12-09 20:47   ` sys-include/newlib.h Jon Beniston
2016-12-09 21:18     ` sys-include/newlib.h Jeff Johnston
2016-12-10  0:05       ` sys-include/newlib.h Jon Beniston
2016-12-12 18:54         ` sys-include/newlib.h Jeff Johnston
2018-12-13 12:16           ` sys-include/newlib.h jon
2016-12-12 11:03     ` sys-include/newlib.h Sebastian Huber
2016-12-12 11:30       ` sys-include/newlib.h Jon Beniston
2016-12-12 11:33         ` sys-include/newlib.h Sebastian Huber
2016-12-12 11:47           ` sys-include/newlib.h Jon Beniston
2016-12-12 12:21             ` sys-include/newlib.h Sebastian Huber

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