From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 32692 invoked by alias); 24 Oct 2003 02:45:18 -0000 Mailing-List: contact gdb-patches-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sources.redhat.com Received: (qmail 32685 invoked from network); 24 Oct 2003 02:45:17 -0000 Received: from unknown (HELO localhost.redhat.com) (65.49.0.121) by sources.redhat.com with SMTP; 24 Oct 2003 02:45:17 -0000 Received: from redhat.com (localhost [127.0.0.1]) by localhost.redhat.com (Postfix) with ESMTP id 4CFC32B89 for ; Thu, 23 Oct 2003 22:44:42 -0400 (EDT) Message-ID: <3F98921A.9040302@redhat.com> Date: Fri, 24 Oct 2003 02:45:00 -0000 From: Andrew Cagney User-Agent: Mozilla/5.0 (X11; U; NetBSD macppc; en-US; rv:1.0.2) Gecko/20030820 X-Accept-Language: en-us, en MIME-Version: 1.0 To: gdb-patches@sources.redhat.com Subject: [patch/rfc] Fix gdb/1426: osabi initialization race condition Content-Type: multipart/mixed; boundary="------------090205060100050409060300" X-SW-Source: 2003-10/txt/msg00718.txt.bz2 This is a multi-part message in MIME format. --------------090205060100050409060300 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Content-length: 488 Hello, ref: http://sources.redhat.com/gdb/bugs/1426 for details. The attached implements the "hack" suggested in tdep/1426 to work around a bogus error message: A handler for the OS ABI "GNU/Linux" is not built into this configuration of GDB. Attempting to continue with the default rs6000:6000 settingsGNU gdb 2003-10-23-cvs Copyright 2003 Free Software Foundation, Inc. ... that appears on some platforms during startup. Baring comment, I'll commit this in a few days. Andrew --------------090205060100050409060300 Content-Type: text/plain; name="diffs" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="diffs" Content-length: 3778 2003-10-23 Andrew Cagney * osabi.c (GDB_OSABI_DEFAULT): Delete macro definition. (user_osabi_default): New static variable. (_initialize_gdb_osabi): Initialize "user_osabi_default" to GDB_OSABI_DEFAULT if defined, GDB_OSABI_UNKNOWN otherwize. (gdbarch_lookup_osabi): Replace GDB_OSABI_DEFAULT with "user_osabi_default". (set_osabi, show_osabi): Ditto. Work around GDB PR tdep/1426. Index: osabi.c =================================================================== RCS file: /cvs/src/src/gdb/osabi.c,v retrieving revision 1.17 diff -u -r1.17 osabi.c --- osabi.c 24 Aug 2003 11:47:18 -0000 1.17 +++ osabi.c 24 Oct 2003 02:30:08 -0000 @@ -30,10 +30,6 @@ #include "elf-bfd.h" -#ifndef GDB_OSABI_DEFAULT -#define GDB_OSABI_DEFAULT GDB_OSABI_UNKNOWN -#endif - /* State for the "set osabi" command. */ static enum { osabi_auto, osabi_default, osabi_user } user_osabi_state; static enum gdb_osabi user_selected_osabi; @@ -45,6 +41,23 @@ }; static const char *set_osabi_string; +/* Value for the "default" osabi. + + It is initialized, during per-file initialization, by the function + _initialize_osabi below, to the build-time macro GDB_OSABI_DEFAULT. + Due to a race condition with the code trying to create the initial + "static" architecture, it is not statically initialized to + GDB_OSABI_DEFAULT. + + The problem with static initialization is that the code creating + that initial "static" architecture calls gdbarch_osabi_init + (requesting the "default" OSABI) before any per-file initialization + has occured, but it is only during that per-file initialization + that the OSABI target code gets to register that said "default" + OSABI. Starting the user_osabi_default out as "uninitialized", and + then initializing it at per-file time works around the problem. */ +static int user_osabi_default = GDB_OSABI_UNINITIALIZED; + /* This table matches the indices assigned to enum gdb_osabi. Keep them in sync. */ static const char * const gdb_osabi_names[] = @@ -210,8 +223,8 @@ an inconclusive result (otherwise). */ if (abfd == NULL) { - if (GDB_OSABI_DEFAULT != GDB_OSABI_UNKNOWN) - return GDB_OSABI_DEFAULT; + if (user_osabi_default != GDB_OSABI_UNKNOWN) + return user_osabi_default; else return GDB_OSABI_UNINITIALIZED; } @@ -277,8 +290,8 @@ /* If we didn't find a match, but a default was specified at configure time, return the default. */ - if (GDB_OSABI_DEFAULT != GDB_OSABI_UNKNOWN && match == GDB_OSABI_UNKNOWN) - return GDB_OSABI_DEFAULT; + if (user_osabi_default != GDB_OSABI_UNKNOWN && match == GDB_OSABI_UNKNOWN) + return user_osabi_default; else return match; } @@ -504,7 +517,7 @@ user_osabi_state = osabi_auto; else if (strcmp (set_osabi_string, "default") == 0) { - user_selected_osabi = GDB_OSABI_DEFAULT; + user_selected_osabi = user_osabi_default; user_osabi_state = osabi_user; } else if (strcmp (set_osabi_string, "none") == 0) @@ -545,9 +558,9 @@ printf_filtered ("The current OS ABI is \"%s\".\n", gdbarch_osabi_name (user_selected_osabi)); - if (GDB_OSABI_DEFAULT != GDB_OSABI_UNKNOWN) + if (user_osabi_default != GDB_OSABI_UNKNOWN) printf_filtered ("The default OS ABI is \"%s\".\n", - gdbarch_osabi_name (GDB_OSABI_DEFAULT)); + gdbarch_osabi_name (user_osabi_default)); } extern initialize_file_ftype _initialize_gdb_osabi; /* -Wmissing-prototype */ @@ -577,4 +590,9 @@ add_cmd ("osabi", class_support, show_osabi, "Show OS/ABI of target.", &showlist); user_osabi_state = osabi_auto; +#ifdef GDB_OSABI_DEFAULT + user_osabi_default = GDB_OSABI_DEFAULT; +#else + user_osabi_default = GDB_OSABI_UNKNOWN; +#endif } --------------090205060100050409060300--