From: Jonathan Wakely <jwakely@redhat.com>
To: Vladimir V <vv.os.swe@gmail.com>
Cc: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org
Subject: Re: Problem building libstdc++ for the avr target
Date: Thu, 25 Mar 2021 18:27:09 +0000 [thread overview]
Message-ID: <20210325182709.GU3008@redhat.com> (raw)
In-Reply-To: <20210325123603.GN3008@redhat.com>
[-- Attachment #1: Type: text/plain, Size: 1970 bytes --]
On 25/03/21 12:36 +0000, Jonathan Wakely wrote:
>On 25/03/21 10:27 +0100, Vladimir V wrote:
>>Hello.
>>
>>Recently I tried the 'freestanding' build of the libstdc++ for the avr to
>>verify that my fixes were sufficient for it as well.
>>Unfortunately, I encountered the following error:
>>../../../../libstdc++-v3/libsupc++/new_opa.cc: In function 'void*
>>__gnu_cxx::aligned_alloc(std::size_t, std::size_t)':
>>../../../../libstdc++-v3/libsupc++/new_opa.cc:97:28: error: 'malloc' was
>>not declared in this scope
>> 97 | void* const malloc_ptr = malloc(sz + al);
>>
>>My investigation showed that in the chain of includes the stdlib.h of the
>>avr-libc is not present.
>>It looks like includes are resolved in the following way (here are the
>>original paths as they are linked from out folders during build):
>>new_opa.cc -> libstdc++-v3/include/c_compatibility/stdlib.h ->
>>libstdc++-v3/include/c_global/cstdlib
>>In cstdlib, for non-hosted builds stdlib.h is not included.
>>
>>This problem is not present if the non-hosted build is done with
>>'with-newlib' flag instead of 'with-avrlibc' (common workaround as the
>>avrlibc build was fixed only recently).
>>Might it be that some include order depends on the target libc? Or maybe
>>some implicit conditions are involved?
>>
>>Could you please support me with this issue?
>
>I think this is needed:
>
>--- a/libstdc++-v3/libsupc++/new_opa.cc
>+++ b/libstdc++-v3/libsupc++/new_opa.cc
>@@ -54,6 +54,10 @@ extern "C"
> void *posix_memalign(void **, size_t alignment, size_t size);
> # elif _GLIBCXX_HAVE_MEMALIGN
> void *memalign(size_t alignment, size_t size);
>+#else
>+ // A freestanding C runtime may not provide "malloc" -- but there is no
>+ // other reasonable way to implement "operator new".
>+ void *malloc (std::size_t); with GCC 7.5
Oops, there was a stray "with GCC 7.5" that got into my clipboard
there!
I've pushed the attached patch, please test and confirm if it fixes
your problem.
[-- Attachment #2: patch.txt --]
[-- Type: text/x-patch, Size: 1093 bytes --]
commit 15d649f79d6b6dc336f6a32eec242b652a262a82
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Thu Mar 25 18:24:37 2021
libstdc++: Declare malloc for freestanding
For a target with none of aligned_alloc, memalign etc. we defined our
own aligned_alloc using malloc, so we need a declaration of malloc. As
in libsupc++/new_op.cc we need to declare it ourselves for freestanding
environments.
libstdc++-v3/ChangeLog:
* libsupc++/new_opa.cc [!_GLIBCXX_HOSTED]: Declare malloc.
diff --git a/libstdc++-v3/libsupc++/new_opa.cc b/libstdc++-v3/libsupc++/new_opa.cc
index 59296226e83..6b78729dc24 100644
--- a/libstdc++-v3/libsupc++/new_opa.cc
+++ b/libstdc++-v3/libsupc++/new_opa.cc
@@ -54,6 +54,10 @@ extern "C"
void *posix_memalign(void **, size_t alignment, size_t size);
# elif _GLIBCXX_HAVE_MEMALIGN
void *memalign(size_t alignment, size_t size);
+# else
+ // A freestanding C runtime may not provide "malloc" -- but there is no
+ // other reasonable way to implement "operator new".
+ void *malloc(size_t);
# endif
}
#endif
next prev parent reply other threads:[~2021-03-25 18:27 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-07 17:32 Vladimir V
2020-12-07 20:30 ` Jonathan Wakely
2020-12-07 20:32 ` Jonathan Wakely
2020-12-09 0:28 ` Vladimir V
2020-12-09 12:32 ` Vladimir V
2020-12-09 12:49 ` Jonathan Wakely
2020-12-09 17:01 ` Jonathan Wakely
2020-12-09 23:00 ` Vladimir V
2020-12-10 17:39 ` Vladimir V
2020-12-10 20:15 ` Jonathan Wakely
2020-12-10 20:31 ` Vladimir V
2020-12-15 11:48 ` Jonathan Wakely
2020-12-16 7:33 ` Vladimir V
2020-12-07 20:41 ` Keith Packard
2020-12-07 21:06 ` Jonathan Wakely
2021-01-04 11:28 ` Vladimir V
2021-01-08 18:21 ` Jonathan Wakely
2021-01-22 14:46 ` Vladimir V
2021-02-07 13:55 ` Vladimir V
2021-02-07 18:22 ` Vladimir V
2021-02-07 18:23 ` Keith Packard
2021-02-07 22:33 ` Vladimir V
2021-02-07 23:06 ` Keith Packard
2021-02-08 12:58 ` Vladimir V
2021-02-08 17:38 ` Jonathan Wakely
2021-02-08 17:45 ` Jonathan Wakely
2021-02-08 17:47 ` Jonathan Wakely
2021-02-08 22:25 ` Vladimir V
2021-02-09 10:47 ` Jonathan Wakely
2021-02-09 10:54 ` Vladimir V
2021-03-25 9:27 ` Vladimir V
2021-03-25 12:36 ` Jonathan Wakely
2021-03-25 18:27 ` Jonathan Wakely [this message]
2021-03-25 21:37 ` Vladimir V
2021-03-25 23:02 ` Jonathan Wakely
2021-03-26 8:25 ` Vladimir V
2020-12-07 21:51 ` Vladimir V
2020-12-07 23:00 ` Keith Packard
2020-12-08 8:12 ` Vladimir V
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=20210325182709.GU3008@redhat.com \
--to=jwakely@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=libstdc++@gcc.gnu.org \
--cc=vv.os.swe@gmail.com \
/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).