2015-01-05 13:33:28 +01:00
|
|
|
/* Copyright (C) 2002-2015 Free Software Foundation, Inc.
|
2004-05-13 08:41:07 +02:00
|
|
|
Contributed by Andy Vaught and Paul Brook <paul@nowt.org>
|
|
|
|
|
2011-04-16 19:43:03 +02:00
|
|
|
This file is part of the GNU Fortran runtime library (libgfortran).
|
2004-05-13 08:41:07 +02:00
|
|
|
|
2005-01-12 22:27:33 +01:00
|
|
|
Libgfortran is free software; you can redistribute it and/or modify
|
2004-05-13 08:41:07 +02:00
|
|
|
it under the terms of the GNU General Public License as published by
|
2009-04-09 17:00:19 +02:00
|
|
|
the Free Software Foundation; either version 3, or (at your option)
|
2004-05-13 08:41:07 +02:00
|
|
|
any later version.
|
|
|
|
|
2005-01-12 22:27:33 +01:00
|
|
|
Libgfortran is distributed in the hope that it will be useful,
|
2004-05-13 08:41:07 +02:00
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
2009-04-09 17:00:19 +02:00
|
|
|
Under Section 7 of GPL version 3, you are granted additional
|
|
|
|
permissions described in the GCC Runtime Library Exception, version
|
|
|
|
3.1, as published by the Free Software Foundation.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License and
|
|
|
|
a copy of the GCC Runtime Library Exception along with this program;
|
|
|
|
see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
|
|
|
|
<http://www.gnu.org/licenses/>. */
|
2004-05-13 08:41:07 +02:00
|
|
|
|
2007-08-31 16:01:34 +02:00
|
|
|
#include "libgfortran.h"
|
2004-05-13 08:41:07 +02:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
gfortran.h (gfc_option_t): Add flag_backtrace field.
* gfortran.h (gfc_option_t): Add flag_backtrace field.
* lang.opt: Add -fbacktrace option.
* invoke.texi: Document the new option.
* trans-decl.c (gfc_build_builtin_function_decls): Add new
option to the call to set_std.
* options.c (gfc_init_options, gfc_handle_option): Handle the
new option.
* runtime/backtrace.c: New file.
* runtime/environ.c (variable_table): New GFORTRAN_ERROR_BACKTRACE
environment variable.
* runtime/compile_options.c (set_std): Add new argument.
* runtime/main.c (store_exe_path, full_exe_path): New functions.
* runtime/error.c (sys_exit): Add call to show_backtrace.
* libgfortran.h (options_t): New backtrace field.
(store_exe_path, full_exe_path, show_backtrace): New prototypes.
* configure.ac: Add checks for execinfo.h, execvp, pipe, dup2,
close, fdopen, strcasestr, getrlimit, backtrace, backtrace_symbols
and getppid.
* Makefile.am: Add runtime/backtrace.c.
* fmain.c (main): Add call to store_exe_path.
* Makefile.in: Renegerate.
* config.h.in: Renegerate.
* configure: Regenerate.
From-SVN: r122954
2007-03-15 13:39:47 +01:00
|
|
|
#include <limits.h>
|
2014-05-22 05:51:25 +02:00
|
|
|
#include <errno.h>
|
2004-05-13 08:41:07 +02:00
|
|
|
|
|
|
|
|
gfortran.h (gfc_option_t): Add flag_backtrace field.
* gfortran.h (gfc_option_t): Add flag_backtrace field.
* lang.opt: Add -fbacktrace option.
* invoke.texi: Document the new option.
* trans-decl.c (gfc_build_builtin_function_decls): Add new
option to the call to set_std.
* options.c (gfc_init_options, gfc_handle_option): Handle the
new option.
* runtime/backtrace.c: New file.
* runtime/environ.c (variable_table): New GFORTRAN_ERROR_BACKTRACE
environment variable.
* runtime/compile_options.c (set_std): Add new argument.
* runtime/main.c (store_exe_path, full_exe_path): New functions.
* runtime/error.c (sys_exit): Add call to show_backtrace.
* libgfortran.h (options_t): New backtrace field.
(store_exe_path, full_exe_path, show_backtrace): New prototypes.
* configure.ac: Add checks for execinfo.h, execvp, pipe, dup2,
close, fdopen, strcasestr, getrlimit, backtrace, backtrace_symbols
and getppid.
* Makefile.am: Add runtime/backtrace.c.
* fmain.c (main): Add call to store_exe_path.
* Makefile.in: Renegerate.
* config.h.in: Renegerate.
* configure: Regenerate.
From-SVN: r122954
2007-03-15 13:39:47 +01:00
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
2005-11-04 09:44:29 +01:00
|
|
|
/* Stupid function to be sure the constructor is always linked in, even
|
|
|
|
in the case of static linking. See PR libfortran/22298 for details. */
|
|
|
|
void
|
|
|
|
stupid_function_name_for_static_linking (void)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-06-13 22:28:08 +02:00
|
|
|
/* This will be 0 for little-endian
|
|
|
|
machines and 1 for big-endian machines. */
|
|
|
|
int big_endian = 0;
|
2004-05-13 08:41:07 +02:00
|
|
|
|
|
|
|
|
|
|
|
/* Figure out endianness for this machine. */
|
|
|
|
|
|
|
|
static void
|
|
|
|
determine_endianness (void)
|
|
|
|
{
|
|
|
|
union
|
|
|
|
{
|
|
|
|
GFC_LOGICAL_8 l8;
|
|
|
|
GFC_LOGICAL_4 l4[2];
|
|
|
|
} u;
|
|
|
|
|
|
|
|
u.l8 = 1;
|
|
|
|
if (u.l4[0])
|
2008-06-13 22:28:08 +02:00
|
|
|
big_endian = 0;
|
2004-05-13 08:41:07 +02:00
|
|
|
else if (u.l4[1])
|
2008-06-13 22:28:08 +02:00
|
|
|
big_endian = 1;
|
2004-05-13 08:41:07 +02:00
|
|
|
else
|
|
|
|
runtime_error ("Unable to determine machine endianness");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int argc_save;
|
|
|
|
static char **argv_save;
|
|
|
|
|
gfortran.h (gfc_option_t): Add flag_backtrace field.
* gfortran.h (gfc_option_t): Add flag_backtrace field.
* lang.opt: Add -fbacktrace option.
* invoke.texi: Document the new option.
* trans-decl.c (gfc_build_builtin_function_decls): Add new
option to the call to set_std.
* options.c (gfc_init_options, gfc_handle_option): Handle the
new option.
* runtime/backtrace.c: New file.
* runtime/environ.c (variable_table): New GFORTRAN_ERROR_BACKTRACE
environment variable.
* runtime/compile_options.c (set_std): Add new argument.
* runtime/main.c (store_exe_path, full_exe_path): New functions.
* runtime/error.c (sys_exit): Add call to show_backtrace.
* libgfortran.h (options_t): New backtrace field.
(store_exe_path, full_exe_path, show_backtrace): New prototypes.
* configure.ac: Add checks for execinfo.h, execvp, pipe, dup2,
close, fdopen, strcasestr, getrlimit, backtrace, backtrace_symbols
and getppid.
* Makefile.am: Add runtime/backtrace.c.
* fmain.c (main): Add call to store_exe_path.
* Makefile.in: Renegerate.
* config.h.in: Renegerate.
* configure: Regenerate.
From-SVN: r122954
2007-03-15 13:39:47 +01:00
|
|
|
static const char *exe_path;
|
2014-05-22 05:51:25 +02:00
|
|
|
static bool please_free_exe_path_when_done;
|
gfortran.h (gfc_option_t): Add flag_backtrace field.
* gfortran.h (gfc_option_t): Add flag_backtrace field.
* lang.opt: Add -fbacktrace option.
* invoke.texi: Document the new option.
* trans-decl.c (gfc_build_builtin_function_decls): Add new
option to the call to set_std.
* options.c (gfc_init_options, gfc_handle_option): Handle the
new option.
* runtime/backtrace.c: New file.
* runtime/environ.c (variable_table): New GFORTRAN_ERROR_BACKTRACE
environment variable.
* runtime/compile_options.c (set_std): Add new argument.
* runtime/main.c (store_exe_path, full_exe_path): New functions.
* runtime/error.c (sys_exit): Add call to show_backtrace.
* libgfortran.h (options_t): New backtrace field.
(store_exe_path, full_exe_path, show_backtrace): New prototypes.
* configure.ac: Add checks for execinfo.h, execvp, pipe, dup2,
close, fdopen, strcasestr, getrlimit, backtrace, backtrace_symbols
and getppid.
* Makefile.am: Add runtime/backtrace.c.
* fmain.c (main): Add call to store_exe_path.
* Makefile.in: Renegerate.
* config.h.in: Renegerate.
* configure: Regenerate.
From-SVN: r122954
2007-03-15 13:39:47 +01:00
|
|
|
|
|
|
|
/* Save the path under which the program was called, for use in the
|
|
|
|
backtrace routines. */
|
2009-05-27 17:22:34 +02:00
|
|
|
void
|
gfortran.h (gfc_option_t): Add flag_backtrace field.
* gfortran.h (gfc_option_t): Add flag_backtrace field.
* lang.opt: Add -fbacktrace option.
* invoke.texi: Document the new option.
* trans-decl.c (gfc_build_builtin_function_decls): Add new
option to the call to set_std.
* options.c (gfc_init_options, gfc_handle_option): Handle the
new option.
* runtime/backtrace.c: New file.
* runtime/environ.c (variable_table): New GFORTRAN_ERROR_BACKTRACE
environment variable.
* runtime/compile_options.c (set_std): Add new argument.
* runtime/main.c (store_exe_path, full_exe_path): New functions.
* runtime/error.c (sys_exit): Add call to show_backtrace.
* libgfortran.h (options_t): New backtrace field.
(store_exe_path, full_exe_path, show_backtrace): New prototypes.
* configure.ac: Add checks for execinfo.h, execvp, pipe, dup2,
close, fdopen, strcasestr, getrlimit, backtrace, backtrace_symbols
and getppid.
* Makefile.am: Add runtime/backtrace.c.
* fmain.c (main): Add call to store_exe_path.
* Makefile.in: Renegerate.
* config.h.in: Renegerate.
* configure: Regenerate.
From-SVN: r122954
2007-03-15 13:39:47 +01:00
|
|
|
store_exe_path (const char * argv0)
|
|
|
|
{
|
|
|
|
#ifndef DIR_SEPARATOR
|
|
|
|
#define DIR_SEPARATOR '/'
|
|
|
|
#endif
|
|
|
|
|
2014-05-22 05:51:25 +02:00
|
|
|
char *cwd, *path;
|
gfortran.h (gfc_option_t): Add flag_backtrace field.
* gfortran.h (gfc_option_t): Add flag_backtrace field.
* lang.opt: Add -fbacktrace option.
* invoke.texi: Document the new option.
* trans-decl.c (gfc_build_builtin_function_decls): Add new
option to the call to set_std.
* options.c (gfc_init_options, gfc_handle_option): Handle the
new option.
* runtime/backtrace.c: New file.
* runtime/environ.c (variable_table): New GFORTRAN_ERROR_BACKTRACE
environment variable.
* runtime/compile_options.c (set_std): Add new argument.
* runtime/main.c (store_exe_path, full_exe_path): New functions.
* runtime/error.c (sys_exit): Add call to show_backtrace.
* libgfortran.h (options_t): New backtrace field.
(store_exe_path, full_exe_path, show_backtrace): New prototypes.
* configure.ac: Add checks for execinfo.h, execvp, pipe, dup2,
close, fdopen, strcasestr, getrlimit, backtrace, backtrace_symbols
and getppid.
* Makefile.am: Add runtime/backtrace.c.
* fmain.c (main): Add call to store_exe_path.
* Makefile.in: Renegerate.
* config.h.in: Renegerate.
* configure: Regenerate.
From-SVN: r122954
2007-03-15 13:39:47 +01:00
|
|
|
|
2009-05-26 23:19:57 +02:00
|
|
|
/* This can only happen if store_exe_path is called multiple times. */
|
|
|
|
if (please_free_exe_path_when_done)
|
|
|
|
free ((char *) exe_path);
|
|
|
|
|
2011-05-22 18:38:05 +02:00
|
|
|
/* Reading the /proc/self/exe symlink is Linux-specific(?), but if
|
|
|
|
it works it gives the correct answer. */
|
|
|
|
#ifdef HAVE_READLINK
|
2014-05-22 05:51:25 +02:00
|
|
|
ssize_t len, psize = 256;
|
|
|
|
while (1)
|
2011-05-22 18:38:05 +02:00
|
|
|
{
|
2014-05-22 05:51:25 +02:00
|
|
|
path = xmalloc (psize);
|
|
|
|
len = readlink ("/proc/self/exe", path, psize);
|
|
|
|
if (len < 0)
|
|
|
|
{
|
|
|
|
free (path);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if (len < psize)
|
|
|
|
{
|
|
|
|
path[len] = '\0';
|
|
|
|
exe_path = strdup (path);
|
|
|
|
free (path);
|
|
|
|
please_free_exe_path_when_done = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* The remaining option is len == psize. */
|
|
|
|
free (path);
|
|
|
|
psize *= 4;
|
2011-05-22 18:38:05 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-01-11 15:39:28 +01:00
|
|
|
/* If the path is absolute or on a simulator where argv is not set. */
|
|
|
|
#ifdef __MINGW32__
|
|
|
|
if (argv0 == NULL
|
|
|
|
|| ('A' <= argv0[0] && argv0[0] <= 'Z' && argv0[1] == ':')
|
|
|
|
|| ('a' <= argv0[0] && argv0[0] <= 'z' && argv0[1] == ':')
|
|
|
|
|| (argv0[0] == '/' && argv0[1] == '/')
|
|
|
|
|| (argv0[0] == '\\' && argv0[1] == '\\'))
|
|
|
|
#else
|
|
|
|
if (argv0 == NULL || argv0[0] == DIR_SEPARATOR)
|
|
|
|
#endif
|
gfortran.h (gfc_option_t): Add flag_backtrace field.
* gfortran.h (gfc_option_t): Add flag_backtrace field.
* lang.opt: Add -fbacktrace option.
* invoke.texi: Document the new option.
* trans-decl.c (gfc_build_builtin_function_decls): Add new
option to the call to set_std.
* options.c (gfc_init_options, gfc_handle_option): Handle the
new option.
* runtime/backtrace.c: New file.
* runtime/environ.c (variable_table): New GFORTRAN_ERROR_BACKTRACE
environment variable.
* runtime/compile_options.c (set_std): Add new argument.
* runtime/main.c (store_exe_path, full_exe_path): New functions.
* runtime/error.c (sys_exit): Add call to show_backtrace.
* libgfortran.h (options_t): New backtrace field.
(store_exe_path, full_exe_path, show_backtrace): New prototypes.
* configure.ac: Add checks for execinfo.h, execvp, pipe, dup2,
close, fdopen, strcasestr, getrlimit, backtrace, backtrace_symbols
and getppid.
* Makefile.am: Add runtime/backtrace.c.
* fmain.c (main): Add call to store_exe_path.
* Makefile.in: Renegerate.
* config.h.in: Renegerate.
* configure: Regenerate.
From-SVN: r122954
2007-03-15 13:39:47 +01:00
|
|
|
{
|
|
|
|
exe_path = argv0;
|
2014-05-22 05:51:25 +02:00
|
|
|
please_free_exe_path_when_done = false;
|
gfortran.h (gfc_option_t): Add flag_backtrace field.
* gfortran.h (gfc_option_t): Add flag_backtrace field.
* lang.opt: Add -fbacktrace option.
* invoke.texi: Document the new option.
* trans-decl.c (gfc_build_builtin_function_decls): Add new
option to the call to set_std.
* options.c (gfc_init_options, gfc_handle_option): Handle the
new option.
* runtime/backtrace.c: New file.
* runtime/environ.c (variable_table): New GFORTRAN_ERROR_BACKTRACE
environment variable.
* runtime/compile_options.c (set_std): Add new argument.
* runtime/main.c (store_exe_path, full_exe_path): New functions.
* runtime/error.c (sys_exit): Add call to show_backtrace.
* libgfortran.h (options_t): New backtrace field.
(store_exe_path, full_exe_path, show_backtrace): New prototypes.
* configure.ac: Add checks for execinfo.h, execvp, pipe, dup2,
close, fdopen, strcasestr, getrlimit, backtrace, backtrace_symbols
and getppid.
* Makefile.am: Add runtime/backtrace.c.
* fmain.c (main): Add call to store_exe_path.
* Makefile.in: Renegerate.
* config.h.in: Renegerate.
* configure: Regenerate.
From-SVN: r122954
2007-03-15 13:39:47 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-09-15 16:52:46 +02:00
|
|
|
#ifdef HAVE_GETCWD
|
2014-05-22 05:51:25 +02:00
|
|
|
size_t cwdsize = 256;
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
cwd = xmalloc (cwdsize);
|
|
|
|
if (getcwd (cwd, cwdsize))
|
|
|
|
break;
|
|
|
|
else if (errno == ERANGE)
|
|
|
|
{
|
|
|
|
free (cwd);
|
|
|
|
cwdsize *= 4;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
free (cwd);
|
|
|
|
cwd = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2007-09-15 16:52:46 +02:00
|
|
|
#else
|
2012-01-12 10:58:34 +01:00
|
|
|
cwd = NULL;
|
2007-09-15 16:52:46 +02:00
|
|
|
#endif
|
gfortran.h (gfc_option_t): Add flag_backtrace field.
* gfortran.h (gfc_option_t): Add flag_backtrace field.
* lang.opt: Add -fbacktrace option.
* invoke.texi: Document the new option.
* trans-decl.c (gfc_build_builtin_function_decls): Add new
option to the call to set_std.
* options.c (gfc_init_options, gfc_handle_option): Handle the
new option.
* runtime/backtrace.c: New file.
* runtime/environ.c (variable_table): New GFORTRAN_ERROR_BACKTRACE
environment variable.
* runtime/compile_options.c (set_std): Add new argument.
* runtime/main.c (store_exe_path, full_exe_path): New functions.
* runtime/error.c (sys_exit): Add call to show_backtrace.
* libgfortran.h (options_t): New backtrace field.
(store_exe_path, full_exe_path, show_backtrace): New prototypes.
* configure.ac: Add checks for execinfo.h, execvp, pipe, dup2,
close, fdopen, strcasestr, getrlimit, backtrace, backtrace_symbols
and getppid.
* Makefile.am: Add runtime/backtrace.c.
* fmain.c (main): Add call to store_exe_path.
* Makefile.in: Renegerate.
* config.h.in: Renegerate.
* configure: Regenerate.
From-SVN: r122954
2007-03-15 13:39:47 +01:00
|
|
|
|
2012-01-12 10:58:34 +01:00
|
|
|
if (!cwd)
|
|
|
|
{
|
|
|
|
exe_path = argv0;
|
2014-05-22 05:51:25 +02:00
|
|
|
please_free_exe_path_when_done = false;
|
2012-01-12 10:58:34 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-05-22 18:38:05 +02:00
|
|
|
/* exe_path will be cwd + "/" + argv[0] + "\0". This will not work
|
|
|
|
if the executable is not in the cwd, but at this point we're out
|
|
|
|
of better ideas. */
|
2011-04-16 19:43:03 +02:00
|
|
|
size_t pathlen = strlen (cwd) + 1 + strlen (argv0) + 1;
|
2014-05-22 05:51:25 +02:00
|
|
|
path = xmalloc (pathlen);
|
2011-04-16 19:43:03 +02:00
|
|
|
snprintf (path, pathlen, "%s%c%s", cwd, DIR_SEPARATOR, argv0);
|
2014-05-22 05:51:25 +02:00
|
|
|
free (cwd);
|
gfortran.h (gfc_option_t): Add flag_backtrace field.
* gfortran.h (gfc_option_t): Add flag_backtrace field.
* lang.opt: Add -fbacktrace option.
* invoke.texi: Document the new option.
* trans-decl.c (gfc_build_builtin_function_decls): Add new
option to the call to set_std.
* options.c (gfc_init_options, gfc_handle_option): Handle the
new option.
* runtime/backtrace.c: New file.
* runtime/environ.c (variable_table): New GFORTRAN_ERROR_BACKTRACE
environment variable.
* runtime/compile_options.c (set_std): Add new argument.
* runtime/main.c (store_exe_path, full_exe_path): New functions.
* runtime/error.c (sys_exit): Add call to show_backtrace.
* libgfortran.h (options_t): New backtrace field.
(store_exe_path, full_exe_path, show_backtrace): New prototypes.
* configure.ac: Add checks for execinfo.h, execvp, pipe, dup2,
close, fdopen, strcasestr, getrlimit, backtrace, backtrace_symbols
and getppid.
* Makefile.am: Add runtime/backtrace.c.
* fmain.c (main): Add call to store_exe_path.
* Makefile.in: Renegerate.
* config.h.in: Renegerate.
* configure: Regenerate.
From-SVN: r122954
2007-03-15 13:39:47 +01:00
|
|
|
exe_path = path;
|
2014-05-22 05:51:25 +02:00
|
|
|
please_free_exe_path_when_done = true;
|
gfortran.h (gfc_option_t): Add flag_backtrace field.
* gfortran.h (gfc_option_t): Add flag_backtrace field.
* lang.opt: Add -fbacktrace option.
* invoke.texi: Document the new option.
* trans-decl.c (gfc_build_builtin_function_decls): Add new
option to the call to set_std.
* options.c (gfc_init_options, gfc_handle_option): Handle the
new option.
* runtime/backtrace.c: New file.
* runtime/environ.c (variable_table): New GFORTRAN_ERROR_BACKTRACE
environment variable.
* runtime/compile_options.c (set_std): Add new argument.
* runtime/main.c (store_exe_path, full_exe_path): New functions.
* runtime/error.c (sys_exit): Add call to show_backtrace.
* libgfortran.h (options_t): New backtrace field.
(store_exe_path, full_exe_path, show_backtrace): New prototypes.
* configure.ac: Add checks for execinfo.h, execvp, pipe, dup2,
close, fdopen, strcasestr, getrlimit, backtrace, backtrace_symbols
and getppid.
* Makefile.am: Add runtime/backtrace.c.
* fmain.c (main): Add call to store_exe_path.
* Makefile.in: Renegerate.
* config.h.in: Renegerate.
* configure: Regenerate.
From-SVN: r122954
2007-03-15 13:39:47 +01:00
|
|
|
}
|
|
|
|
|
2009-05-26 23:19:57 +02:00
|
|
|
|
gfortran.h (gfc_option_t): Add flag_backtrace field.
* gfortran.h (gfc_option_t): Add flag_backtrace field.
* lang.opt: Add -fbacktrace option.
* invoke.texi: Document the new option.
* trans-decl.c (gfc_build_builtin_function_decls): Add new
option to the call to set_std.
* options.c (gfc_init_options, gfc_handle_option): Handle the
new option.
* runtime/backtrace.c: New file.
* runtime/environ.c (variable_table): New GFORTRAN_ERROR_BACKTRACE
environment variable.
* runtime/compile_options.c (set_std): Add new argument.
* runtime/main.c (store_exe_path, full_exe_path): New functions.
* runtime/error.c (sys_exit): Add call to show_backtrace.
* libgfortran.h (options_t): New backtrace field.
(store_exe_path, full_exe_path, show_backtrace): New prototypes.
* configure.ac: Add checks for execinfo.h, execvp, pipe, dup2,
close, fdopen, strcasestr, getrlimit, backtrace, backtrace_symbols
and getppid.
* Makefile.am: Add runtime/backtrace.c.
* fmain.c (main): Add call to store_exe_path.
* Makefile.in: Renegerate.
* config.h.in: Renegerate.
* configure: Regenerate.
From-SVN: r122954
2007-03-15 13:39:47 +01:00
|
|
|
/* Return the full path of the executable. */
|
|
|
|
char *
|
|
|
|
full_exe_path (void)
|
|
|
|
{
|
|
|
|
return (char *) exe_path;
|
|
|
|
}
|
|
|
|
|
2009-05-26 23:19:57 +02:00
|
|
|
|
2014-10-20 09:53:37 +02:00
|
|
|
#ifndef HAVE_STRTOK_R
|
|
|
|
static char*
|
|
|
|
gfstrtok_r (char *str, const char *delim,
|
|
|
|
char **saveptr __attribute__ ((unused)))
|
|
|
|
{
|
|
|
|
return strtok (str, delim);
|
|
|
|
}
|
|
|
|
#define strtok_r gfstrtok_r
|
|
|
|
#endif
|
|
|
|
|
2011-05-29 22:13:52 +02:00
|
|
|
char *addr2line_path;
|
|
|
|
|
|
|
|
/* Find addr2line and store the path. */
|
|
|
|
|
|
|
|
void
|
|
|
|
find_addr2line (void)
|
|
|
|
{
|
|
|
|
#ifdef HAVE_ACCESS
|
2014-10-20 09:53:37 +02:00
|
|
|
#define A2L_LEN 11
|
2012-05-05 08:30:51 +02:00
|
|
|
char *path = secure_getenv ("PATH");
|
2011-11-11 17:31:47 +01:00
|
|
|
if (!path)
|
2011-11-11 17:38:11 +01:00
|
|
|
return;
|
2014-10-20 09:53:37 +02:00
|
|
|
char *tp = strdup (path);
|
|
|
|
if (!tp)
|
|
|
|
return;
|
2011-05-29 22:13:52 +02:00
|
|
|
size_t n = strlen (path);
|
2014-10-20 09:53:37 +02:00
|
|
|
char *ap = xmalloc (n + A2L_LEN);
|
|
|
|
char *saveptr;
|
|
|
|
for (char *str = tp;; str = NULL)
|
2011-05-29 22:13:52 +02:00
|
|
|
{
|
2014-10-20 09:53:37 +02:00
|
|
|
char *token = strtok_r (str, ":", &saveptr);
|
|
|
|
if (!token)
|
|
|
|
break;
|
|
|
|
size_t toklen = strlen (token);
|
|
|
|
memcpy (ap, token, toklen);
|
|
|
|
memcpy (ap + toklen, "/addr2line", A2L_LEN);
|
|
|
|
if (access (ap, R_OK|X_OK) == 0)
|
2011-05-29 22:13:52 +02:00
|
|
|
{
|
2014-10-20 09:53:37 +02:00
|
|
|
addr2line_path = strdup (ap);
|
|
|
|
break;
|
2011-05-29 22:13:52 +02:00
|
|
|
}
|
|
|
|
}
|
2014-10-20 09:53:37 +02:00
|
|
|
free (tp);
|
|
|
|
free (ap);
|
2011-05-29 22:13:52 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-05-26 23:19:57 +02:00
|
|
|
/* Set the saved values of the command line arguments. */
|
|
|
|
|
|
|
|
void
|
|
|
|
set_args (int argc, char **argv)
|
|
|
|
{
|
|
|
|
argc_save = argc;
|
|
|
|
argv_save = argv;
|
|
|
|
store_exe_path (argv[0]);
|
|
|
|
}
|
2009-06-14 18:52:49 +02:00
|
|
|
iexport(set_args);
|
2009-05-26 23:19:57 +02:00
|
|
|
|
|
|
|
|
|
|
|
/* Retrieve the saved values of the command line arguments. */
|
|
|
|
|
|
|
|
void
|
|
|
|
get_args (int *argc, char ***argv)
|
|
|
|
{
|
|
|
|
*argc = argc_save;
|
|
|
|
*argv = argv_save;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-05-13 08:41:07 +02:00
|
|
|
/* Initialize the runtime library. */
|
|
|
|
|
|
|
|
static void __attribute__((constructor))
|
|
|
|
init (void)
|
|
|
|
{
|
|
|
|
/* Figure out the machine endianness. */
|
|
|
|
determine_endianness ();
|
|
|
|
|
|
|
|
/* Must be first */
|
|
|
|
init_variables ();
|
|
|
|
|
|
|
|
init_units ();
|
2005-10-12 22:21:31 +02:00
|
|
|
set_fpu ();
|
2005-08-11 15:50:13 +02:00
|
|
|
init_compile_options ();
|
2004-05-13 08:41:07 +02:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
/* Check for special command lines. */
|
|
|
|
|
|
|
|
if (argc > 1 && strcmp (argv[1], "--help") == 0)
|
|
|
|
show_variables ();
|
|
|
|
|
acinclude.m4 (LIBGFOR_CHECK_ATTRIBUTE_VISIBILITY): New.
* acinclude.m4 (LIBGFOR_CHECK_ATTRIBUTE_VISIBILITY): New.
(LIBGFOR_CHECK_ATTRIBUTE_DLLEXPORT): New.
(LIBGFOR_CHECK_ATTRIBUTE_ALIAS): New.
* configure.ac: Use them.
* configure, config.h.in, aclocal.m4: Rebuild.
* libgfortran.h (prefix): Remove.
(PREFIX, IPREFIX): New.
(sym_rename, sym_rename1, sym_rename2): New.
(internal_proto, export_proto, export_proto_np): New.
(iexport_proto, iexport): New.
(iexport_data_proto, iexport_data): New.
* intrinsics/abort.c, intrinsics/args.c, intrinsics/associated.c,
intrinsics/cpu_time.c, intrinsics/cshift0.c,
intrinsics/date_and_time.c, intrinsics/env.c, intrinsics/eoshift0.c,
intrinsics/eoshift2.c, intrinsics/etime.c, intrinsics/exit.c,
intrinsics/flush.c, intrinsics/fnum.c, intrinsics/getXid.c,
intrinsics/getcwd.c, intrinsics/ishftc.c, intrinsics/mvbits.c,
intrinsics/pack_generic.c, intrinsics/rand.c, intrinsics/random.c,
intrinsics/reshape_generic.c, intrinsics/size.c,
intrinsics/spread_generic.c, intrinsics/stat.c,
intrinsics/string_intrinsics.c, intrinsics/system.c,
intrinsics/system_clock.c, intrinsics/transpose_generic.c,
intrinsics/umask.c, intrinsics/unlink.c, intrinsics/unpack_generic.c,
io/backspace.c, io/close.c, io/endfile.c, io/inquire.c, io/io.h,
io/open.c, io/rewind.c, io/transfer.c, libgfortran.h, m4/cshift1.m4,
m4/dotprod.m4, m4/dotprodc.m4, m4/dotprodl.m4, m4/eoshift1.m4,
m4/eoshift3.m4, m4/exponent.m4, m4/fraction.m4, m4/iforeach.m4,
m4/ifunction.m4, m4/matmul.m4, m4/matmull.m4, m4/nearest.m4,
m4/pow.m4, m4/reshape.m4, m4/set_exponent.m4, m4/shape.m4,
m4/transpose.m4, runtime/environ.c, runtime/error.c,
runtime/in_pack_generic.c, runtime/in_unpack_generic.c,
runtime/main.c, runtime/memory.c, runtime/pause.c, runtime/select.c,
runtime/stop.c: Use them to mark symbols internal or external.
* generated/*: Rebuild.
From-SVN: r92045
2004-12-12 09:59:05 +01:00
|
|
|
/* if (argc > 1 && strcmp(argv[1], "--resume") == 0) resume(); */
|
2004-05-13 08:41:07 +02:00
|
|
|
#endif
|
|
|
|
|
2011-05-29 22:13:52 +02:00
|
|
|
if (options.backtrace == 1)
|
|
|
|
find_addr2line ();
|
|
|
|
|
2007-08-12 22:45:29 +02:00
|
|
|
random_seed_i4 (NULL, NULL, NULL);
|
2004-05-13 08:41:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Cleanup the runtime library. */
|
|
|
|
|
|
|
|
static void __attribute__((destructor))
|
normalize.c (almostone_r4, [...]): Fix parameter list.
* runtime/normalize.c (almostone_r4, almostone_r8): Fix parameter
list.
* intrinsics/random.c (KISS_DEFAULT_SEED): Remove extra semicolon.
* io/transfer.c: Do not use empty initializers for global objects.
Add missing initializers.
* io/lock.c: Do not use empty initializers for global objects.
* io/close.c: Add missing initializers.
* runtime/environ.c: Add missing initializers. Do not use empty
initializers for global object.
(init_string): Mark argument as unused.
* runtime/main.c (cleanup): Fix parameter list.
* io/io.h: Fix parameter lists.
* m4/transpose.m4, m4/matmul.m4: Fix pointer cast to avoid
warning.
* generated/transpose_c4.c, generated/transpose_c8.c,
generated/transpose_i4.c, generated/transpose_i8.c,
generated/matmul_c4.c, generated/matmul_c8.c,
generated/matmul_i4.c, generated/matmul_i8.c,
generated/matmul_r4.c, generated/matmul_r8.c: Regenerated.
* io/write.c (nml_write_obj): Fix 64-bit problem.
* io/list_read.c (nml_get_obj_data): Add missing braces around
initializer to avoid warnings.
* intrinsics/etime.c (etime_sub): Remove unused variable.
From-SVN: r99719
2005-05-15 14:44:42 +02:00
|
|
|
cleanup (void)
|
2004-05-13 08:41:07 +02:00
|
|
|
{
|
|
|
|
close_units ();
|
2007-04-19 13:01:15 +02:00
|
|
|
|
|
|
|
if (please_free_exe_path_when_done)
|
2007-10-18 23:25:21 +02:00
|
|
|
free ((char *) exe_path);
|
2011-05-29 22:13:52 +02:00
|
|
|
|
|
|
|
free (addr2line_path);
|
2004-05-13 08:41:07 +02:00
|
|
|
}
|