News for hackers. Stuff that matters.
Re:Why isn't memset() async-signal-safe? by Gibbon1 on Tuesday January 03, 2017 @06:29PM (#13314285)
Slightly terrifying is the optimizer may very well replace the following

    while(n--)
       *m++ = c;
With a call to the built in memset()
Re:Why isn't memset() async-signal-safe? by megous on Tuesday January 03, 2017 @06:55PM (#13314451)
It does a lot more replacements, depending on the architecture. Even a simple a/b or a%b will get replaced with function call on many archs.
Re:Why isn't memset() async-signal-safe? by Spivak on Tuesday January 03, 2017 @06:51PM (#13314431)
I'm fairly inexperienced on this matter. Can you give a real life example where this would be a bad thing?
Re:Why isn't memset() async-signal-safe? by Gibbon1 on Tuesday January 03, 2017 @07:53PM (#13314755)
Well there is this bug: 'memcpy implementation optimized as a call to memcpy'

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56888

The terrifying thing is while the programmer might know that memset() isn't async-signal-safe and not use it in a signal handler, the compiler may blissfully and silently optimize the code to use memset() anyways. Odd crashes or worse security leaks may result.

Reminds me a bit of old floating point implemented in software. Some implementations had global scratchpad registers. Very weird things happened if you did any floating point operations in multiple threads.

Re:Why isn't memset() async-signal-safe? by temac on Tuesday January 03, 2017 @06:57PM (#13314460)
If memset is actually not async signal safe on some target, and a compiler targetting the same does that transformation, the end results are very unsound...