]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Check return value of bfd_init
authorTom Tromey <tom@tromey.com>
Thu, 25 Oct 2018 15:00:52 +0000 (09:00 -0600)
committerTom Tromey <tom@tromey.com>
Tue, 30 Oct 2018 13:06:17 +0000 (07:06 -0600)
Alan recently added a way for BFD library users to check whether they
were in fact loading a compatible version of BFD:

https://sourceware.org/ml/binutils/2018-10/msg00198.html

It seemed reasonable to me that gdb should do this check as well, in
case someone is dynamically linking against BFD.

Simon pointed out that an earlier version of the patch would cause a
gdb crash if the test failed.  This version works around this by
lowering the call to bfd_init and adding a comment explaining where
'error' can safely be called in captured_main_1.

gdb/ChangeLog
2018-10-30  Tom Tromey  <tom@tromey.com>

* main.c (captured_main_1): Check return value of bfd_init.

gdb/ChangeLog
gdb/main.c

index 0207bec2787a1ca4ed6240c058d94095c3a5722e..940300f95a9617bd3a4ab5fb71b7f594eea4a4d1 100644 (file)
@@ -1,3 +1,7 @@
+2018-10-30  Tom Tromey  <tom@tromey.com>
+
+       * main.c (captured_main_1): Check return value of bfd_init.
+
 2018-10-29  Sergio Durigan Junior  <sergiodj@redhat.com>
 
        * common/offset-type.h (DEFINE_OFFSET_REL_OP): Delete.
index 8709357e924ca8e6ef40b8d7c7e98f81673e01ed..c71d5b557fbdd37ddce37528c89f46a73cfccc78 100644 (file)
@@ -506,7 +506,6 @@ captured_main_1 (struct captured_main_args *context)
   textdomain (PACKAGE);
 #endif
 
-  bfd_init ();
   notice_open_fds ();
 
   saved_command_line = (char *) xstrdup ("");
@@ -517,12 +516,17 @@ captured_main_1 (struct captured_main_args *context)
   setvbuf (stderr, NULL, _IONBF, BUFSIZ);
 #endif
 
+  /* Note: `error' cannot be called before this point, because the
+     caller will crash when trying to print the exception.  */
   main_ui = new ui (stdin, stdout, stderr);
   current_ui = main_ui;
 
   gdb_stdtargerr = gdb_stderr; /* for moment */
   gdb_stdtargin = gdb_stdin;   /* for moment */
 
+  if (bfd_init () != BFD_INIT_MAGIC)
+    error (_("fatal error: libbfd ABI mismatch"));
+
 #ifdef __MINGW32__
   /* On Windows, argv[0] is not necessarily set to absolute form when
      GDB is found along PATH, without which relocation doesn't work.  */