[sword-devel] Segmentation fault - was Re: SWORD 1.7.0RC3

Jaak Ristioja jaak at ristioja.ee
Wed Sep 11 14:07:42 MST 2013


On 11.09.2013 22:35, DM Smith wrote:
> The C++ standard does specify order w/in a file (top down), but not
> across files.

Yeah, something like that. It is explained in detail in 3.6.2 of the C++
03 standard. I've attached a patch which fixes the issue for these
globals (and as a side effect might also get rid of three exported
symbols). I just put these objects into local scope to ensure that they
get (dynamically) initialized on use.

Blessings,
Jaak

On 11.09.2013 22:35, DM Smith wrote:
> The C++ standard does specify order w/in a file (top down), but not
> across files. This fact can be used to order across files by using a
> global from one to initialize a global another. Don't recommend it, but
> it is nice when it is a must.
> 
> -- DM
> 
> On Sep 11, 2013, at 12:56 PM, "Troy A. Griffitts" <scribe at crosswire.org
> <mailto:scribe at crosswire.org>> wrote:
> 
>> Jaak, I disagree that your comments have anything to do with this
>> problem. I have confirmed that the 3 file globals immediately
>> preceding the problem global have been initialized. I doubt you are
>> saying the c++ standard doesn't support initializing a global array
>> and then initializing a global std::list with the members of this
>> array, all in the same object file. I know the spec doesn't assure
>> global initialization order across object files, but within the same
>> object file, I find it hard to believe there is no specification to
>> the order.
>>
>> Jaak Ristioja <jaak at ristioja.ee <mailto:jaak at ristioja.ee>> wrote:
>>
> It's not a compiler bug.
> 
> Basically the C++ standard does not enforce an initialization order
> for globals. So the compiler is free to initialize such stuff in any
> order. I think your toolchain just happens to be lucky enough to do
> that in an the order which doesn't yield in a crash.
> 
> I don't have the time to look this up in the C++ standards myself, but
> you can google such stuff:
> 
> http://stackoverflow.com/questions/3746238/c-global-initialization-order-ignores-dependencies
> 
> 
> Blessings,
> Jaak
> 
> On 10.09.2013 18:12, Troy A. Griffitts wrote:
> 
>     Hey Jaak,
> 
>     Thank, yeah, but why? :)
> 
>     My investigation turns up:
> 
>     shared build works fine and valgrinds clean static build on g++
>     (GCC) 4.8.1 (F19) fails static build on g++ (GCC) 4.4.7 (RHEL 6.4)
>     works fine and valgrinds clean
> 
>     In the error case, it seems that std::list's c-tor(iterator
>     start,
>     iterator end) doesn't get called appropriately, though all the
>     other file globals get initialized just fine.
> 
>     I moved the global filter in the utility to a stack variable and
>     it alleviates the problem, but still wonder why the problem in the
>     first place.
> 
>     Any advice would be appreciated. If I'm doing something wrong, I'd
>     like to change it, but right now I'm going with "compiler bug" :)
> 
>     Troy
> 
> 
> 
> 
> 
>     On 09/10/2013 08:20 AM, Jaak Ristioja wrote: I'm pretty sure that
>     the crash is because the global
> 
>     const StringList oValues(&choices[0], &choices[2]);
> 
>     in ../src/modules/filters/utf8greekaccents.cpp:41 is not
>     initialized when it is used in
>     UTF8GreekAccents::UTF8GreekAccents()
>     to initialize the global
> 
>     UTF8GreekAccents greekAccentsFilter;
> 
>     instance in imp2gbs.cpp:62.
> 
> 
>     Blessings, Jaak
> 
>     On 10.09.2013 02:02, Peter von Kaehne wrote:
> 
>                 I hate to bring this up, now, when we really all
>                 want 1.7
>                 out, but current svn head produces a segmentation
>                 fault in
>                 imp2gbs. The other utilities insofar as I tested
>                 them seem to
>                 be fine.
> 
>                 Below the stacktrace. Tell me if you need more. I
>                 basically
>                 use usrinst.sh <http://usrinst.sh/> produced
>                 binaries, with the only modification
>                 that I changed the install directory to /usr/local/bin
> 
> 
> 
>                 peter at peter-ThinkPad-Twist:~/Source/sword$ gdb
>                 /usr/local/bin/imp2gbs GNU gdb (GDB) 7.5-ubuntu
>                 Copyright (C)
>                 2012 Free Software Foundation, Inc. License
>                 GPLv3+: GNU GPL
>                 version 3 or later
>                 <http://gnu.org/licenses/gpl.html> This is
>                 free software: you are free to change and
>                 redistribute it.
>                 There is NO WARRANTY, to the extent permitted by
>                 law. Type
>                 "show copying" and "show warranty" for details.
>                 This GDB was
>                 configured as "i686-linux-gnu". For bug reporting
>                 instructions, please see:
>                 <http://www.gnu.org/software/gdb/bugs/>... Reading
>                 symbols
>                 from /usr/local/bin/imp2gbs...done. (gdb) r Starting
>                 program: /usr/local/bin/imp2gbs
> 
>                 Program received signal SIGSEGV, Segmentation fault.
>                 0x08050b7a in sword::SWBuf::c_str (this=0x8) at
>                 ../include/swbuf.h:141 141 inline const char
>                 *c_str() const{
>                 return buf; } (gdb) bt #0 0x08050b7a in
>                 sword::SWBuf::c_str
>                 (this=0x8) at ../include/swbuf.h:141 #1 0x0805a790 in
>                 sword::SWOptionFilter::setOptionValue (this=0x8115b60
>                 <greekAccentsFilter>, ival=0x80c715b "On") at
>                 ../src/modules/filters/swoptfilter.cpp:51 #2
>                 0x0805aca2 in
>                 sword::UTF8GreekAccents::UTF8GreekAccents
>                 (this=0x8115b60
>                 <greekAccentsFilter>, __in_chrg=<optimised out>,
>                 __vtt_parm=<optimised out>) at
>                 ../src/modules/filters/utf8greekaccents.cpp:43 #3
>                 0x0805099d
>                 in __static_initialization_and_destruction_0
>                 (__initialize_p=1, __priority=65535) at
>                 imp2gbs.cpp:62 #4
>                 0x080509df in _GLOBAL__sub_I_imp2gbs.cpp(void) () at
>                 imp2gbs.cpp:273 #5 0x080c6ae2 in __libc_csu_init () #6
>                 0xb77f046a in __libc_start_main () from
>                 /lib/i386-linux-gnu/libc.so <http://libc.so/>.6 #7
>                 0x0804f931 in _start ()
>                 (gdb) #0 0x08050b7a in sword::SWBuf::c_str
>                 (this=0x8) at
>                 ../include/swbuf.h:141 #1 0x0805a790 in
>                 sword::SWOptionFilter::setOptionValue (this=0x8115b60
>                 <greekAccentsFilter>, ival=0x80c715b "On") at
>                 ../src/modules/filters/swoptfilter.cpp:51 #2
>                 0x0805aca2 in
>                 sword::UTF8GreekAccents::UTF8GreekAccents
>                 (this=0x8115b60
>                 <greekAccentsFilter>, __in_chrg=<optimised out>,
>                 __vtt_parm=<optimised out>) at
>                 ../src/modules/filters/utf8greekaccents.cpp:43 #3
>                 0x0805099d
>                 in __static_initialization_and_destruction_0
>                 (__initialize_p=1, __priority=65535) at
>                 imp2gbs.cpp:62 #4
>                 0x080509df in _GLOBAL__sub_I_imp2gbs.cpp(void) () at
>                 imp2gbs.cpp:273 #5 0x080c6ae2 in __libc_csu_init () #6
>                 0xb77f046a in __libc_start_main () from
>                 /lib/i386-linux-gnu/libc.so <http://libc.so/>.6 #7
>                 0x0804f931 in _start ()
>                 (gdb) #0 0x08050b7a in sword::SWBuf::c_str
>                 (this=0x8) at
>                 ../include/swbuf.h:141 #1 0x0805a790 in
>                 sword::SWOptionFilter::setOptionValue (this=0x8115b60
>                 <greekAccentsFilter>, ival=0x80c715b "On") at
>                 ../src/modules/filters/swoptfilter.cpp:51 #2
>                 0x0805aca2 in
>                 sword::UTF8GreekAccents::UTF8GreekAccents
>                 (this=0x8115b60
>                 <greekAccentsFilter>, __in_chrg=<optimised out>,
>                 __vtt_parm=<optimised out>) at
>                 ../src/modules/filters/utf8greekaccents.cpp:43 #3
>                 0x0805099d
>                 in __static_initialization_and_destruction_0
>                 (__initialize_p=1, __priority=65535) at
>                 imp2gbs.cpp:62 #4
>                 0x080509df in _GLOBAL__sub_I_imp2gbs.cpp(void) () at
>                 imp2gbs.cpp:273 #5 0x080c6ae2 in __libc_csu_init () #6
>                 0xb77f046a in __libc_start_main () from
>                 /lib/i386-linux-gnu/libc.so <http://libc.so/>.6 #7
>                 0x0804f931 in _start ()
>                 (gdb)
> 
> 
> 
>                 ------------------------------------------------------------------------
>                 sword-devel
>                 mailing list: sword-devel at crosswire.org
>                 <mailto:sword-devel at crosswire.org>
>                 http://www.crosswire.org/mailman/listinfo/sword-devel
>                 Instructions to unsubscribe/change your settings
>                 at above
>                 page
> 
> 
> 
>         ------------------------------------------------------------------------
>         sword-devel
>         mailing list: sword-devel at crosswire.org
>         <mailto:sword-devel at crosswire.org>
>         http://www.crosswire.org/mailman/listinfo/sword-devel
>         Instructions to unsubscribe/change your settings at above page
> 
> 
> 
>     ------------------------------------------------------------------------
>     sword-devel mailing
>     list: sword-devel at crosswire.org
>     <mailto:sword-devel at crosswire.org>
>     http://www.crosswire.org/mailman/listinfo/sword-devel Instructions
>     to unsubscribe/change your settings at above page
> 
> 
>>
>>     ------------------------------------------------------------------------
>>
>>     sword-devel mailing list: sword-devel at crosswire.org <mailto:sword-devel at crosswire.org>
>>     http://www.crosswire.org/mailman/listinfo/sword-devel
>>     Instructions to unsubscribe/change your settings at above page
>>
>>
>> -- 
>> Sent from my Android device with K-9 Mail. Please excuse my brevity.
>> _______________________________________________
>> sword-devel mailing list: sword-devel at crosswire.org
>> <mailto:sword-devel at crosswire.org>
>> http://www.crosswire.org/mailman/listinfo/sword-devel
>> Instructions to unsubscribe/change your settings at above page
> 
> 
> 
> _______________________________________________
> sword-devel mailing list: sword-devel at crosswire.org
> http://www.crosswire.org/mailman/listinfo/sword-devel
> Instructions to unsubscribe/change your settings at above page
> 

-------------- next part --------------
diff --git a/src/modules/filters/utf8greekaccents.cpp b/src/modules/filters/utf8greekaccents.cpp
index 201418e..6133003 100644
--- a/src/modules/filters/utf8greekaccents.cpp
+++ b/src/modules/filters/utf8greekaccents.cpp
@@ -33,13 +33,20 @@ sword::UTF8NFKD decompose;
 
 SWORD_NAMESPACE_START
 
+namespace {
+
 const char oName[] = "Greek Accents";
 const char oTip[] = "Toggles Greek Accents";
 
-const SWBuf choices[3] = {"On", "Off", ""};
-const StringList oValues(&choices[0], &choices[2]);
+const StringList & optionValues() {
+	static const SWBuf choices[3] = {"On", "Off", ""};
+	static const StringList oValues(&choices[0], &choices[2]);
+	return oValues;
+}
+
+} // anonymous namespace
 
-UTF8GreekAccents::UTF8GreekAccents() : SWOptionFilter(oName, oTip, &oValues) {
+UTF8GreekAccents::UTF8GreekAccents() : SWOptionFilter(oName, oTip, &optionValues()) {
 	setOptionValue("On");
 }
 


More information about the sword-devel mailing list