Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 493648 - sys-libs/newlib-2.0.0 - non-assembly memset broken with -O3
Summary: sys-libs/newlib-2.0.0 - non-assembly memset broken with -O3
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Development (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Gentoo Toolchain Maintainers
URL: https://sourceware.org/ml/newlib/2013...
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-12-08 12:17 UTC by Alexander Holler
Modified: 2014-01-04 15:15 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
inhibit_loop_to_libcall.patch (inhibit_loop_to_libcall.patch,2.18 KB, patch)
2013-12-08 12:18 UTC, Alexander Holler
Details | Diff
inhibit_loop.patch (inhibit_loop.patch,39.27 KB, patch)
2013-12-10 12:24 UTC, Alexander Holler
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Alexander Holler 2013-12-08 12:17:51 UTC
The plain non-size-optimized C-version of memset is broken when compiled with -O3.

Unfortunately both is true when newlib will be compiled for ARM. The default there is -O3 and no optimized assembler version of memset will be used.

I've already notified upstream: http://sourceware.org/ml/newlib/2013/msg01059.html

I'm attaching a quick patch wich works only with gcc, to make it usuable with other compilers, someone will have to play with autofoo like here: http://sourceware.org/ml/libc-alpha/2013-06/msg00734.html

I wanted to do it myself, but eautorecof doesn't work for newlib.


Reproducible: Always
Comment 1 Alexander Holler 2013-12-08 12:18:45 UTC
Created attachment 364926 [details, diff]
inhibit_loop_to_libcall.patch

gcc-only patch to fix the problem.
Comment 2 Alexander Holler 2013-12-10 12:24:16 UTC
Created attachment 365044 [details, diff]
inhibit_loop.patch

Updated patch (including configure stuff) which should work with any compiler.
Tested on ARM Cortex-Mn.
Comment 3 Alexander Holler 2013-12-30 21:00:41 UTC
I've just checked newlib 2.1.0 which was released at 23-12-2013 and it contains the necessary patch for the memset problem (I've reported upstream too).

So just upgrading the version to 2.1.0 would fix this bug.

Up to now I haven't tested 2.1.0 myself, but I assume it will now work too with -O3 as the source looks like the attached patch.

I'm still not sure where newlib got the -O3 from (maybe it has taken it from my host CFLAGS, which indeed contains -O3), but I don't care much.

It might be a good idea to add a useflag to add --enable-target-optspace to the configure flags (or even enable that by default), as that option enables -Os. But I'm not sure about that, because I don't know where newlib is used besides my use case (ARM Cortex-Mn).
Comment 4 SpanKY gentoo-dev 2013-12-31 00:22:39 UTC
(In reply to Alexander Holler from comment #3)

2.1.0 is in the tree already

we don't create USE flags that just control optimization flags.  testing 2.1.0, i don't see -O3 being used.
Comment 5 Alexander Holler 2014-01-04 15:07:45 UTC
Very unusual but newlib uses the optimization level as found in the CFLAGS of the build machine (e.g. in /etc/portage/make.conf) to (cross-)compile the target libraries.

Therefor a useflag might make sense here.

Anyway, since it now works even if CFLAGS contains -O3 (just tested), it's ok.

Thanks for the version bump.
Comment 6 SpanKY gentoo-dev 2014-01-04 15:15:09 UTC
(In reply to Alexander Holler from comment #5)

this is a known TODO in crossdev (bug 420089).  a USE flag doesn't make sense.