Changing thread_local to __thread in libFuzzer

Authored by george.karpenkov on Apr 20 2017, 2:53 PM.



Old apple compilers do not support thread_local keyword.
__thread is supported, and appears to have the same effect.

Diff Detail

kcc added a comment.Apr 20 2017, 2:55 PM

Yes, I don't like the change -- I really want to have portable modern C++ w/o any old stuff.
Can you do some cmake magic to add -Dthread_local=__thread for old compilers (and only for them)?

george.karpenkov edited the summary of this revision. (Show Details)

Detect whether thread_local is supported in CMake, and alternate between thread_local and __thread.
Files built using the built script would always have thread_local.

I understand that you would prefer not to have __thread at all, but I'm not sure whether it is possible, since thread_local is a keyword, not a define, and CMake operates by generating files which are later included by a compiler.

A system modifying the source code and replacing thread_local by __thread could be implemented, but I think it would cause far more trouble.

kcc added a comment.Apr 20 2017, 6:29 PM

That's even worse.
Why can't you add -Dthread_local=__thread to compiler flags if the compiler is old?

Indeed, you are right, my assumption was that keywords could not be changed by the preprocessor, yet surprisingly that works.

kcc accepted this revision.Apr 20 2017, 8:38 PM


This revision is now accepted and ready to land.Apr 20 2017, 8:38 PM
This revision was automatically updated to reflect the committed changes.