[Top][All Lists]

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

Re: [lmi] Linker discarding initialization code

From: Greg Chicares
Subject: Re: [lmi] Linker discarding initialization code
Date: Tue, 26 Jan 2016 23:30:02 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Icedove/31.3.0

On 2016-01-26 15:01, Vadim Zeitlin wrote:
> On Tue, 26 Jan 2016 14:21:50 +0000 Greg Chicares <address@hidden> wrote:
> GC> /cygdrive/c/downloads[0]$./elapsed_time.exe xyzzy
> GC> zsh: segmentation fault  ./elapsed_time.exe xyzzy
> GC> 
> 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

Tell the linker to link all required object files into each program:
makes sense to me.

> 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.

Or eliminated by using a common build directory for all objects. I guess
that's not the automake way. But following my own way instead means I
don't need automake or ccache.

> 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.

So we fix it once, and we're done.

>  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

I prefer to avoid drastic change.

>  The only other alternative that might work would be to have a wx style
> system of "modules"
> 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.

Agreed: it's not needed here.

>  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).

It works. Before:

  /cygdrive/c/downloads[0]$./elapsed_time xyzzy
  zsh: segmentation fault  ./elapsed_time xyzzy


  /cygdrive/c/downloads[139]$./elapsed_time.exe xyzzy
  Exit code 12345 from command 'xyzzy'.
  Elapsed time: 2 milliseconds

Index: Makefile.am
--- Makefile.am (revision 6491)
+++ Makefile.am (working copy)
@@ -453,6 +453,7 @@

 elapsed_time_SOURCES = \
+    alert_cli.cpp \
     elapsed_time.cpp \
     system_command.cpp \
     system_command_non_wx.cpp \


These days, I use 'time' instead, so I'm in no rush to commit that change.
Maybe when I purge 'mpatrol'.

> But I think it
> would be better to change the code to make sure such issues can never arise
> instead or, at least, later.

Pragmatically speaking, many other things must take priority over this.

reply via email to

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