Re: Annoying global variables initialization order issue

2023-05-11 Thread Jean-Marc Lasgouttes

Le 11/05/2023 à 03:08, Richard Kimberly Heck a écrit :

On 5/10/23 13:00, Jean-Marc Lasgouttes wrote:

Hello,

Trying to run LyX under valgrind, I find many AVX2-related valgrind 
warnings (see attachment). It seems related to a change of variable 
initialization order by the compiler.


The following patch fixes the first warnings. The other ones will be a 
bit more complicated.


Not here. I do not understand that kind of stuff.


I do not see the valgrind output in ubuntu 20.04. I did not find any 
reference to this.


The fact is that the patch I sent makes more sense and makes the 
relevant errors go away.


Does anyone see the valgrind errors on a recent system?

JMarc

--
lyx-devel mailing list
lyx-devel@lists.lyx.org
http://lists.lyx.org/mailman/listinfo/lyx-devel


Re: Annoying global variables initialization order issue

2023-05-10 Thread Richard Kimberly Heck

On 5/10/23 13:00, Jean-Marc Lasgouttes wrote:

Hello,

Trying to run LyX under valgrind, I find many AVX2-related valgrind 
warnings (see attachment). It seems related to a change of variable 
initialization order by the compiler.


The following patch fixes the first warnings. The other ones will be a 
bit more complicated.


Not here. I do not understand that kind of stuff.

Riki


--
lyx-devel mailing list
lyx-devel@lists.lyx.org
http://lists.lyx.org/mailman/listinfo/lyx-devel


Annoying global variables initialization order issue

2023-05-10 Thread Jean-Marc Lasgouttes

Hello,

Trying to run LyX under valgrind, I find many AVX2-related valgrind 
warnings (see attachment). It seems related to a change of variable 
initialization order by the compiler.


The following patch fixes the first warnings. The other ones will be a 
bit more complicated.


Ideas?

JMarc
From 2e12216e3b8eeca2716da2cb90e676e8c82174ed Mon Sep 17 00:00:00 2001
From: Jean-Marc Lasgouttes 
Date: Wed, 10 May 2023 18:53:22 +0200
Subject: [PATCH] Fix weird initialization issue

Valgrind complains when launching LyX (see below).

It seems to be related to some initialization order of global static
variable. This patch fixes the easiest one, but several other exist
(e.g. for the lmanguages variable).

==8864== Invalid read of size 32
==8864==at 0x6113CDD: __wmemcmp_avx2_movbe (memcmp-avx2-movbe.S:415)
==8864==by 0x44A15E: compare (char_traits.h:512)
==8864==by 0x44A15E: compare (basic_string.h:3148)
==8864==by 0x44A15E: operator< , std::all
ocator > (basic_string.h:3694)
==8864==by 0x44A15E: operator() (stl_function.h:408)
==8864==by 0x44A15E: _M_get_insert_hint_unique_pos (stl_tree.h:2225)
==8864==by 0x44A15E: _M_emplace_hint_unique, std::allocator >&>, std::tuple<> > (stl_tree.h:2462)
==8864==by 0x44A15E: operator[] (stl_map.h:511)
==8864==by 0x44A15E: init_deco_table (MathSupport.cpp:536)
==8864==by 0x44A15E: __static_initialization_and_destruction_0 (MathSupport.cpp:541)
==8864==by 0x44A15E: _GLOBAL__sub_I_MathSupport.cpp (MathSupport.cpp:1120)
==8864==by 0x5FBEBBD: call_init (libc-start.c:145)
==8864==by 0x5FBEBBD: __libc_start_main@@GLIBC_2.34 (libc-start.c:347)
==8864==by 0x456784: (below main) (in /home/lasgoutt/src/lyx/profdbuild/src/lyx)
---
 src/mathed/MathSupport.cpp | 26 ++
 1 file changed, 6 insertions(+), 20 deletions(-)

