Re: [PATCH] libstdc++-v3: Have aligned_alloc() on Newlib

Szabolcs Nagy <[email protected]>
Newsgroups gmane.comp.lib.newlib,gmane.comp.gcc.patches,gmane.comp.gcc.libstdc++.devel
Message-ID <[email protected]>
On 09/08/18 10:08, Jonathan Wakely wrote:
> On 09/08/18 06:56 +0200, Sebastian Huber wrote:
>> On 08/08/18 16:33, Jonathan Wakely wrote:
>>> On 08/08/18 16:22 +0200, Ulrich Weigand wrote:
>>>> Jonathan Wakely wrote:
>>>>
>>>>> Aha, so newlib was using memalign previously:
>>>>>
>>>>> @@ -53,20 +54,24 @@ aligned_alloc (std::size_t al, std::size_t sz)
>>>>>  #else
>>>>>  extern "C" void *memalign(std::size_t boundary, std::size_t size);
>>>>>  #endif
>>>>> -#define aligned_alloc memalign
>>>>
>>>> Yes, exactly ... this commit introduced the regression.
>>>>
>>>>> OK, I've regressed the branches then - I'll fix that.
>>>
>>> This should fix it. I'll finish testing and commit it.
>>>
>>> Sebastian, your patch to define HAVE_ALIGNED_ALLOC is OK for
>>> gcc-7-branch and gcc-8-branch, because changing newlib from using
>>> memalign to aligned_alloc is safe.
>>
>> Should I check in my patch in addition to your patch?
> 
> Yes please, on trunk and 7 and 8. It's better to use the standard
> aligned_alloc if available.
> 

but the newlib aligned_alloc is broken on baremetal targets,
it is implemented using posix_memalign which is not provided
by the newlib malloc implementation (except on cygwin)

in libstdc++ test log i see

