From patchwork Tue Jun 20 06:45:43 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Liebler X-Patchwork-Id: 778139 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 3wsJJq6tMZz9s78 for ; Tue, 20 Jun 2017 16:46:03 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="DaYt6sFl"; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:to:from:subject:date:mime-version:content-type :message-id; q=dns; s=default; b=rzYnNhasOGmPFHKuUE8Au5e8d7wooqc U2kcloHESTfoTM0KUv6Nt/B4jQu3wo0F9p7iVBYhsgX8deLKYxacMe0Ib+juutn6 lf98W3HBBkyDKpZdZPrGIFVAOHFVys+kP7xPoxCkFgqW8pqJM2H8lI0dFpDbBPcG +jK6AUt8G4tE= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:to:from:subject:date:mime-version:content-type :message-id; s=default; bh=aehWGGknm2hUrSvbfcBPo7L1f24=; b=DaYt6 sFlSy9AV7EHVmW/vXiUXX7Yscl57HnukO9NvaWGF8yTHxDJnezsP3UOvPsrhRCVN JcsV5ZxTgQUCWdNPWe/4pBF8cE8rlsyvttNzjxv/4v33PqyufCrGHXLITuBDpKlY qGePUMzHX97MUX/u9VfUdVG83z8p6NackpEJU4= Received: (qmail 93999 invoked by alias); 20 Jun 2017 06:45:54 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 93977 invoked by uid 89); 20 Jun 2017 06:45:52 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-23.6 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, KHOP_DYNAMIC, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 spammy= X-HELO: mx0a-001b2d01.pphosted.com To: libc-alpha@sourceware.org From: Stefan Liebler Subject: [PATCH] S390: Save and restore r12 in TLS_IE macro. Date: Tue, 20 Jun 2017 08:45:43 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.1.0 MIME-Version: 1.0 X-TM-AS-GCONF: 00 x-cbid: 17062006-0012-0000-0000-000005511C15 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17062006-0013-0000-0000-000018C1FA2A Message-Id: <7ff67b8d-4e01-6226-db47-e64828bed692@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-06-20_04:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=1 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1703280000 definitions=main-1706200123 Hi, the testcases elf/tst-tls1-static and elf/tst-tls2-static are failing on s390 if gcc is configured with --enable-default-pie: set bar to 1 (LE) get sum of foo and bar (IE) = 0 bar = 0 The linker reports the following error without aborting: elf/tst-tls1-static.o(.text+0x80): invalid instruction for TLS relocation R_390_TLS_LOAD According to binutils, there are only four valid cases for IE -> LE transition: lg %rx,(0,%ry) -> sllg %rx,%ry,0 lg %rx,(%ry,0) -> sllg %rx,%ry,0 lg %rx,(%ry,%r12) -> sllg %rx,%ry,0 lg %rx,(%r12,%ry) -> sllg %rx,%ry,0 Thus I've adjusted the TLS_IE macro in s390 tls-macros.h files in PIC case in order to use r12 for the address of global offset table. The adjusted macro definition is not used if gcc is not configured with --enable-default-pie. Bye. Stefan ChangeLog: * sysdeps/s390/s390-32/tls-macros.h (TLS_IE): Use r12 for GOT address. * sysdeps/s390/s390-64/tls-macros.h (TLS_IE): Likewise. commit a4296064ced57e04172fa5b76675e2690ae03b1e Author: Stefan Liebler Date: Mon Jun 19 17:05:15 2017 +0200 S390: Save and restore r12 in TLS_IE macro. The testcases elf/tst-tls1-static and elf/tst-tls2-static are failing on s390 if gcc is configured with --enable-default-pie. According to binutils, there are only four valid cases for IE -> LE transition: lg %rx,(0,%ry) -> sllg %rx,%ry,0 lg %rx,(%ry,0) -> sllg %rx,%ry,0 lg %rx,(%ry,%r12) -> sllg %rx,%ry,0 lg %rx,(%r12,%ry) -> sllg %rx,%ry,0 Thus I've adjusted the TLS_IE macro in s390 tls-macros.h files in PIC case in order to use r12 for the address of global offset table. The adjusted macro definition is not used if gcc is not configured with --enable-default-pie. ChangeLog: * sysdeps/s390/s390-32/tls-macros.h (TLS_IE): Use r12 for GOT address. * sysdeps/s390/s390-64/tls-macros.h (TLS_IE): Likewise. diff --git a/sysdeps/s390/s390-32/tls-macros.h b/sysdeps/s390/s390-32/tls-macros.h index a4c5fff..153523a 100644 --- a/sysdeps/s390/s390-32/tls-macros.h +++ b/sysdeps/s390/s390-32/tls-macros.h @@ -8,15 +8,17 @@ #ifdef PIC # define TLS_IE(x) \ - ({ unsigned long __offset, __got; \ + ({ unsigned long __offset, __save12; \ __asm__ ("bras %0,1f\n" \ "0:\t.long _GLOBAL_OFFSET_TABLE_-0b\n\t" \ ".long " #x "@gotntpoff\n" \ - "1:\tl %1,0(%0)\n\t" \ - "la %1,0(%1,%0)\n\t" \ + "1:\tlr %1,%%r12\n\t" \ + "l %%r12,0(%0)\n\t" \ + "la %%r12,0(%0,%%r12)\n\t" \ "l %0,4(%0)\n\t" \ - "l %0,0(%0,%1):tls_load:" #x "\n" \ - : "=&a" (__offset), "=&a" (__got) : : "cc" ); \ + "l %0,0(%0,%%r12):tls_load:" #x "\n\t" \ + "lr %%r12,%1\n" \ + : "=&a" (__offset), "=&a" (__save12) : : "cc" ); \ (int *) (__builtin_thread_pointer() + __offset); }) #else # define TLS_IE(x) \ diff --git a/sysdeps/s390/s390-64/tls-macros.h b/sysdeps/s390/s390-64/tls-macros.h index d70ea6c..449a843 100644 --- a/sysdeps/s390/s390-64/tls-macros.h +++ b/sysdeps/s390/s390-64/tls-macros.h @@ -8,13 +8,15 @@ #ifdef PIC # define TLS_IE(x) \ - ({ unsigned long __offset, __got; \ + ({ unsigned long __offset, __save12; \ __asm__ ("bras %0,0f\n\t" \ ".quad " #x "@gotntpoff\n" \ - "0:\tlarl %1,_GLOBAL_OFFSET_TABLE_\n\t" \ + "0:\tlgr %1,%%r12\n\t" \ + "larl %%r12,_GLOBAL_OFFSET_TABLE_\n\t" \ "lg %0,0(%0)\n\t" \ - "lg %0,0(%0,%1):tls_load:" #x "\n" \ - : "=&a" (__offset), "=&a" (__got) : : "cc" ); \ + "lg %0,0(%0,%%r12):tls_load:" #x "\n\t" \ + "lgr %%r12,%1\n" \ + : "=&a" (__offset), "=&a" (__save12) : : "cc" ); \ (int *) (__builtin_thread_pointer() + __offset); }) #else # define TLS_IE(x) \