From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1033) id 3923D3950C5D; Sat, 26 Sep 2020 15:28:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3923D3950C5D Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: David Edelsohn To: gcc-cvs@gcc.gnu.org Subject: [gcc r11-3481] aix: collect2 visibility X-Act-Checkin: gcc X-Git-Author: David Edelsohn X-Git-Refname: refs/heads/master X-Git-Oldrev: 5b26b3b3f5c75a86a5a3e851866247ac7fcb6c8b X-Git-Newrev: e721d1137fb3f0323d31b767bc64c772086ff868 Message-Id: <20200926152827.3923D3950C5D@sourceware.org> Date: Sat, 26 Sep 2020 15:28:27 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 26 Sep 2020 15:28:27 -0000 https://gcc.gnu.org/g:e721d1137fb3f0323d31b767bc64c772086ff868 commit r11-3481-ge721d1137fb3f0323d31b767bc64c772086ff868 Author: David Edelsohn Date: Wed Sep 23 16:52:15 2020 -0400 aix: collect2 visibility The code that collect2 generates, compiles and links into applications and shared libraries to initialize constructors and register DWARF tables is built with the compiler options used to invoke the linker. If the compiler options change the visibility from default, the library initialization routines will not be visible and this can prevent initialization. This patch checks if the command line sets visibiliity and then adds GCC pragmas to the initialization code generated by collect2 if necessary to define the visibility on global, exported functions as default. gcc/ChangeLog: 2020-09-26 David Edelsohn Clement Chigot * collect2.c (visibility_flag): New. (main): Detect -fvisibility. (write_c_file_stat): Push and pop default visibility. Diff: --- gcc/collect2.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/gcc/collect2.c b/gcc/collect2.c index f8a5ce45994..6d074a79e91 100644 --- a/gcc/collect2.c +++ b/gcc/collect2.c @@ -184,7 +184,8 @@ static int strip_flag; /* true if -s */ static int export_flag; /* true if -bE */ static int aix64_flag; /* true if -b64 */ static int aixrtl_flag; /* true if -brtl */ -static int aixlazy_flag; /* true if -blazy */ +static int aixlazy_flag; /* true if -blazy */ +static int visibility_flag; /* true if -fvisibility */ #endif enum lto_mode_d { @@ -1239,6 +1240,11 @@ main (int argc, char **argv) *c_ptr++ = xstrdup (q); } } +#ifdef COLLECT_EXPORT_LIST + /* Detect any invocation with -fvisibility. */ + if (strncmp (q, "-fvisibility", 12) == 0) + visibility_flag = 1; +#endif } obstack_free (&temporary_obstack, temporary_firstobj); *c_ptr++ = "-fno-profile-arcs"; @@ -2131,6 +2137,11 @@ write_c_file_stat (FILE *stream, const char *name ATTRIBUTE_UNUSED) fprintf (stream, "\t}\n"); } +#ifdef COLLECT_EXPORT_LIST + /* Set visibility of initializers to default. */ + if (visibility_flag) + fprintf (stream, "#pragma GCC visibility push(default)\n"); +#endif fprintf (stream, "void %s() {\n", initname); if (constructors.number > 0 || frames) { @@ -2163,11 +2174,24 @@ write_c_file_stat (FILE *stream, const char *name ATTRIBUTE_UNUSED) destructors.number + frames); } fprintf (stream, "}\n"); +#ifdef COLLECT_EXPORT_LIST + if (visibility_flag) + fprintf (stream, "#pragma GCC visibility pop\n"); +#endif if (shared_obj) { +#ifdef COLLECT_EXPORT_LIST + /* Set visibility of initializers to default. */ + if (visibility_flag) + fprintf (stream, "#pragma GCC visibility push(default)\n"); +#endif COLLECT_SHARED_INIT_FUNC (stream, initname); COLLECT_SHARED_FINI_FUNC (stream, fininame); +#ifdef COLLECT_EXPORT_LIST + if (visibility_flag) + fprintf (stream, "#pragma GCC visibility pop\n"); +#endif } }