[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lmi] Linker discarding initialization code (was: Cross-linking issu

From: Vadim Zeitlin
Subject: Re: [lmi] Linker discarding initialization code (was: Cross-linking issues)
Date: Tue, 26 Jan 2016 16:01:43 +0100

On Tue, 26 Jan 2016 14:21:50 +0000 Greg Chicares <address@hidden> wrote:

GC> On 2016-01-21 01:52, Greg Chicares wrote:
GC> > On 2016-01-14 01:35, Vadim Zeitlin wrote:
GC> [...]
GC> >> Second, we need to
GC> >> add the "force linking" stuff to alert_wx.cpp and main_wx.cpp to ensure
GC> >> that the alert function pointers are set correctly in lmi_wx.exe as
GC> >> otherwise they were not, resulting in an error message and abort, for the
GC> >> same reason as in the MSVS build: alert_wx object file was simply omitted
GC> >> entirely by the linker.
GC> > 
GC> > Committed (with additions) 20160121T0032Z,  revision 6486.
GC> More work is required. The issue is not confined to wx-dependent code.
GC> /cygdrive/c/downloads[0]$./elapsed_time.exe xyzzy
GC> zsh: segmentation fault  ./elapsed_time.exe xyzzy
GC> Messagebox:
GC>   Catastrophic error
GC>   Not all alert function pointers have been set.

 Yes, this does look like exactly the same issue. Unfortunately I'm not
sure what to do about this. The simplest solution is probably to always
link alert_{cli,wx}.cpp and other similar files into the main program
itself instead of putting them in a library -- after all, this is what
objects.make does and even Makefile.am does it for some programs, but not
for elapsed_time. The advantage of doing it like this is, again, the
simplicity but I also see two problems with this approach: first, not very
important, is that it makes the build longer because the same file needs to
be compiled again and again as part of many different projects instead of
being compiled only once as part of a library. This could be mostly
alleviated by just using ccache though. The second problem, which is more
serious IMO, is that it's error-prone: it's too simple to forget to add
alert_xxx.cpp to the list of a target's sources and everything will still
build fine and just crash during run-time. I think it would be worth trying
to avoid this.

 And the best way I see to do it is to force all alert function pointers to
be defined in the main program, so that we get link errors if we forget to
initialize them. This would be a drastic change compared to the existing
approach (especially because it wouldn't be limited to alert functions only
but also to the progress ones etc), but it looks like a better solution to

 The only other alternative that might work would be to have a wx style
system of "modules", i.e. objects that provide functions for initializing
and shutting down different subsystems. There would be still be some
function to call to set them up (e.g. wxInitialize() in the wx case), and
so in principle it would still be possible to forget to call it, but at
least you'd only have to call a single function. Still, this would require
quite a few changes as well and I don't think the extra flexibility of wx
style modules (e.g. the possibility to have dependencies between them) is
really needed here and justifies the extra complexity.

 To summarize, right now, the simplest way to fix the problem is to just
add alert_cli.cpp to elapsed_time_SOURCES in Makefile.am (I didn't have
time to test this yet, but I'm almost sure it will work). But I think it
would be better to change the code to make sure such issues can never arise
instead or, at least, later.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]