From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by sourceware.org (Postfix) with ESMTPS id D289C3858D3C for ; Mon, 16 May 2022 18:35:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D289C3858D3C Received: from pps.filterd (m0098421.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 24GIV2t0002144; Mon, 16 May 2022 18:35:31 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3g3uy982we-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 16 May 2022 18:35:31 +0000 Received: from m0098421.ppops.net (m0098421.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 24GIVQK1003107; Mon, 16 May 2022 18:35:30 GMT Received: from ppma06ams.nl.ibm.com (66.31.33a9.ip4.static.sl-reverse.com [169.51.49.102]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3g3uy982vr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 16 May 2022 18:35:30 +0000 Received: from pps.filterd (ppma06ams.nl.ibm.com [127.0.0.1]) by ppma06ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 24GIVwnj015306; Mon, 16 May 2022 18:35:29 GMT Received: from b06cxnps4074.portsmouth.uk.ibm.com (d06relay11.portsmouth.uk.ibm.com [9.149.109.196]) by ppma06ams.nl.ibm.com with ESMTP id 3g23pjb3vt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 16 May 2022 18:35:28 +0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 24GIZPbC26607988 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 16 May 2022 18:35:25 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 63505A4055; Mon, 16 May 2022 18:35:25 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0DB78A404D; Mon, 16 May 2022 18:35:25 +0000 (GMT) Received: from heavy.ibmuc.com (unknown [9.171.25.184]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP; Mon, 16 May 2022 18:35:24 +0000 (GMT) From: Ilya Leoshkevich To: Andreas Krebbel Cc: Martin Liska , Alan Modra , binutils@sourceware.org, Ilya Leoshkevich Subject: [PATCH] IBM zSystems: Fix left-shifting negative PCRel32 values (PR gas/29152) Date: Mon, 16 May 2022 20:35:23 +0200 Message-Id: <20220516183523.2466672-1-iii@linux.ibm.com> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-GUID: Q4ozV8tvhC7eDrABqp53ERaBL0OKivHk X-Proofpoint-ORIG-GUID: 2KvRwOWQFc3tXUnFQvqBOgh6fxfq0acU X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.858,Hydra:6.0.486,FMLib:17.11.64.514 definitions=2022-05-16_15,2022-05-16_02,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 adultscore=0 priorityscore=1501 impostorscore=0 phishscore=0 mlxscore=0 spamscore=0 malwarescore=0 clxscore=1011 mlxlogscore=999 bulkscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2205160101 X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 16 May 2022 18:35:33 -0000 s390_insert_operand ()'s val, min and max are encoded PCRel32 values and need to be left-shifted by 1 before being shown to the user. Left-shifting negative values is undefined behavior in C, but the current code does not try to prevent it, causing UBSan to complain. Fix by casting the values to their unsigned equivalents before shifting. --- gas/config/tc-s390.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gas/config/tc-s390.c b/gas/config/tc-s390.c index fb452f8a986..04a3c059c91 100644 --- a/gas/config/tc-s390.c +++ b/gas/config/tc-s390.c @@ -622,9 +622,9 @@ s390_insert_operand (unsigned char *insn, if (operand->flags & S390_OPERAND_PCREL) { - val <<= 1; - min <<= 1; - max <<= 1; + val = (offsetT) ((addressT) val << 1); + min = (offsetT) ((addressT) min << 1); + max = (offsetT) ((addressT) max << 1); } if (file == (char *) NULL) as_bad (err, (int64_t) val, (int64_t) min, (int64_t) max); -- 2.35.1