diff options
author | Ian Lance Taylor <ian@gcc.gnu.org> | 2014-08-02 00:54:15 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2014-08-02 00:54:15 +0000 |
commit | dc14e88e07ba3c0d8b7ef1f3183240d6f6428be3 (patch) | |
tree | d37998f4cbceacc74d2de058a6ad5c59557e4f02 /libgo | |
parent | 3bc63227d5eb38a70adee7375e5d3596e9c7ec01 (diff) | |
download | gcc-dc14e88e07ba3c0d8b7ef1f3183240d6f6428be3.zip gcc-dc14e88e07ba3c0d8b7ef1f3183240d6f6428be3.tar.gz gcc-dc14e88e07ba3c0d8b7ef1f3183240d6f6428be3.tar.bz2 |
re PR other/61895 (libbacktrace crashes with bus error with empty file argv[0])
PR other/61895
runtime: Ignore small argv[0] file for backtrace.
Reportedly in some cases Docker starts processes with argv[0]
pointing to an empty file. That would cause libgo to pass
that empty file to libbacktrace, which would then fail to do
any backtraces. Everything should work fine if libbacktrace
falls back to /proc/self/exe.
This patch to libgo works around the problem by ignoring
argv[0] if it is a small file, or if stat fails. This is not
a perfect fix but it's an unusual problem.
From-SVN: r213513
Diffstat (limited to 'libgo')
-rw-r--r-- | libgo/runtime/go-caller.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/libgo/runtime/go-caller.c b/libgo/runtime/go-caller.c index a5c687d..7fcdf20 100644 --- a/libgo/runtime/go-caller.c +++ b/libgo/runtime/go-caller.c @@ -7,6 +7,9 @@ /* Implement runtime.Caller. */ #include <stdint.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <unistd.h> #include "backtrace.h" @@ -99,6 +102,7 @@ __go_get_backtrace_state () if (back_state == NULL) { const char *filename; + struct stat s; filename = (const char *) runtime_progname (); @@ -108,6 +112,14 @@ __go_get_backtrace_state () if (__builtin_strchr (filename, '/') == NULL) filename = NULL; + /* If the file is small, then it's not the real executable. + This is specifically to deal with Docker, which uses a bogus + argv[0] (http://gcc.gnu.org/PR61895). It would be nice to + have a better check for whether this file is the real + executable. */ + if (stat (filename, &s) < 0 || s.st_size < 1024) + filename = NULL; + back_state = backtrace_create_state (filename, 1, error_callback, NULL); } runtime_unlock (&back_state_lock); |