[Solwed (32 bit vs 64 bit ) ] Re: wxString class crashes in shared lib

Do you have a typical platform dependent issue you're battling with ? Ask it here. Make sure you mention your platform, compiler, and wxWidgets version.
Post Reply
MasterAlexei
In need of some credit
In need of some credit
Posts: 5
Joined: Fri Jan 22, 2021 2:58 pm

[Solwed (32 bit vs 64 bit ) ] Re: wxString class crashes in shared lib

Post by MasterAlexei » Fri Jan 22, 2021 3:19 pm

Hello,
I try to cross compile the Windows project, that works since about 6 years with wxMSW 3.1.3 to the Linux wxGTK 3.1.3 and/or 3.0.0.
The Project consist from one shared lib and main app. the problem is, that first thing occurs in a lib is some wxString assignments.
And there is a segmentation fault occurs.

On the assignment :

ConfigData.Options.wsLANAddress = wxT("");

The gdb debugger shows the line (string.h line 1933):

m_impl = ImplStr(pwz);

I did installed the wxWidgets with apt-get. But with the self compiled version the same thing happens.
The compiler switches in the last case are the same as the switched for the lib and app, except that for the lib there is -fpic switch.

Can some one tel me, what did I missed with that shared libs, may be some Init of wxWidgets or some thing?

Thaks in Advance!
Last edited by MasterAlexei on Tue Jan 26, 2021 12:15 pm, edited 1 time in total.

User avatar
doublemax
Moderator
Moderator
Posts: 16014
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxString class crashes in shared lib

Post by doublemax » Fri Jan 22, 2021 4:04 pm

Code: Select all

ConfigData.Options.wsLANAddress = wxT("");
What's the context of this line, where and when is it called?
The gdb debugger shows the line (string.h line 1933):
m_impl = ImplStr(pwz);
Please show the complete call stack.
Use the source, Luke!

MasterAlexei
In need of some credit
In need of some credit
Posts: 5
Joined: Fri Jan 22, 2021 2:58 pm

Re: wxString class crashes in shared lib

Post by MasterAlexei » Fri Jan 22, 2021 4:36 pm

Here is the screenshot of Callstack:
CallStack.PNG
from 6 to 4 is my Main programm,
from 3 to 1 is my shared lib.
on the left is the place, where debugger is stopped.
Point 6 is an OnActivate event handler. Also the context of the line is a wxFrame::OnActivate handler.

Code: Select all

void DeviceETH::SetConfigFile( wxString cfgFN )
{
...
  m_config = new(std::nothrow) ComLibConfig( wxT(""), cfgFN );
  if( m_config )
  {
    m_config->Init( wxT(""), cfgFN );
    m_config->Load();			// <<<  here it is
    LOG(LOG_DEBUG, wxT("Config file set"));
  }
}

Code: Select all

