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 2D07C38618BE for ; Thu, 15 Feb 2024 15:58:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2D07C38618BE Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=linux.ibm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linux.ibm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 2D07C38618BE Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=148.163.158.5 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708012717; cv=none; b=Jkbb2joIa2Kvwk8wXeyhsa53QdQcYRrduAokB0Lqw3B3SAor4YmbLhLrYUST6jBzyisqbzcZnRsZm2qnyjzz8no5QwZvfFmwJ6cD7Kbjuq7zLVGdvHzXq5TiO1O+681J684h1YyA3Kqxy9tneHDKCYCcoSVygeoKerUIbSzgZRc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708012717; c=relaxed/simple; bh=tIqYD4/7kF6m9w+/glWW7UOSY1VJcwl2pP26l/7FMhU=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=QuK8oTIrsIn752myv8SUo/Zg8MfTjc+Twt4N2+0VF5kvj4E0XGq+XKb0JR9nj4AVRMHCMZlAXlxbUsyozN/ooz4uapn9Nl/gWfcSNsUulr8WpS1exWBPhvFJ8cI6h5/fP8/ANsSd5Xpx0OGiIszylmIObtElqAKH9E0rqOZbONM= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0353724.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 41FFlULL014342 for ; Thu, 15 Feb 2024 15:58:34 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=w87Qpi4BkwYeSOiUsgxTx4A1lFHI2tPbGTphQs/Nf5k=; b=E1ZQOm6k5rO2BMlS3ZtEhWoilGbSueXBeAfSWzJW2WApxwYCksaiLw9K/IviNnwHu7ED kO0wMlN9UpZ0BTU8J3LAc+9eteV7PTnpkYNOkHEI6Z9YqPJ73/kwSy0q8RIc9MRNVUKL fxJ5tjOaFu70UsBimaef24oth19qKnzIZ3CnI4s9NTKLUQvycJvLmpFao/pkqq1nz9GY mahAlZi8NqW0Jho7TOpyHS2OMnr8eiIKI4ZGeDErOU9khohP4G7lEN39wTJIP4Spy7xH OsOPgyPzWvHH114PaM/muZP1MKy86GdTxnwQEM95Ih521mKf8M6fF8lJJEyMMwLThf65 Bg== Received: from ppma21.wdc07v.mail.ibm.com (5b.69.3da9.ip4.static.sl-reverse.com [169.61.105.91]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3w9nje872f-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 15 Feb 2024 15:58:34 +0000 Received: from pps.filterd (ppma21.wdc07v.mail.ibm.com [127.0.0.1]) by ppma21.wdc07v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 41FDjPSL024888 for ; Thu, 15 Feb 2024 15:58:34 GMT Received: from smtprelay07.fra02v.mail.ibm.com ([9.218.2.229]) by ppma21.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3w6mfpnq6a-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 15 Feb 2024 15:58:33 +0000 Received: from smtpav04.fra02v.mail.ibm.com (smtpav04.fra02v.mail.ibm.com [10.20.54.103]) by smtprelay07.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 41FFwSIW27722398 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 15 Feb 2024 15:58:30 GMT Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B725120063; Thu, 15 Feb 2024 15:58:28 +0000 (GMT) Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 91DDD2005A; Thu, 15 Feb 2024 15:58:28 +0000 (GMT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by smtpav04.fra02v.mail.ibm.com (Postfix) with ESMTP; Thu, 15 Feb 2024 15:58:28 +0000 (GMT) From: Jens Remus To: binutils@sourceware.org Cc: Jens Remus , Andreas Krebbel Subject: [PATCH 04/14] s390: Correct setting of highgprs flag in ELF output Date: Thu, 15 Feb 2024 16:58:11 +0100 Message-Id: <20240215155821.4065623-5-jremus@linux.ibm.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240215155821.4065623-1-jremus@linux.ibm.com> References: <20240215155821.4065623-1-jremus@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: c9bsX4KSYzCWFLSHRyq_eiNXo7ZX1dnD X-Proofpoint-GUID: c9bsX4KSYzCWFLSHRyq_eiNXo7ZX1dnD X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-15_14,2024-02-14_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 mlxscore=0 phishscore=0 priorityscore=1501 adultscore=0 lowpriorityscore=0 bulkscore=0 clxscore=1015 malwarescore=0 spamscore=0 impostorscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402150129 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_H3,RCVD_IN_MSPIKE_WL,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 List-Id: The combination of an architecture size of 32 bits and z/Architecture mode requires the highgprs flag to be set in the ELF output. It causes the high-halves of the general purpose registers (GPRs) to be preserved at run-time, so that the code can use 64-bit GPRs. The architecture size of 32 bits can either be the default in case of a default architecture name of "s390" or due to specification of the option -m31 (to generate the 31-bit file format). The z/Architecture mode can either be the default or due to specification of the option -mzarch (to assemble for z/Architecture mode). It can also be selected using the pseudo commands ".machinemode zarch" and ".machinemode zarch_nohighgprs". The latter not causing the highgprs flag to be set. The highgprs flag was only set when the following s390-specific assembler options were given in the following specific order: "-m31 -mzarch". The highgprs flag was erroneously not set when: - the order of above options was inverse (i.e. "-mzarch -m31"), - the architecture mode defaulted to z/Architecture mode and option "-m31" was specified, - the architecture size defaulted to 32 bits due to a default architecture name of "s390" and option -mzarch was specified, - the architecture size defaulted to 32 bits and the architecture mode defaulted to z/Architecture due to the specified processor (e.g. "-march=z900" or follow-on processor). Determine whether to set the highgprs flag in init_default_arch() after having processed all assembler options in md_parse_option(). This ensures the flag is set in all of the above cases it was erroneously not set. Add test cases for highgprs flag, including ones that use .machinemode to switch the architecture mode. gas/ * config/tc-s390.c: Correct setting of highgprs flag in ELF output. * testsuite/gas/s390/s390.exp: Add test cases for highgprs flag. * testsuite/gas/s390/blank.s: Empty assembler source used in test cases for "highgprs" flag. * testsuite/gas/s390/esa-highgprs-0.d: Add test case for highgprs flag. * testsuite/gas/s390/zarch-highgprs-0.d: Likewise. * testsuite/gas/s390/zarch-highgprs-1.d: Likewise. * testsuite/gas/s390/esa-highgprs-machinemode-0.s: Add test case for highgprs flag when using .machinemode to switch architecture mode. * testsuite/gas/s390/esa-highgprs-machinemode-0.d: Likewise. * testsuite/gas/s390/esa-highgprs-machinemode-1.s: Likewise. * testsuite/gas/s390/esa-highgprs-machinemode-1.d: Likewise. Reviewed-by: Andreas Krebbel Signed-off-by: Jens Remus --- gas/config/tc-s390.c | 14 ++++++----- gas/testsuite/gas/s390/blank.s | 0 gas/testsuite/gas/s390/esa-highgprs-0.d | 24 +++++++++++++++++++ .../gas/s390/esa-highgprs-machinemode-0.d | 23 ++++++++++++++++++ .../gas/s390/esa-highgprs-machinemode-0.s | 2 ++ .../gas/s390/esa-highgprs-machinemode-1.d | 23 ++++++++++++++++++ .../gas/s390/esa-highgprs-machinemode-1.s | 3 +++ gas/testsuite/gas/s390/s390.exp | 12 ++++++++++ gas/testsuite/gas/s390/zarch-highgprs-0.d | 24 +++++++++++++++++++ gas/testsuite/gas/s390/zarch-highgprs-1.d | 24 +++++++++++++++++++ 10 files changed, 143 insertions(+), 6 deletions(-) create mode 100644 gas/testsuite/gas/s390/blank.s create mode 100644 gas/testsuite/gas/s390/esa-highgprs-0.d create mode 100644 gas/testsuite/gas/s390/esa-highgprs-machinemode-0.d create mode 100644 gas/testsuite/gas/s390/esa-highgprs-machinemode-0.s create mode 100644 gas/testsuite/gas/s390/esa-highgprs-machinemode-1.d create mode 100644 gas/testsuite/gas/s390/esa-highgprs-machinemode-1.s create mode 100644 gas/testsuite/gas/s390/zarch-highgprs-0.d create mode 100644 gas/testsuite/gas/s390/zarch-highgprs-1.d diff --git a/gas/config/tc-s390.c b/gas/config/tc-s390.c index cfe98b5e94be..55a5873edc18 100644 --- a/gas/config/tc-s390.c +++ b/gas/config/tc-s390.c @@ -47,7 +47,7 @@ static unsigned int current_flags = S390_INSTR_FLAG_FACILITY_MASK; static unsigned int current_mode_mask = 0; /* Set to TRUE if the highgprs flag in the ELF header needs to be set - for the output file. */ + for the output file. The default is picked in init_default_arch(). */ static bool set_highgprs_p = false; /* Whether to use user friendly register names. Default is TRUE. */ @@ -221,6 +221,7 @@ size_t md_longopts_size = sizeof (md_longopts); static void init_default_arch (void) { + /* Default architecture size. */ if (strcmp (default_arch, "s390") == 0) { if (s390_arch_size == 0) @@ -234,6 +235,7 @@ init_default_arch (void) else as_fatal (_("Invalid default architecture, broken assembler.")); + /* Default current architecture mode. */ if (current_mode_mask == 0) { /* Default to z/Architecture mode if the CPU supports it. */ @@ -242,6 +244,10 @@ init_default_arch (void) else current_mode_mask = 1 << S390_OPCODE_ZARCH; } + + /* Determine whether the highgprs flag in the ELF header needs to be set. */ + if ((s390_arch_size == 32) && (current_mode_mask & (1 << S390_OPCODE_ZARCH))) + set_highgprs_p = true; } /* Called by TARGET_FORMAT. */ @@ -419,11 +425,7 @@ md_parse_option (int c, const char *arg) current_mode_mask = 1 << S390_OPCODE_ESA; else if (arg != NULL && strcmp (arg, "zarch") == 0) - { - if (s390_arch_size == 32) - set_highgprs_p = true; - current_mode_mask = 1 << S390_OPCODE_ZARCH; - } + current_mode_mask = 1 << S390_OPCODE_ZARCH; else if (arg != NULL && startswith (arg, "arch=")) { diff --git a/gas/testsuite/gas/s390/blank.s b/gas/testsuite/gas/s390/blank.s new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/gas/testsuite/gas/s390/esa-highgprs-0.d b/gas/testsuite/gas/s390/esa-highgprs-0.d new file mode 100644 index 000000000000..aa9eff70cfeb --- /dev/null +++ b/gas/testsuite/gas/s390/esa-highgprs-0.d @@ -0,0 +1,24 @@ +#name: s390 highgprs 0 +#source: blank.s +#readelf: -h + +ELF Header: + Magic: 7f 45 4c 46 01 02 01 00 00 00 00 00 00 00 00 00 + Class: ELF32 + Data: 2's complement, big endian + Version: 1 \(current\) + OS/ABI: UNIX - System V + ABI Version: 0 + Type: REL \(Relocatable file\) + Machine: IBM S/390 + Version: 0x1 + Entry point address: 0x0 + Start of program headers: 0 \(bytes into file\) + Start of section headers: 164 \(bytes into file\) + Flags: 0x0 + Size of this header: 52 \(bytes\) + Size of program headers: 0 \(bytes\) + Number of program headers: 0 + Size of section headers: 40 \(bytes\) + Number of section headers: 7 + Section header string table index: 6 diff --git a/gas/testsuite/gas/s390/esa-highgprs-machinemode-0.d b/gas/testsuite/gas/s390/esa-highgprs-machinemode-0.d new file mode 100644 index 000000000000..483342f3f8bd --- /dev/null +++ b/gas/testsuite/gas/s390/esa-highgprs-machinemode-0.d @@ -0,0 +1,23 @@ +#name: s390 highgprs machinemode 0 +#readelf: -h + +ELF Header: + Magic: 7f 45 4c 46 01 02 01 00 00 00 00 00 00 00 00 00 + Class: ELF32 + Data: 2's complement, big endian + Version: 1 \(current\) + OS/ABI: UNIX - System V + ABI Version: 0 + Type: REL \(Relocatable file\) + Machine: IBM S/390 + Version: 0x1 + Entry point address: 0x0 + Start of program headers: 0 \(bytes into file\) + Start of section headers: 164 \(bytes into file\) + Flags: 0x0 + Size of this header: 52 \(bytes\) + Size of program headers: 0 \(bytes\) + Number of program headers: 0 + Size of section headers: 40 \(bytes\) + Number of section headers: 7 + Section header string table index: 6 diff --git a/gas/testsuite/gas/s390/esa-highgprs-machinemode-0.s b/gas/testsuite/gas/s390/esa-highgprs-machinemode-0.s new file mode 100644 index 000000000000..60d9e3f56781 --- /dev/null +++ b/gas/testsuite/gas/s390/esa-highgprs-machinemode-0.s @@ -0,0 +1,2 @@ +.text + .machinemode zarch_nohighgprs diff --git a/gas/testsuite/gas/s390/esa-highgprs-machinemode-1.d b/gas/testsuite/gas/s390/esa-highgprs-machinemode-1.d new file mode 100644 index 000000000000..c1adc1603b23 --- /dev/null +++ b/gas/testsuite/gas/s390/esa-highgprs-machinemode-1.d @@ -0,0 +1,23 @@ +#name: s390 highgprs machinemode 1 +#readelf: -h + +ELF Header: + Magic: 7f 45 4c 46 01 02 01 00 00 00 00 00 00 00 00 00 + Class: ELF32 + Data: 2's complement, big endian + Version: 1 \(current\) + OS/ABI: UNIX - System V + ABI Version: 0 + Type: REL \(Relocatable file\) + Machine: IBM S/390 + Version: 0x1 + Entry point address: 0x0 + Start of program headers: 0 \(bytes into file\) + Start of section headers: 164 \(bytes into file\) + Flags: 0x1, highgprs + Size of this header: 52 \(bytes\) + Size of program headers: 0 \(bytes\) + Number of program headers: 0 + Size of section headers: 40 \(bytes\) + Number of section headers: 7 + Section header string table index: 6 diff --git a/gas/testsuite/gas/s390/esa-highgprs-machinemode-1.s b/gas/testsuite/gas/s390/esa-highgprs-machinemode-1.s new file mode 100644 index 000000000000..c46b95b7e95d --- /dev/null +++ b/gas/testsuite/gas/s390/esa-highgprs-machinemode-1.s @@ -0,0 +1,3 @@ +.text + .machinemode zarch + .machinemode esa diff --git a/gas/testsuite/gas/s390/s390.exp b/gas/testsuite/gas/s390/s390.exp index 7fbc7f8a7515..b63c09e40324 100644 --- a/gas/testsuite/gas/s390/s390.exp +++ b/gas/testsuite/gas/s390/s390.exp @@ -12,6 +12,16 @@ if [expr [istarget "s390-*-*"] || [istarget "s390x-*-*"]] then { run_dump_test "esa-z9-109" "{as -m31} {as -march=z9-109}" run_dump_test "esa-reloc" "{as -m31}" run_dump_test "esa-operands" "{as -m31}" + run_dump_test "esa-highgprs-0" "{as -m31} {as -mesa}" + run_dump_test "esa-highgprs-0" "{as -mesa} {as -m31}" + run_dump_test "esa-highgprs-0" "{as -m31} {as -march=g5}" + run_dump_test "zarch-highgprs-1" "{as -m31} {as -mzarch}" + run_dump_test "zarch-highgprs-1" "{as -mzarch} {as -m31}" + run_dump_test "zarch-highgprs-1" "{as -m31} {as -march=z900}" + run_dump_test "esa-highgprs-machinemode-0" "{as -m31} {as -mesa}" + run_dump_test "esa-highgprs-machinemode-0" "{as -mesa} {as -m31}" + run_dump_test "esa-highgprs-machinemode-1" "{as -m31} {as -mesa}" + run_dump_test "esa-highgprs-machinemode-1" "{as -mesa} {as -m31}" } # # PIC is only supported on ELF targets. @@ -44,6 +54,8 @@ if [expr [istarget "s390-*-*"] || [istarget "s390x-*-*"]] then { run_list_test "machine-parsing-4" "" run_list_test "machine-parsing-5" "" run_list_test "machine-parsing-6" "" + run_dump_test "zarch-highgprs-0" "{as -m64} {as -mzarch}" + run_dump_test "zarch-highgprs-0" "{as -mzarch} {as -m64}" run_dump_test "zarch-omitted-base-index" "{as -m64}" run_list_test "zarch-omitted-base-index-err" "" } diff --git a/gas/testsuite/gas/s390/zarch-highgprs-0.d b/gas/testsuite/gas/s390/zarch-highgprs-0.d new file mode 100644 index 000000000000..53cc3e057652 --- /dev/null +++ b/gas/testsuite/gas/s390/zarch-highgprs-0.d @@ -0,0 +1,24 @@ +#name: s390x highgprs 0 +#source: blank.s +#readelf: -h + +ELF Header: + Magic: 7f 45 4c 46 02 02 01 00 00 00 00 00 00 00 00 00 + Class: ELF64 + Data: 2's complement, big endian + Version: 1 \(current\) + OS/ABI: UNIX - System V + ABI Version: 0 + Type: REL \(Relocatable file\) + Machine: IBM S/390 + Version: 0x1 + Entry point address: 0x0 + Start of program headers: 0 \(bytes into file\) + Start of section headers: 208 \(bytes into file\) + Flags: 0x0 + Size of this header: 64 \(bytes\) + Size of program headers: 0 \(bytes\) + Number of program headers: 0 + Size of section headers: 64 \(bytes\) + Number of section headers: 7 + Section header string table index: 6 diff --git a/gas/testsuite/gas/s390/zarch-highgprs-1.d b/gas/testsuite/gas/s390/zarch-highgprs-1.d new file mode 100644 index 000000000000..d351032fbc47 --- /dev/null +++ b/gas/testsuite/gas/s390/zarch-highgprs-1.d @@ -0,0 +1,24 @@ +#name: s390x highgprs 0 +#source: blank.s +#readelf: -h + +ELF Header: + Magic: 7f 45 4c 46 01 02 01 00 00 00 00 00 00 00 00 00 + Class: ELF32 + Data: 2's complement, big endian + Version: 1 \(current\) + OS/ABI: UNIX - System V + ABI Version: 0 + Type: REL \(Relocatable file\) + Machine: IBM S/390 + Version: 0x1 + Entry point address: 0x0 + Start of program headers: 0 \(bytes into file\) + Start of section headers: 164 \(bytes into file\) + Flags: 0x1, highgprs + Size of this header: 52 \(bytes\) + Size of program headers: 0 \(bytes\) + Number of program headers: 0 + Size of section headers: 40 \(bytes\) + Number of section headers: 7 + Section header string table index: 6 -- 2.40.1