From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id 50265385802B for ; Thu, 25 Mar 2021 18:27:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 50265385802B Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-425-4EpTIGR9NHiFIQc6oOHS_A-1; Thu, 25 Mar 2021 14:27:11 -0400 X-MC-Unique: 4EpTIGR9NHiFIQc6oOHS_A-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6DF301005D4E; Thu, 25 Mar 2021 18:27:10 +0000 (UTC) Received: from localhost (unknown [10.33.36.164]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0AF2C60939; Thu, 25 Mar 2021 18:27:09 +0000 (UTC) Date: Thu, 25 Mar 2021 18:27:09 +0000 From: Jonathan Wakely To: Vladimir V Cc: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: Re: Problem building libstdc++ for the avr target Message-ID: <20210325182709.GU3008@redhat.com> References: <20210108182111.GE9471@redhat.com> <20210208174539.GN3008@redhat.com> <20210208174707.GO3008@redhat.com> <20210209104756.GW3008@redhat.com> <20210325123603.GN3008@redhat.com> MIME-Version: 1.0 In-Reply-To: <20210325123603.GN3008@redhat.com> X-Clacks-Overhead: GNU Terry Pratchett X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: multipart/mixed; boundary="qZLIv6EoKi7YuaSc" Content-Disposition: inline X-Spam-Status: No, score=-14.0 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libstdc++@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++ mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 25 Mar 2021 18:27:17 -0000 --qZLIv6EoKi7YuaSc Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline 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. --qZLIv6EoKi7YuaSc Content-Type: text/x-patch; charset=us-ascii Content-Disposition: attachment; filename="patch.txt" commit 15d649f79d6b6dc336f6a32eec242b652a262a82 Author: Jonathan Wakely 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 --qZLIv6EoKi7YuaSc--