bool ComLibConfig::Load()
{
...
...
  Open(); // Creates the Conf in a Heap
...
...
    Conf->SetPath("/");
...
...
      ConfigData.Options.wsLANAddress = wxT(""); // <<< here it is
Conf is a member variable of the base class of the ComLibConfig.
and is assigned in the Open() function:
Conf = new wxFileConfig( "", "", wsFileName, "", wxCONFIG_USE_LOCAL_FILE );

Hope I put everything needed here.

User avatar
doublemax
Moderator
Moderator
Posts: 16014
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxString class crashes in shared lib

Post by doublemax » Fri Jan 22, 2021 5:28 pm

I usually work under Windows only and i have hard time interpreting the debugger output. The two pointer addresses look ok to me, so i'm not sure why or where exactly it crashes.

Do you link wxWidgets itself as a shared library (you should)?
Does your shared lib also link to wxWidgets?

Does it make any difference if you change wxT("") to "" ?
Use the source, Luke!

MasterAlexei
In need of some credit
In need of some credit
Posts: 5
Joined: Fri Jan 22, 2021 2:58 pm

Re: wxString class crashes in shared lib

Post by MasterAlexei » Fri Jan 22, 2021 5:47 pm

doublemax wrote:
Fri Jan 22, 2021 5:28 pm
I usually work under Windows only and i have hard time interpreting the debugger output. The two pointer addresses look ok to me, so i'm not sure why or where exactly it crashes.
For me too. I think that there is something not intialised in wxWidgets itself in the library context.
Difference with the windows is that in linux libs there is no main, where the initialisation may be done. There are just functions there. As I know it. May be I am wrong here, but on Raspi debian the same portion of code works without any problems. And now it is an ubuntu 18.04
doublemax wrote:
Fri Jan 22, 2021 5:28 pm
Do you link wxWidgets itself as a shared library (you should)?
Yes.
doublemax wrote:
Fri Jan 22, 2021 5:28 pm
Does your shared lib also link to wxWidgets?
Yes
doublemax wrote:
Fri Jan 22, 2021 5:28 pm
Does it make any difference if you change wxT("") to "" ?
No.
The behavior is the same.

There is more. If I change that line to
ConfigData.Options.wsLANAddress.Empty();

then it crashes there:

Code: Select all

    // delete characters from nStart to nStart + nLen
  wxString& erase(size_type pos = 0, size_type n = npos)
  {
      wxSTRING_INVALIDATE_CACHE();

      size_t from, len;
      PosLenToImpl(pos, n, &from, &len);
      m_impl.erase(from, len);             // <<<<< here it is

      return *this;
  }

DavidHart
Site Admin
Site Admin
Posts: 4058
Joined: Thu Jan 12, 2006 6:23 pm
Location: IoW, UK

Re: wxString class crashes in shared lib

Post by DavidHart » Fri Jan 22, 2021 6:11 pm

Hi,

I've no experience of cross-compiling (BTW, why not build in linux direct, in e.g. a virtualbox guest?) but:
the context of the line is a wxFrame::OnActivate handler
makes me wonder if the handler is called too early, when something is not yet initialised.

Try changing that handler so that it just creates a delay, using e.g. CallAfter().

Regards,

David

MasterAlexei
In need of some credit
In need of some credit
Posts: 5
Joined: Fri Jan 22, 2021 2:58 pm

Re: wxString class crashes in shared lib

Post by MasterAlexei » Fri Jan 22, 2021 6:23 pm

DavidHart wrote:
Fri Jan 22, 2021 6:11 pm
(BTW, why not build in linux direct, in e.g. a virtualbox guest?) :
May be I sad it wrong here. I build in Linux (in virtual machine) direct but the same code, as for Windows. And it is not working in linux.
But I also building the same code in really cross compiling on Windows Host for Raspi, with RaspiGcc 6.3 Compiler. And there, on Raspi, it is working.
DavidHart wrote:
Fri Jan 22, 2021 6:11 pm
..if the handler is called too early, when something is not yet initialised.
Try changing that handler so that it just creates a delay, using e.g. CallAfter().
And there may be something. Raspi is a little bit slower as Intel I7... Ill try to make some delay before that call.

MasterAlexei
In need of some credit
In need of some credit
Posts: 5
Joined: Fri Jan 22, 2021 2:58 pm

[Solwed (32 bit vs 64 bit ) ] Re: wxString class crashes in shared lib

Post by MasterAlexei » Tue Jan 26, 2021 12:14 pm

Well... Hello here.

I did find the cause of the problem: it is the 32 bit vs 64 bit.

The lib and the app are not yet checked for the 64 bit World. But they are compiles very well, and partly worked, but the transition of control in runtime between the app and lib is not so smooth, as it should be. The segmentation faults occurs partly in malloc func with the message "malloc corrupted size vs. prev_size". And, what makes me very curious, mostly (almost only) in wxString class.

So.
The problem is solved only after chrooting in 32 bit world, compile wxWidgets there with bunch of -m32 flags, and using THIS libs in 64 bit World, to compile lib and app with the same flag -m32.

Now it works!
But I think there will be a problem if I would want to make annother app but 64 bit. Bekaus, as I read out, it is very difficult to hold two versions of the same lib in one system...

But till now I produce mostly 32 bit apps, and can live with that some time.

Post Reply