From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1033) id 3F4533858C3A; Sun, 15 Aug 2021 17:23:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3F4533858C3A MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="utf-8" From: David Edelsohn To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-2914] aix: 64 bit AIX TLS libpthread dependency. X-Act-Checkin: gcc X-Git-Author: =?utf-8?q?Cl=C3=A9ment_Chigot?= X-Git-Refname: refs/heads/master X-Git-Oldrev: 882f1d58bfa56737ff2de84c3cd1e0acfc318b86 X-Git-Newrev: 34ce7f7a9a64dd69dd6a77dfd4a77406c3c71014 Message-Id: <20210815172335.3F4533858C3A@sourceware.org> Date: Sun, 15 Aug 2021 17:23:35 +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: Sun, 15 Aug 2021 17:23:35 -0000 https://gcc.gnu.org/g:34ce7f7a9a64dd69dd6a77dfd4a77406c3c71014 commit r12-2914-g34ce7f7a9a64dd69dd6a77dfd4a77406c3c71014 Author: Clément Chigot Date: Thu Aug 12 13:17:15 2021 -0400 aix: 64 bit AIX TLS libpthread dependency. 64bit XCOFF files will generated TLS access, with local-exec or global-exec models, by an access to R13. Thus, there isn't any reference to a TLS symbol. The problem is that it allows programs with TLS to be compiled and linked even without -pthread. Most of the time, it will result in a segfault when trying to access a TLS variable. But sometimes, it might create a memory corruption. This patch forces a reference to __tls_get_addr() to ensure link will fail without -pthread. gcc/ChangeLog: 2021-08-11 Clément Chigot * config/rs6000/rs6000.c (xcoff_tls_exec_model_detected): New. (rs6000_legitimize_tls_address_aix): Use it. (rs6000_xcoff_file_end): Add ".ref __tls_get_addr" when xcoff_tls_exec_model_detected is true. Diff: --- gcc/config/rs6000/rs6000.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c index 60f406a4ff6..e073b26b430 100644 --- a/gcc/config/rs6000/rs6000.c +++ b/gcc/config/rs6000/rs6000.c @@ -127,6 +127,9 @@ scalar_int_mode rs6000_pmode; bool rs6000_passes_ieee128 = false; #endif +/* Track use of r13 in 64bit AIX TLS. */ +static bool xcoff_tls_exec_model_detected = false; + /* Generate the manged name (i.e. U10__float128) used in GCC 8.1, and not the name used in current releases (i.e. u9__ieee128). */ static bool ieee128_mangling_gcc_8_1; @@ -9397,7 +9400,10 @@ rs6000_legitimize_tls_address_aix (rtx addr, enum tls_model model) emit_insn (gen_tls_get_tpointer (tlsreg)); } else - tlsreg = gen_rtx_REG (DImode, 13); + { + tlsreg = gen_rtx_REG (DImode, 13); + xcoff_tls_exec_model_detected = true; + } /* Load the TOC value into temporary register. */ tmpreg = gen_reg_rtx (Pmode); @@ -21122,6 +21128,12 @@ rs6000_xcoff_file_end (void) fputs (TARGET_32BIT ? "\t.long _section_.text\n" : "\t.llong _section_.text\n", asm_out_file); + + if (xcoff_tls_exec_model_detected) + { + /* Add a .ref to __tls_get_addr to force libpthread dependency. */ + fputs ("\t.extern __tls_get_addr\n\t.ref __tls_get_addr\n", asm_out_file); + } } struct declare_alias_data