Patchwork [libbacktrace] Find executable on ia64 and 64-bit hppa hpux

login
register
mail settings
Submitter John David Anglin
Date Dec. 9, 2012, 7:57 p.m.
Message ID <20121209195737.GA20382@hiauly1.hia.nrc.ca>
Download mbox | patch
Permalink /patch/204780/
State New
Headers show

Comments

John David Anglin - Dec. 9, 2012, 7:57 p.m.
The getexecname function is not availble on HP-UX.  This patch provides
an alternative techique to obtain the executable path on HP-UX ELF targets.
These have the dlget and dlgetname calls.  I believe that this requires
the dld.sl library be linked with the application which is the normal
case.

With this change and the other libbacktrace fixes that I previously
posted, libbacktrace now works on hppa64-hp-hpux11.11.  Don't have
an ia64 system, so I can't test there.

There is an alternative technique available using the pstat interface
in HP-UX 11.11 and later.  It's also possible to use the pstat interface
and a file system walk on earlier HP-UX versions.  However, this is
painfully slow on large file systems.  It would probably be better to
use argv[0] and some additional checks.

32-bit hppa*-*-hpux* uses the SOM object format.  Don't know how
hard it would be to port libbacktrace to it.  As a result,
BACKTRACE_SUPPORTED is 0.  However, libbacktrace is still called
and fails in finding the executable.  For example,

/test/gnu/gcc/gcc/gcc/testsuite/g++.dg/pr48660.C:16:18: internal compiler error:
 in simplify_subreg, at simplify-rtx.c:5682
 libbacktrace could not find executable to open
 Please submit a full bug report,with preprocessed source if appropriate.

Not sure what would happen if libbacktrace found the executable.

OK for trunk?

Dave
Ian Taylor - Dec. 12, 2012, 1:50 a.m.
On Sun, Dec 9, 2012 at 11:57 AM, John David Anglin
<dave@hiauly1.hia.nrc.ca> wrote:
>
>  #ifndef HAVE_GETEXECNAME
> +#if defined(__hpux) && (defined(__ia64) || defined(_LP64))
> +#include <dlfcn.h>
> +#define getexecname getexecname_hpux
> +
> +static char *
> +getexecname_hpux (void)
> +{
> +  struct load_module_desc desc;
> +
> +  dlget(-2, &desc, sizeof(desc));
> +  return dlgetname(&desc, sizeof(desc), NULL, 0, 0);
> +}
> +

This is the kind of thing that is normally done via configure tests
rather than #ifdef tests.  And once the configure tests are written, I
would prefer to see this as another pass in fileline.c, rather than
this rather complex reuse of getexecname.

Ian

Patch

Index: fileline.c
===================================================================
--- fileline.c	(revision 194325)
+++ fileline.c	(working copy)
@@ -42,8 +42,23 @@ 
 #include "internal.h"
 
 #ifndef HAVE_GETEXECNAME
+#if defined(__hpux) && (defined(__ia64) || defined(_LP64))
+#include <dlfcn.h>
+#define getexecname getexecname_hpux
+
+static char *
+getexecname_hpux (void)
+{
+  struct load_module_desc desc;
+
+  dlget(-2, &desc, sizeof(desc));
+  return dlgetname(&desc, sizeof(desc), NULL, 0, 0);
+}
+
+#else
 #define getexecname() NULL
 #endif
+#endif
 
 /* Initialize the fileline information from the executable.  Returns 1
    on success, 0 on failure.  */