[PATCH] D31413: [libc++] Use __attribute__((init_priority(101))) to ensure streams get initialized early

Hal Finkel via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 11 04:21:42 PDT 2017


hfinkel added a comment.

In https://reviews.llvm.org/D31413#712013, @aaron.ballman wrote:

> I'm not certain of a good way to test it, but I have a question about the value you picked for `init_priority`. My understanding of the values starting from 101 is that 1-100 are reserved for implementation use. Is that understanding correct? If so, you may want to pick a value below 100 to ensure there's not an arms race with the user. I believe this may require some alteration to SemaDeclAttr.cpp to not diagnose when this is coming from a system header. Otherwise, what's to stop the user from having something marked `constructor(101)` that attempts to use a stream, but can't because they're not initialized yet?


I agree; using 100 probably makes sense here. By spec, that's before any regular user code might execute.

Regarding testing, it is easy to test this (i.e. use cout/cerr/etc. from a constructor of a global object) if you link with libc++.a. Maybe just add a simple test and then we can see about setting up a buildbot which builds/tests a static libc++?


https://reviews.llvm.org/D31413





More information about the cfe-commits mailing list