spawn /B/gcc/xg++ -shared-libgcc -B/B/gcc -nostdinc++ -L/B/aarch64-none-elf/libstdc++-v3/src -L/B/aarch64-none-elf/libstdc++-v3/src/.libs 
-L/B/aarch64-none-elf/libstdc++-v3/libsupc++/.libs -B/P/aarch64-none-elf/bin/ -B/P/aarch64-none-elf/lib/ -isystem /P/aarch64-none-elf/include 
-isystem /P/aarch64-none-elf/sys-include -B/B/aarch64-none-elf/./libstdc++-v3/src/.libs -fmessage-length=0 -fno-show-column -ffunction-sections 
-fdata-sections -g -ffunction-sections -fdata-sections -O2 -DLOCALEDIR="." -nostdinc++ 
-I/B/aarch64-none-elf/libstdc++-v3/include/aarch64-none-elf -I/B/aarch64-none-elf/libstdc++-v3/include -I/S/gcc/libstdc++-v3/libsupc++ 
-I/S/gcc/libstdc++-v3/include/backward -I/S/gcc/libstdc++-v3/testsuite/util 
/S/gcc/libstdc++-v3/testsuite/18_support/aligned_alloc/aligned_alloc.cc -std=gnu++17 -fno-diagnostics-show-caret -fdiagnostics-color=never 
./libtestc++.a -L/B/aarch64-none-elf/libstdc++-v3/src/filesystem/.libs -specs=aem-ve.specs -lm -mcmodel=small -o ./aligned_alloc.exe
/P/aarch64-none-elf/bin/ld: /P/aarch64-none-elf/lib/libg.a(lib_a-aligned_alloc.o): in function `aligned_alloc':
/S/newlib-cygwin/newlib/libc/stdlib/aligned_alloc.c:35: undefined reference to `posix_memalign'
/P/aarch64-none-elf/bin/ld: /S/newlib-cygwin/newlib/libc/stdlib/aligned_alloc.c:35:(.text.aligned_alloc+0x14): relocation truncated to fit: 
R_AARCH64_CALL26 against undefined symbol `posix_memalign'
collect2: error: ld returned 1 exit status


FAIL: 18_support/aligned_alloc/aligned_alloc.cc (test for excess errors)
FAIL: 18_support/new_aligned.cc (test for excess errors)
FAIL: 20_util/allocator/overaligned.cc (test for excess errors)
FAIL: 20_util/memory_resource/2.cc (test for excess errors)
FAIL: 20_util/monotonic_buffer_resource/allocate.cc (test for excess errors)
FAIL: 20_util/monotonic_buffer_resource/deallocate.cc (test for excess errors)
FAIL: 20_util/monotonic_buffer_resource/release.cc (test for excess errors)
FAIL: 20_util/monotonic_buffer_resource/upstream_resource.cc (test for excess errors)
FAIL: 20_util/polymorphic_allocator/resource.cc (test for excess errors)
FAIL: 20_util/polymorphic_allocator/select.cc (test for excess errors)
FAIL: ext/bitmap_allocator/overaligned.cc (test for excess errors)
FAIL: ext/mt_allocator/overaligned.cc (test for excess errors)
FAIL: ext/new_allocator/overaligned.cc (test for excess errors)
FAIL: ext/pool_allocator/overaligned.cc (test for excess errors)
FAIL: g++.dg/cpp1z/aligned-new1.C   (test for excess errors)
FAIL: g++.dg/cpp1z/aligned-new2.C   (test for excess errors)
FAIL: g++.dg/cpp1z/aligned-new5.C  -std=gnu++11 (test for excess errors)
FAIL: g++.dg/cpp1z/aligned-new5.C  -std=gnu++14 (test for excess errors)
FAIL: g++.dg/cpp1z/aligned-new5.C  -std=gnu++98 (test for excess errors)
FAIL: g++.dg/cpp1z/aligned-new6.C  -std=gnu++11 (test for excess errors)
FAIL: g++.dg/cpp1z/aligned-new6.C  -std=gnu++14 (test for excess errors)
FAIL: g++.dg/cpp1z/aligned-new8.C   (test for excess errors)
UNRESOLVED: 18_support/aligned_alloc/aligned_alloc.cc compilation failed to produce executable
UNRESOLVED: 18_support/new_aligned.cc compilation failed to produce executable
UNRESOLVED: 20_util/allocator/overaligned.cc compilation failed to produce executable
UNRESOLVED: 20_util/memory_resource/2.cc compilation failed to produce executable
UNRESOLVED: 20_util/monotonic_buffer_resource/allocate.cc compilation failed to produce executable
UNRESOLVED: 20_util/monotonic_buffer_resource/deallocate.cc compilation failed to produce executable
UNRESOLVED: 20_util/monotonic_buffer_resource/release.cc compilation failed to produce executable
UNRESOLVED: 20_util/monotonic_buffer_resource/upstream_resource.cc compilation failed to produce executable
UNRESOLVED: 20_util/polymorphic_allocator/resource.cc compilation failed to produce executable
UNRESOLVED: 20_util/polymorphic_allocator/select.cc compilation failed to produce executable
UNRESOLVED: ext/bitmap_allocator/overaligned.cc compilation failed to produce executable
UNRESOLVED: ext/mt_allocator/overaligned.cc compilation failed to produce executable
UNRESOLVED: ext/new_allocator/overaligned.cc compilation failed to produce executable
UNRESOLVED: ext/pool_allocator/overaligned.cc compilation failed to produce executable
UNRESOLVED: g++.dg/cpp1z/aligned-new1.C   compilation failed to produce executable
UNRESOLVED: g++.dg/cpp1z/aligned-new2.C   compilation failed to produce executable
UNRESOLVED: g++.dg/cpp1z/aligned-new5.C  -std=gnu++11 compilation failed to produce executable
UNRESOLVED: g++.dg/cpp1z/aligned-new5.C  -std=gnu++14 compilation failed to produce executable
UNRESOLVED: g++.dg/cpp1z/aligned-new5.C  -std=gnu++98 compilation failed to produce executable
UNRESOLVED: g++.dg/cpp1z/aligned-new6.C  -std=gnu++11 compilation failed to produce executable
UNRESOLVED: g++.dg/cpp1z/aligned-new6.C  -std=gnu++14 compilation failed to produce executable
UNRESOLVED: g++.dg/cpp1z/aligned-new8.C   compilation failed to produce executable
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.