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 [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id 8375B3846411 for ; Thu, 25 Mar 2021 12:36:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 8375B3846411 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-336-d_gVyWb4NAehTH97si26-g-1; Thu, 25 Mar 2021 08:36:06 -0400 X-MC-Unique: d_gVyWb4NAehTH97si26-g-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 9A3FF107ACCD; Thu, 25 Mar 2021 12:36:04 +0000 (UTC) Received: from localhost (unknown [10.33.36.164]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3AA2760861; Thu, 25 Mar 2021 12:36:04 +0000 (UTC) Date: Thu, 25 Mar 2021 12:36:03 +0000 From: Jonathan Wakely To: Vladimir V Cc: libstdc++@gcc.gnu.org Subject: Re: Problem building libstdc++ for the avr target Message-ID: <20210325123603.GN3008@redhat.com> References: <20210108182111.GE9471@redhat.com> <20210208174539.GN3008@redhat.com> <20210208174707.GO3008@redhat.com> <20210209104756.GW3008@redhat.com> MIME-Version: 1.0 In-Reply-To: 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: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline X-Spam-Status: No, score=-8.0 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, 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 12:36:09 -0000 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 # endif } #endif