diff --git a/src/mathed/MathSupport.cpp b/src/mathed/MathSupport.cpp
index 16019205f1..52e1e3cb30 100644
--- a/src/mathed/MathSupport.cpp
+++ b/src/mathed/MathSupport.cpp
@@ -522,28 +522,14 @@ named_deco_struct deco_table[] = {
 };
 
 
-map deco_list;
-
-// sort the table on startup
-class init_deco_table {
-public:
-	init_deco_table() {
-		unsigned const n = sizeof(deco_table) / sizeof(deco_table[0]);
-		for (named_deco_struct * p = deco_table; p != deco_table + n; ++p) {
-			deco_struct d;
-			d.data  = p->data;
-			d.angle = p->angle;
-			deco_list[from_ascii(p->name)] = d;
-		}
-	}
-};
-
-static init_deco_table dummy_deco_table;
-
-
 deco_struct const * search_deco(docstring const & name)
 {
-	map::const_iterator p = deco_list.find(name);
+	static map deco_list;
+	if (deco_list.empty()) {
+		for (auto const & ds : deco_table)
+			deco_list[from_ascii(ds.name)] = { ds.data, ds.angle };
+	}
+	auto p = deco_list.find(name);
 	return p == deco_list.end() ? 0 : &(p->second);
 }
 
-- 
2.39.2

==8864== Memcheck, a memory error detector
==8864== Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al.
==8864== Using Valgrind-3.19.0 and LibVEX; rerun with -h for copyright info
==8864== Command: src/lyx
==8864== 
==8864== Invalid read of size 32
==8864==at 0x6113CDD: __wmemcmp_avx2_movbe (memcmp-avx2-movbe.S:415)
==8864==by 0x44A15E: compare (char_traits.h:512)
==8864==by 0x44A15E: compare (basic_string.h:3148)
==8864==by 0x44A15E: operator< , 
std::allocator > (basic_string.h:3694)
==8864==by 0x44A15E: operator() (stl_function.h:408)
==8864==by 0x44A15E: _M_get_insert_hint_unique_pos (stl_tree.h:2225)
==8864==by 0x44A15E: _M_emplace_hint_unique, 
std::allocator >&>, std::tuple<> > (stl_tree.h:2462)
==8864==by 0x44A15E: operator[] (stl_map.h:511)
==8864==by 0x44A15E: init_deco_table (MathSupport.cpp:536)
==8864==by 0x44A15E: __static_initialization_and_destruction_0 
(MathSupport.cpp:541)
==8864==by 0x44A15E: _GLOBAL__sub_I_MathSupport.cpp (MathSupport.cpp:1120)
==8864==by 0x5FBEBBD: call_init (libc-start.c:145)
==8864==by 0x5FBEBBD: __libc_start_main@@GLIBC_2.34 (libc-start.c:347)
==8864==by 0x456784: (below main) (in 
/home/lasgoutt/src/lyx/profdbuild/src/lyx)
==8864==  Address 0x8e26d50 is 0 bytes inside a block of size 28 alloc'd
==8864==at 0x4843FA3: operator new(unsigned long) (in 
/usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==8864==by 0x44AD9D: _M_construct (basic_string.tcc:225)
==8864==by 0x44AD9D: basic_string (basic_string.h:544)
==8864==by 0x44AD9D: pair, std::allocator >&, 0> (tuple:1817)
==8864==by 0x44AD9D: pair, std::allocator >&> (tuple:1807)
==8864==by 0x44AD9D: construct, lyx::(anonymous namespace)::deco_struct>, 
const std::piecewise_construct_t&, std::tuple, 
std::allocator >&>, std::tuple<> > (new_allocator.h:175)
==8864==by 0x44AD9D: construct, lyx::(anonymous namespace)::deco_struct>, 
const std::piecewise_construct_t&, std::tuple, 
std::allocator >&>, std::tuple<> > (alloc_traits.h:516)
==8864==by 0x44AD9D: _M_construct_node, 
std::allocator >&>, std::tuple<> >