From patchwork Fri Jun 15 12:04:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "REIX, Tony" X-Patchwork-Id: 929907 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-479797-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=atos.net Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="Dm6gQ05j"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 416fKz63pjz9ry1 for ; Fri, 15 Jun 2018 22:04:23 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:content-type:mime-version; q=dns; s=default; b=dPsVn2QrPeaYGrmEoZqBh863aZQaMgj94Ui9zMkzn65Yxyecvu GAmrZZGEjoaWf4hgRLPt0HFm8aZLakvwJhux7AvqsbAySIXIUwfWIg6qwBN9STLM 2lSJstKefptHlXhSLSwO+PaiYxRvl7fQRIHIACbI2e7P6FQkF0psWuOIk= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:content-type:mime-version; s= default; bh=aA2UK4qS+khaQ1GtkPnf/fUC6Zs=; b=Dm6gQ05jxg9xs3TBSwxq jI7v74D0mqFYFilTT36ekvOH5SyFlqpN8hSifQKAhuVM4GSEgDF+t/BtdETcw/a/ M3HLW2WwRhPwNDZf/rj9AuLiuxwoVDoXgelFFZ3C4yDqnvtFivTVGMvSaWjC1oh9 /XtbUync9LSVyg3H0+w6LBg= Received: (qmail 30407 invoked by alias); 15 Jun 2018 12:04:16 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 30396 invoked by uid 89); 15 Jun 2018 12:04:15 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-10.5 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, UNPARSEABLE_RELAY autolearn=ham version=3.3.2 spammy=SUCCESS, destructors, H*c:HHH, office X-HELO: smtppost.atos.net Received: from smtppost.atos.net (HELO smtppost.atos.net) (193.56.114.164) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 15 Jun 2018 12:04:13 +0000 Received: from mail1-ext.my-it-solutions.net (mail1-ext.my-it-solutions.net) by smarthost1.atos.net with smtp (TLS: TLSv1/SSLv3,256bits,ECDHE-RSA-AES256-GCM-SHA384) id 04c0_243a_4e289d5d_c8b4_4186_9ca3_b628af2dc998; Fri, 15 Jun 2018 14:04:10 +0200 Received: from mail1-int.my-it-solutions.net ([10.92.32.11]) by mail1-ext.my-it-solutions.net (8.15.2/8.15.2) with ESMTPS id w5FC48Ra003915 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 15 Jun 2018 14:04:08 +0200 Received: from FRCRPVV9ET1MSX.ww931.my-it-solutions.net ([172.23.231.41]) by mail1-int.my-it-solutions.net (8.15.2/8.15.2) with ESMTPS id w5FC47kO025871 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 15 Jun 2018 14:04:08 +0200 Received: from FRCRPVV9EX7MSX.ww931.my-it-solutions.net ([169.254.14.9]) by FRCRPVV9ET1MSX.ww931.my-it-solutions.net ([172.23.231.41]) with mapi id 14.03.0382.000; Fri, 15 Jun 2018 14:04:07 +0200 From: "REIX, Tony" To: "gcc-patches@gcc.gnu.org" CC: "dje.gcc@gmail.com" , Ian Lance Taylor Subject: [PATCH,AIX] Fix -static-libgcc & -static-libgo issues for AIX Date: Fri, 15 Jun 2018 12:04:07 +0000 Message-ID: MIME-Version: 1.0 Description: * This patch fixes the crash issues faced when using -static-libgcc & -static-libgo on AIX On AIX, do not call shared library initializers when linking statically. This fixes a bug where frame tables are registered twice at runtime, one time by the shared library initializer and one time by the main program initializer, because when linking statically frame tables from the shared library end up in the main program after the first collect2 pass. This breaks _Unwind_Find_FDE’s non-overlapping objects assumption. Tests: * AIX: Build: SUCCESS - build made by means of gmake in trunk. - patch generated by: cd gcc-svn-trunk/ svn diff gcc/ChangeLog gcc/collect2.c ChangeLog: + gcc/collect2.c: manage static link + gcc/ChangeLog: Description Regards, Tony Reix ATOS / Bull SAS ATOS Expert IBM Coop Architect & Technical Leader Office : +33 (0) 4 76 29 72 67 1 rue de Provence - 38432 Échirolles - France www.atos.net --- ./gcc/ChangeLog (revision 261620) +++ ./gcc/ChangeLog (working copy) @@ -1,3 +1,13 @@ +2018-06-15 Tony Reix + + * collect2.c: On AIX, do not call shared library initializers + when linking statically. This fixes a bug where frame tables + are registered twice at runtime, one time by the shared library + initializer and one time by the main program initializer, + because when linking statically frame tables from the shared + library end up in the main program after the first collect2 pass. + This breaks _Unwind_Find_FDE's non-overlapping objects assumption. + 2018-06-15 Richard Biener PR middle-end/86076 --- ./gcc/collect2.c (revision 261597) +++ ./gcc/collect2.c (working copy) @@ -201,6 +201,7 @@ static enum lto_mode_d lto_mode = LTO_MODE_NONE; bool helpflag; /* true if --help */ static int shared_obj; /* true if -shared */ +static int static_obj; /* true if -static */ static const char *c_file; /* .c for constructor/destructor list. */ static const char *o_file; /* .o for constructor/destructor list. */ @@ -255,6 +256,7 @@ bool may_unlink_output_file = false; #ifdef COLLECT_EXPORT_LIST /* Lists to keep libraries to be scanned for global constructors/destructors. */ static struct head libs; /* list of libraries */ +static struct head static_libs; /* list of statically linked libraries */ static struct path_prefix cmdline_lib_dirs; /* directories specified with -L */ static struct path_prefix libpath_lib_dirs; /* directories in LIBPATH */ static struct path_prefix *libpaths[3] = {&cmdline_lib_dirs, @@ -320,9 +322,7 @@ static void write_c_file_glob (FILE *, const char static void scan_libraries (const char *); #endif #ifdef COLLECT_EXPORT_LIST -#if 0 static int is_in_list (const char *, struct id *); -#endif static void write_aix_file (FILE *, struct id *); static char *resolve_lib_name (const char *); #endif @@ -911,6 +911,7 @@ main (int argc, char **argv) int first_file; int num_c_args; char **old_argv; + bool is_static = false; int i; for (i = 0; i < USE_LD_MAX; i++) @@ -1241,6 +1242,8 @@ main (int argc, char **argv) *c_ptr++ = xstrdup (q); if (strcmp (q, "-shared") == 0) shared_obj = 1; + if (strcmp (q, "-static") == 0) + static_obj = 1; if (*q == '-' && q[1] == 'B') { *c_ptr++ = xstrdup (q); @@ -1269,6 +1272,7 @@ main (int argc, char **argv) /* Parse arguments. Remember output file spec, pass the rest to ld. */ /* After the first file, put in the c++ rt0. */ + is_static = static_obj; first_file = 1; while ((arg = *++argv) != (char *) 0) { @@ -1374,6 +1378,14 @@ main (int argc, char **argv) #endif break; +#ifdef COLLECT_EXPORT_LIST + case 'b': + if (!strcmp (arg, "-bstatic")) + is_static = true; + else if (!strcmp (arg, "-bdynamic") || !strcmp (arg, "-bshared")) + is_static = false; + break; +#endif case 'l': if (first_file) { @@ -1390,6 +1402,8 @@ main (int argc, char **argv) /* Saving a full library name. */ add_to_list (&libs, s); + if (is_static) + add_to_list (&static_libs, s); } #endif break; @@ -1490,6 +1504,8 @@ main (int argc, char **argv) { /* Saving a full library name. */ add_to_list (&libs, arg); + if (is_static) + add_to_list (&static_libs, arg); } #endif } @@ -1501,6 +1517,8 @@ main (int argc, char **argv) { fprintf (stderr, "List of libraries:\n"); dump_list (stderr, "\t", libs.first); + fprintf (stderr, "List of statically linked libraries:\n"); + dump_list (stderr, "\t", static_libs.first); } /* The AIX linker will discard static constructors in object files if @@ -1525,9 +1543,11 @@ main (int argc, char **argv) this_filter &= ~SCAN_DWEH; #endif + /* Scan object files. */ while (export_object_lst < object) scan_prog_file (*export_object_lst++, PASS_OBJ, this_filter); + /* Scan libraries. */ for (; list; list = list->next) scan_prog_file (list->name, PASS_FIRST, this_filter); @@ -1975,7 +1995,6 @@ write_list (FILE *stream, const char *prefix, stru #ifdef COLLECT_EXPORT_LIST /* This function is really used only on AIX, but may be useful. */ -#if 0 static int is_in_list (const char *prefix, struct id *list) { @@ -1986,7 +2005,6 @@ is_in_list (const char *prefix, struct id *list) } return 0; } -#endif #endif /* COLLECT_EXPORT_LIST */ /* Added for debugging purpose. */ @@ -2818,7 +2836,8 @@ scan_prog_file (const char *prog_name, scanpass wh case SYM_AIXI: if (! (filter & SCAN_CTOR)) break; - if (is_shared && !aixlazy_flag) + if (is_shared && !aixlazy_flag && !static_obj + && ! is_in_list (prog_name, static_libs.first)) add_to_list (&constructors, name); break;