From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-eopbgr80077.outbound.protection.outlook.com [40.107.8.77]) by sourceware.org (Postfix) with ESMTPS id 165F1385803D for ; Mon, 27 Jun 2022 14:07:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 165F1385803D ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KlrSpO6+jxxZug4Fg9Q2iXfanSElkq5BWrG4AfCPw5Upl+Drv3+/DX/EGV2CJAgp6izKvxG4vyJbmk2+D69CneVZA+onYd2bURyy5hL+2nV9SewLFcmFG60yx4pI91CMI7txgUc/E7wwnHeE9SHqxmjCdebhtKaE4Cx3bTwCf0NhcSlEBaWza33CZZoez4weTaSuszD1b8JB3xRCHwfz5r9k/34l3+XyE7xs3Dxsn0VXGJP3CtAIvVV6fz6pUeKQdzN4YAtrAsjVychUOtyTveYPGX6ZUlTHjar3GVvmx8v7MsOrrkrd8bN22qhtienjCnKZyot8QbNj0VcsQ0P6Wg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=kx/gpdk4KdMsnfcp+TRnVBA2WfW/kWwdTgaZjSCgDwc=; b=FnDaH498ZnSxG3KSpoGIZzQBNfVMyhNs0I067KKnUF/Ni62zZ8Mw9SqYWMNFPP8cf31YUliM3bEGhuOJFcUuKxCeVV4hNsJBUZwO+3tV108tTq9eHWIJjrf74i8sx6CxeHy0Q/EQop33Zl3D0nngZa4lfv6UI+51437snwDLfAb21csqUPbvguiwFDMmPK/fuH7L3sV4O564wh7KJK9CTMMiWouy+qFN9cePjMBldmSNK08JTacSr37J6cvDA1YFKnqQSyRyoJF9iX4Zcko648+nm/HqRBM53VFcag2xTvb2Irox++aC1tyLeBM8EZxFEizYMLpYx6omMJtE4j3ebA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none Received: from VE1PR04MB6560.eurprd04.prod.outlook.com (2603:10a6:803:122::25) by PAXPR04MB8206.eurprd04.prod.outlook.com (2603:10a6:102:1cb::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5373.18; Mon, 27 Jun 2022 14:07:17 +0000 Received: from VE1PR04MB6560.eurprd04.prod.outlook.com ([fe80::dfa:a64a:432f:e26b]) by VE1PR04MB6560.eurprd04.prod.outlook.com ([fe80::dfa:a64a:432f:e26b%7]) with mapi id 15.20.5373.018; Mon, 27 Jun 2022 14:07:17 +0000 Message-ID: <3668dff3-15e3-2db6-4ebc-fb6f62b38668@suse.com> Date: Mon, 27 Jun 2022 16:07:15 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.10.0 Content-Language: en-US To: Binutils Cc: Nick Clifton , Alan Modra , Dave Anglin , Jeff Law , Hans-Peter Nilsson From: Jan Beulich Subject: [PATCH] gas: fix bogus error on .org involving expression Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-ClientProxiedBy: AM5PR1001CA0045.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:206:15::22) To VE1PR04MB6560.eurprd04.prod.outlook.com (2603:10a6:803:122::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 6b0fbdeb-b70a-4143-0be4-08da584657eb X-MS-TrafficTypeDiagnostic: PAXPR04MB8206:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Anvy+NNh3Cc7Ja0didN4bH7Wcv01jWmVkyyL3bJ+5Hsh1oNO0CnaJgecIiINiQOXVdXSsy6Ydv7IZO3lkW1NLYSMfB9yIr07XFZsk/4SrE7KP+lLm0XRebCDPPkUWRagflPTDXkxde5jExd58mdBfatBeThS7E1MohQG4qMRjnCZmSt6J+ObAVvjdR+Dydz2V5bcPY1M6EifTJ+Phnl96QRYfdMVAFEpjnJs3ULa2HeRv8uzOXyxQEgHMtoSbteav9bTY6raUIDGDkcJZ60haRNppUjdWm+8NC6oIth6/3xK9uOuzJcfVdMJBKMnCvnsZpBfWpF1UB5EPdtvTrAQI0HGD2DSTidBGtTkFicGqNPDku4zGFMUL0CgyOZV3Dfijrwh3KM5QXMKt3H8omoaO8EZZ5j9aHPexLcy0SkQAcZmZJomvtqofyiYnnvEsa+VzPmp46RgtidaULkLov5dn2RNf5mPmaGsh1xo18lDhiUVYrXzgrboqnxmPdTALNR9Nez9hGzVbT26fee0QHAKTDVrnKY1ERfWeTXFY09LdEHeJIeN8JnYO/ZCim3QBfVJ5gNK2942yu1jIvUJEtlA9yIfJihWyfBUn4UpWZCkc+sRj5KsqDDBR2+7mJnPzsvZ2SWM8p33wH6Gu57jli292SMDq0PTNM5Q4TVKkgF7I9Vj1KG3/86D+6szpjx3wQWrBjeBwdaF0Ddzz++vx9QbHt3OSf1PpZAXPCCWGXLFp7evbYacVfH4vjkAh22HZev6ZHlxNU5tKDIHFA5SflebR109xsmIbTI5xvHWEQ4sQv9axkvOaOb4p1txHSJuQW5S0KqVmKKP1kpSnAS/GjY9puDVqTXI6XCK8AB1BtnAi0g= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:VE1PR04MB6560.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230016)(396003)(39860400002)(136003)(346002)(376002)(366004)(5660300002)(2616005)(316002)(66476007)(66556008)(8936002)(6486002)(41300700001)(83380400001)(186003)(6512007)(6506007)(36756003)(478600001)(26005)(86362001)(31696002)(66946007)(6916009)(38100700002)(31686004)(4326008)(2906002)(54906003)(8676002)(142923001)(43740500002)(45980500001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?V2FtRUFsMDUrK0NXZncvcWwzQWtLRjBDb2VNbWNkdlN4U2t1dFExMDZYd3Uz?= =?utf-8?B?V0ErV3dpZWhsTGR5eGVhV2RCOEZCM1ZsVWxXUEp2bmdnT2hteFFoaEJMalRO?= =?utf-8?B?RHBoOU42ZldyZEVTckxNdmhGaUt2a2Z5SFNwZ1Bid01KM0x3QkcrQUU1VDRk?= =?utf-8?B?d3FCbzhmYWJNbU9OVXFPS3ZMM0djM2NlY3Z6SDR0MnZTVWl4WEZZQTcrVVEw?= =?utf-8?B?OFVQc3ZCVk9SZ3N5VjRmTnJBc29hVllNZjRXL3RyL3BHK1hNR0crcTZ0ZkZC?= =?utf-8?B?L1JFZ2gyb1k4Ty9MMkNxaWVocHNYcmlQQ2daRXF1eWRaRE96c0VLVTA1amxo?= =?utf-8?B?YjNmeU50eXdkR2hYdTNVYUtMNmQ1NERQeENBU2V0S3BWRWZ5RmRWYUQzd0Fq?= =?utf-8?B?bDNmLytFV2hPWWMwMG1aMmdZT3JobittdGpwMUFRUzdWcUhXYUdUK2xYY2Zr?= =?utf-8?B?Rlh6Z2ZjeUV3aEtpbkhHMDJHZHQvU0tDdzhxcTFPQ04zY1R2WC9ISGphNlBP?= =?utf-8?B?TUJCV0RYZXVLTUJxNjVSdXY4YUZWSzd4VDZZVXdBREx4ekEwTUNrMXBHV3hy?= =?utf-8?B?V3ZBN0U3Qyt4N0ZyRm9PU0pMWnlkZWUvOTRBdE02RVNRUVl0ckh3OEFCME5K?= =?utf-8?B?bldNOWtKdWNydzZSYU0vRFZpRFV2OS8rdUpIZW9Ja01scmlCRkplYW82YVRD?= =?utf-8?B?dzNQYWI2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lhu?= =?utf-8?B?OUREOHkvYjZXdndYOUU3ZFN3Y0JYVWZwTnhBM3lNekovVGlCOERGUW1zWll1?= =?utf-8?B?M1FFck8vam9hMWJvZ0NGcEh5Q2hOTjFWYWYzeDRDSVN2QVhtLzdhZnpjN0VP?= =?utf-8?B?eTRiMlRUelcvRnE3anBDcVZCYk9LY2Fpa0hDcW5ITUxwTE9WUFFEeDVVL0hB?= =?utf-8?B?a3gwSG1iOEVsWGNFOHR6cFdxZk10QlMzaXM2V0VMOVlFRXR1OGFXWURwcU51?= =?utf-8?B?cFNrdXdnQ0lDTEpGVFNxK2s4NXAyQmxkenNFSmRiSUdGQ1p5bUp3NkthNkMw?= =?utf-8?B?L3p5V29IRkx2MmhsZWtwREdzaVFTazRod2pEOVFkaGwyQm1KZklNNEg5T2pH?= =?utf-8?B?aUQxKzJaSEFPbzVaT05EckVVa2xiVmdOSXAxeVY4NnR3dFA5N2F6c09uT29l?= =?utf-8?B?dWZKTThkRzhaL29RMU44RmFUazlUaDhpM3pPVXNBRGhCZ0U5enpETXlxRThm?= =?utf-8?Q?0jRarnxq+rd2pEqnB5KLED0ii?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6b0fbdeb-b70a-4143-0be4-08da584657eb X-MS-Exchange-CrossTenant-AuthSource: VE1PR04MB6560.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jun 2022 14:07:17.3573 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f7a17af6-1c5c-4a36-aa8b-f5be247aa4ba X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: gPC4RRE6aXmhiT4uWiC8295m9u81KQnu4vmC84yRc82GBLTBkosiVUSKAyTDCCSfJismomDovwSmXipMdyEviQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR04MB8206 X-Spam-Status: No, score=-3030.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, 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, 27 Jun 2022 14:07:22 -0000 For years I have been carrying this change, and it was long forgotten what it was originally meant to deal with, hence I've never submitted it. Until I came across an issue with Linux-kernel-like alternative instruction patching, where the space needed to hold the replacement instruction was allocated using .org. Things built fine for me (since I had the patch in place), and things also built fine on 2.20. But assemblers from at least 2.22 onwards produce an undefined symbol warning for the "orig" label in the new test case, followed by an error complaining that .org would be moving backwards (which is a logical consequence of the undefined symbol getting replaced by plain zero). The cvt_frag_to_fill() change is to deal with targets setting TC_FINALIZE_SYMS_BEFORE_SIZE_SEG to zero. Such targets skip the report_op_error() invocation in resolve_symbol_value(), when called from S_GET_VALUE() a few lines up from where the change is being made. (This in turn leads to the elf/bad-group testcase failing, or more generally .sleb128 / .uleb128 otherwise silently accepting expressions which weren't actually resolved.) This change in turn depends on the hackish change to resolve_symbol_value(). All of this feels generally wrong, so quite likely this change is only papering over an issue elsewhere, or similar checks may need adding in further places (which I haven't managed to discover yet). --- Otoh the asymmetry of the code being changed in resolve_symbol_value() looks bogus as well. To just name a few aspects: - at least for commutative operators it's not clear why seg_left and seg_right should be treated differently, - - doesn't really make sense to "live" in the symbol's section, - yet more complex expressions don't really make sense to "live" in any "normal" section, - at least all relational operators really have absolute results. --- a/gas/config/tc-hppa.c +++ b/gas/config/tc-hppa.c @@ -1282,6 +1282,7 @@ get_expression (char *str) input_line_pointer = str; seg = expression (&the_insn.exp); if (!(seg == absolute_section + || seg == expr_section || seg == undefined_section || SEG_NORMAL (seg))) { --- a/gas/config/tc-i386.c +++ b/gas/config/tc-i386.c @@ -10894,6 +10894,7 @@ i386_finalize_immediate (segT exp_seg AT && exp_seg != text_section && exp_seg != data_section && exp_seg != bss_section + && exp_seg != expr_section && exp_seg != undefined_section && !bfd_is_com_section (exp_seg)) { @@ -11192,6 +11193,7 @@ i386_finalize_displacement (segT exp_seg && exp_seg != text_section && exp_seg != data_section && exp_seg != bss_section + && exp_seg != expr_section && exp_seg != undefined_section && !bfd_is_com_section (exp_seg)) { --- a/gas/config/tc-mmix.c +++ b/gas/config/tc-mmix.c @@ -2025,7 +2025,7 @@ mmix_greg_internal (char *label) expP->X_op_symbol = NULL; } - if (section == undefined_section) + if (section == undefined_section || section == expr_section) { /* This is an error or a LOC with an expression involving forward references. For the expression to be correctly @@ -3967,7 +3967,7 @@ s_loc (int ignore ATTRIBUTE_UNUSED) return; } - if (section == undefined_section) + if (section == undefined_section || section == expr_section) { /* This is an error or a LOC with an expression involving forward references. For the expression to be correctly @@ -4058,7 +4058,9 @@ s_loc (int ignore ATTRIBUTE_UNUSED) /* If we can't deduce the section, it must be the current one. Below, we arrange to assert this. */ - if (section != now_seg && section != undefined_section) + if (section != now_seg + && section != undefined_section + && section != expr_section) { obj_elf_section_change_hook (); subseg_set (section, 0); @@ -4082,7 +4084,7 @@ s_loc (int ignore ATTRIBUTE_UNUSED) sym = exp.X_add_symbol; off = exp.X_add_number; - if (section == undefined_section) + if (section == undefined_section || section == expr_section) { /* We need an expr_symbol when tracking sections. In order to make this an expr_symbol with file and line @@ -4096,7 +4098,7 @@ s_loc (int ignore ATTRIBUTE_UNUSED) /* Track the LOC's where we couldn't deduce the section: assert that we weren't supposed to change section. */ - if (section == undefined_section) + if (section == undefined_section || section == expr_section) { struct loc_assert_s *next = loc_asserts; loc_asserts = XNEW (struct loc_assert_s); --- a/gas/expr.c +++ b/gas/expr.c @@ -2048,7 +2048,11 @@ expr (int rankarg, /* Larger # is highe retval = absolute_section; rightseg = absolute_section; } + else + retval = expr_section; } + else + retval = expr_section; } else { @@ -2060,17 +2064,18 @@ expr (int rankarg, /* Larger # is highe resultP->X_add_number = 0; resultP->X_unsigned = 1; resultP->X_extrabit = 0; + retval = expr_section; } if (retval != rightseg) { - if (retval == undefined_section) + if (retval == expr_section) ; - else if (rightseg == undefined_section) + else if (rightseg == expr_section) retval = rightseg; - else if (retval == expr_section) + else if (retval == undefined_section) ; - else if (rightseg == expr_section) + else if (rightseg == undefined_section) retval = rightseg; else if (retval == reg_section) ; --- a/gas/symbols.c +++ b/gas/symbols.c @@ -1660,7 +1660,11 @@ resolve_symbol_value (symbolS *symp) final_seg = undefined_section; else if (seg_left == absolute_section) final_seg = seg_right; +#if defined (TC_FINALIZE_SYMS_BEFORE_SIZE_SEG) && !TC_FINALIZE_SYMS_BEFORE_SIZE_SEG + else if (finalize_syms || seg_right == absolute_section) +#else else +#endif final_seg = seg_left; } resolved = (symbol_resolved_p (add_symbol) --- /dev/null +++ b/gas/testsuite/gas/all/expr-org.d @@ -0,0 +1,11 @@ +#objdump: -s -j .data -j .alt +#name: .org with expression (with forward reference) + +.*: .* + +Contents of section \.data: + 0000 [0f][0f]ffff[0f][0f] 01[0 .]* + +Contents of section \.alt: + 0000 00000000 [ .]* +#pass --- /dev/null +++ b/gas/testsuite/gas/all/expr-org.s @@ -0,0 +1,10 @@ + .data +orig: + .byte 0 + .org orig + (alt_end - alt_begin), 0xff + .pushsection .alt, "a", %progbits +alt_begin: + .long 0 +alt_end: + .popsection + .byte 1 --- a/gas/testsuite/gas/all/gas.exp +++ b/gas/testsuite/gas/all/gas.exp @@ -457,6 +457,11 @@ gas_test_error "weakref4.s" "" "is alrea run_dump_test string if [is_elf_format] { run_dump_test none + +# Targets enabling OBJ_COMPLEX_RELC don't seem to be compatible with this. + if { ![istarget "mep-*-*"] } { + run_dump_test expr-org + } } run_dump_test quoted-sym-names --- a/gas/write.c +++ b/gas/write.c @@ -467,6 +467,9 @@ cvt_frag_to_fill (segT sec ATTRIBUTE_UNU _("leb128 operand is an undefined symbol: %s"), S_GET_NAME (fragP->fr_symbol)); } + else if (S_GET_SEGMENT (fragP->fr_symbol) == expr_section) + as_bad_where (fragP->fr_file, fragP->fr_line, + _("leb128 operand is an unresolved expression")); size = output_leb128 (fragP->fr_literal + fragP->fr_fix, value, fragP->fr_subtype);