From: "Václav Zeman" <vhaisman@gmail.com>
To: gcc-help@gcc.gnu.org
Subject: Re: init_priority attribute and libstdc++
Date: Mon, 18 Aug 2014 19:04:00 -0000 [thread overview]
Message-ID: <53F24E4B.5030502@gmail.com> (raw)
In-Reply-To: <53F24D45.9090604@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 2691 bytes --]
On 18.8.2014 13:25, Jonathan Wakely wrote:
> I'm on my phone so can't send plain text mail to the list, or check the
> code, but I'm pretty sure the answer is 101
>
> Anything lower than that is reserved for the implementation so libstdc++
> would use that. Nothing in string or vector needs dynamic init anyway IIRC
Some paths of my library's initialization might try to print warnings or
errors. I have hit a SIGSEGV with the following test case, which uses
std::cerr:
~~~~
#include <iostream>
struct S1
{
S1() { std::cerr << __FUNCTION__ << "\n"; }
} static s1 __attribute__ ((__init_priority__ (65535/2)));
int
main ()
{
return 0;
}
~~~~
The stack trace is
~~~~
#0 0x00007ffff7b6a559 in std::ostream::sentry::sentry(std::ostream&) ()
from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#1 0x00007ffff7b6ac19 in std::basic_ostream<char,
std::char_traits<char> >& std::__ostream_insert<char,
std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char>
>&, char const*, long)
() from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#2 0x00007ffff7b6b077 in std::basic_ostream<char,
std::char_traits<char> >& std::operator<< <std::char_traits<char>
>(std::basic_ostream<char, std::char_traits<char> >&, char const*) ()
from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#3 0x000000000040081d in S1::S1 (this=0x601172 <s1>) at test.cxx:5
#4 0x00000000004007d6 in __static_initialization_and_destruction_0
(__initialize_p=1, __priority=32767) at test.cxx:6
#5 0x00000000004007eb in _GLOBAL__sub_I.32767_main(void) () at test.cxx:13
#6 0x000000000040087d in __libc_csu_init ()
#7 0x00007ffff7731e55 in __libc_start_main (main=0x40077d <main()>,
argc=1, argv=0x7fffffffe2c8, init=0x400830 <__libc_csu_init>,
fini=<optimized out>, rtld_fini=<optimized out>,
stack_end=0x7fffffffe2b8) at libc-start.c:246
#8 0x00000000004006b9 in _start ()
~~~~
Is this expected?
>
> On Aug 17, 2014 8:56 PM, "Václav Zeman" <vhaisman@gmail.com
> <mailto:vhaisman@gmail.com>> wrote:
>
> Hi.
>
> I want to use the init_priority(prio) attribute
> (https://gcc.gnu.org/onlinedocs/gcc/C_002b_002b-Attributes.html#C_002b_002b-Attributes)
> to initialize stuff in my library early so that users of the library can
> use the library during their own static objects construction. However,
> my library uses standard C++ library facilities like std::string,
> std::vector<>, etc. The question is:
>
> What is the lowest priority for init_priority attribute that I can use
> to still have libstdc++ initialize itself before my library is
> initialized?
--
VZ
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 230 bytes --]
next parent reply other threads:[~2014-08-18 19:04 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <53F24D45.9090604@gmail.com>
2014-08-18 19:04 ` Václav Zeman [this message]
2014-08-17 19:56 Václav Zeman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=53F24E4B.5030502@gmail.com \
--to=vhaisman@gmail.com \
--cc=gcc-help@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).