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

Aaron Ballman via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Thu Sep 17 06:12:45 PDT 2020


aaron.ballman added a comment.

In D31413#2277985 <https://reviews.llvm.org/D31413#2277985>, @ldionne wrote:

> In D31413#2277630 <https://reviews.llvm.org/D31413#2277630>, @smeenai wrote:
>
>> What was the conclusion for the comments about the priority level (100 vs. 101)?
>
> My understanding is that values below `101` are literally not allowed:
>
>   <...>/llvm/libcxx/src/iostream.cpp:80:66: error: 'init_priority' attribute requires integer constant between 101 and 65535 inclusive
>   _LIBCPP_HIDDEN ios_base::Init __start_std_streams __attribute__((init_priority(100)));
>                                                                    ^             ~~~
>   1 error generated.
>
> If there's a way around that, and if values below 101 are reserved for the implementation, then I agree `100` is what we should use. @aaron.ballman where did you read that values below 101 were reserved for the implementation?

>From GCC itself: https://godbolt.org/z/zajPsj but also from libstdc++ maintainers https://gcc.gnu.org/legacy-ml/gcc-help/2014-08/msg00117.html

> The GCC docs at https://gcc.gnu.org/onlinedocs/gcc/C_002b_002b-Attributes.html don't imply that -- they say the attribute starts at 101. I agree it's a fairly logical thing to think values before that would be reserved, but it doesn't say explicitly.
>
> Is it possible that GCC reserves values before 101 for the implementation, but Clang implemented the attribute "naively" and just errors out?

Yes, and the way I would handle this is to change the `init_priority` value checking to allow values <= 100 if the attribute location is within a system header. This would allow libc++ to use the reserved priority but would still give errors when attempted from user code.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D31413/new/

https://reviews.llvm.org/D31413



More information about the libcxx-commits mailing list