From patchwork Fri Dec 8 07:01:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 81726 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3D2E3385841E for ; Fri, 8 Dec 2023 07:01:22 +0000 (GMT) X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by sourceware.org (Postfix) with ESMTPS id 467043858C62 for ; Fri, 8 Dec 2023 07:01:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 467043858C62 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 467043858C62 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::436 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702018866; cv=none; b=u5hhnAfgXa8ezS2J+gMZZYjbl5GLhAYB9s2oc09dF1CuL44HdcfxLn3LXf+jfhj/ZUR4W8YB9DlUjO48sqT+jkVDYq4ljz3nBS3uEq60GHjqshvx2NP5Ugpl4A40p+3DApFBTWOdW8vrk4nYsAIfKxHgJaN0Em6kt7m7rN2r89g= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702018866; c=relaxed/simple; bh=Jfze8PNE7zSEiUk9xFBALjdAPXexa52WZsyzx73u4LU=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:From:To; b=WARyuOV5USFPpefFNDm2fiI62t25zEPC88zOqL30RBDHxSTUgJhnOqdmeWrMyzHyaoyPPsDahkzjaxqx+y8naF6BMIU9HdNWUqUN74fD/XkJmMJ3yfszE2xD9FMXIufWvNA20zoWW+IEuh9XsB9gSHZ91eRWevPrRv2dwd4/V8s= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-x436.google.com with SMTP id ffacd0b85a97d-3332e351670so1645089f8f.0 for ; Thu, 07 Dec 2023 23:01:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1702018863; x=1702623663; darn=sourceware.org; h=content-transfer-encoding:in-reply-to:autocrypt:references:cc:to :from:content-language:subject:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to; bh=4BdgSN6Q+dFt/fmKvpVaTFIZWZv+UzVVCGfpqCTC6ow=; b=Ek4ZAsHdBUDP1VUYojXDJbiZ8MEjc3v5YIymg89e58qbhIFGm/MKpFrNc9p/qJqoIf OAVaIozZYp/X8i04UYwSu0tIae1ttRb7FzqSNfJKaFVZ4JDdo4Tn98ybfNqcxk9wwdlo 3Uoo4kL9POhZ1FQZlzh5K2i/cvPLtzoel630eCaSGitvGIq8Nu0la2v/swrwSfKg9aOm awUT/Sv2NQh8/OeZYTc2UZKgM7oZXTs6QhFbVxgzpYlOybz5vYc84RCQVyTpV/ZEzL+c Fg0Q8vcw9Khl9OxVjh7Y8Hx8FoQ5SKgymDrf7EHRfCYfyWUI6V4EWanValKIDPsuJOvB 3K4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702018863; x=1702623663; h=content-transfer-encoding:in-reply-to:autocrypt:references:cc:to :from:content-language:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=4BdgSN6Q+dFt/fmKvpVaTFIZWZv+UzVVCGfpqCTC6ow=; b=ioyguBDudzS2c8xnF2Zf2DXsLpVb8w7bdrM1c77y2Gy4TKWwnybPEZXOl0m8wbdGBU jWc80UgXC1d3KDmKaZQM2wOP3K8BB5PpCI0Ew2bFizcl7XmLLpQxqG0sFw5IUcTDw1Tn QAubDJrybF7OHYBuuNRhhrKG/vUq+jyhJqrPnwb92zGQyhLViybLmxkXrM9hxk66J08S 3BNLMzVSSB2+Fd/ewROYaHiHK6ejrEQ7xqfXnuQwCVA7yGcd9ZY8sJKtcdYZWy8DXGH1 CWbZLWfJJmIwOEWlw0ofPF0g7i7ZFZiUye0JpdkKR4Z8dPNy2LqZEyVv+xbs2HpVbp+6 X0vw== X-Gm-Message-State: AOJu0YxX0dJpzXxtdXefRd7ziyE5i7BBt91U0gxM9ps8rhmjnt8Xu2dq 5fMZMYwof9XjkXKCL9Pk55/n0b7sL4zi7gh//q3y X-Google-Smtp-Source: AGHT+IFSZ5Wsmu7RkkboKZ4YuDwDDwI4yDJPPOZu8ac0ZYY4kk7+DsJZZWpgFIEYSsQz4NUqKCUGxw== X-Received: by 2002:a5d:4d85:0:b0:333:3117:c43e with SMTP id b5-20020a5d4d85000000b003333117c43emr1143230wru.207.1702018862915; Thu, 07 Dec 2023 23:01:02 -0800 (PST) Received: from [10.156.60.236] (ip-037-024-206-209.um08.pools.vodafone-ip.de. [37.24.206.209]) by smtp.gmail.com with ESMTPSA id w13-20020a5d404d000000b003333f9200d8sm1320385wrp.84.2023.12.07.23.01.02 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 07 Dec 2023 23:01:02 -0800 (PST) Message-ID: <00ae907a-8fe1-44b1-9e1f-2c20d33a31a5@suse.com> Date: Fri, 8 Dec 2023 08:01:02 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH 2/3] ELF: reliably invoke md_elf_section_change_hook() Content-Language: en-US From: Jan Beulich To: Binutils Cc: "H.J. Lu" , Alan Modra , Nick Clifton References: <9853a641-73fc-4d47-83aa-1402464d2920@suse.com> Autocrypt: addr=jbeulich@suse.com; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu507c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+3 HYudvpdNK3lLujXeA5fLOH+Z/G9WBc5pFVSMocI71I8bT8lIAzreg0WvkWg5V2WZsUMlnDL9 mpwIGFhlbM3gfDMs7MPMu8YQRFVdUvtSpaAs8OFfGQ0ia3LGZcjA6Ik2+xcqscEJzNH+qh8V m5jjp28yZgaqTaRbg3M/+MTbMpicpZuqF4rnB0AQD12/3BNWDR6bmh+EkYSMcEIpQmBM51qM EKYTQGybRCjpnKHGOxG0rfFY1085mBDZCH5Kx0cl0HVJuQKC+dV2ZY5AqjcKwAxpE75MLFkr wkkEGBECAAkFAlk3nEQCGwwACgkQoDSui/t3IH7nnwCfcJWUDUFKdCsBH/E5d+0ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL In-Reply-To: <9853a641-73fc-4d47-83aa-1402464d2920@suse.com> X-Spam-Status: No, score=-3026.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, 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.30 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: binutils-bounces+patchwork=sourceware.org@sourceware.org ... after any (sub)section change. While certain existing target hooks only look at now_seg, for a few others it looks as if failing to do so could have caused anomalies if sub-sections were used. In any event a subsequent x86 change is going to require the sub-section to be properly in place at the time the hook is invoked. This primarily means for obj_elf_section() to pass the new subsection into obj_elf_change_section(), for it to be set right away (ahead of invoking the hook). While adding the new function parameter, take the opportunity and change two adjacent boolean ones to "bool". Also adjust obj_elf_ident() to invoke the hook after all section changes. (Note that obj_elf_version(), which also changes sections and then changes them back, has no hook invocation at all so far, so none are added. Presumably there is a reason for this difference in behavior.) --- Considering that no caller outside of obj-elf.c cares about the existing "push" and the new "new_subsection" arguments, an alternative might be to drop the "push" one in a prereq patch, thus eliminating the need for this one to touch various targets. Thoughts anyone? --- a/gas/config/obj-elf.c +++ b/gas/config/obj-elf.c @@ -546,8 +546,9 @@ obj_elf_change_section (const char *name bfd_vma attr, int entsize, struct elf_section_match *match_p, - int linkonce, - int push) + bool linkonce, + bool push, + subsegT new_subsection) { asection *old_sec; segT sec; @@ -585,10 +586,10 @@ obj_elf_change_section (const char *name if (old_sec) { sec = old_sec; - subseg_set (sec, 0); + subseg_set (sec, new_subsection); } else - sec = subseg_force_new (name, 0); + sec = subseg_force_new (name, new_subsection); bed = get_elf_backend_data (stdoutput); ssect = (*bed->get_sec_type_attr) (stdoutput, sec); @@ -1103,8 +1104,8 @@ obj_elf_section (int push) bfd_vma attr; bfd_vma gnu_attr; int entsize; - int linkonce; - subsegT new_subsection = -1; + bool linkonce; + subsegT new_subsection = 0; struct elf_section_match match; unsigned long linked_to_section_index = -1UL; @@ -1489,7 +1490,7 @@ obj_elf_section (int push) } obj_elf_change_section (name, type, attr, entsize, &match, linkonce, - push); + push, new_subsection); if (linked_to_section_index != -1UL) { @@ -1497,9 +1498,6 @@ obj_elf_section (int push) elf_section_data (now_seg)->this_hdr.sh_link = linked_to_section_index; /* FIXME: Should we perform some sanity checking on the section index ? */ } - - if (push && new_subsection != -1) - subseg_set (now_seg, new_subsection); } /* Change to the .bss section. */ @@ -2519,9 +2517,17 @@ obj_elf_ident (int ignore ATTRIBUTE_UNUS *p = 0; } else - subseg_set (comment_section, 0); + { + subseg_set (comment_section, 0); +#ifdef md_elf_section_change_hook + md_elf_section_change_hook (); +#endif + } stringer (8 + 1); subseg_set (old_section, old_subsection); +#ifdef md_elf_section_change_hook + md_elf_section_change_hook (); +#endif } #ifdef INIT_STAB_SECTION --- a/gas/config/obj-elf.h +++ b/gas/config/obj-elf.h @@ -198,7 +198,7 @@ extern void obj_elf_data (int); extern void obj_elf_text (int); extern void obj_elf_change_section (const char *, unsigned int, bfd_vma, int, struct elf_section_match *, - int, int); + bool, bool, subsegT); extern void obj_elf_vtable_inherit (int); extern void obj_elf_vtable_entry (int); extern struct fix * obj_elf_get_vtable_inherit (void); --- a/gas/config/tc-arm.c +++ b/gas/config/tc-arm.c @@ -27775,7 +27775,7 @@ start_unwind_section (const segT text_se } obj_elf_change_section (sec_name, type, flags, 0, &match, - linkonce, 0); + linkonce, false, 0); /* Set the section link for index tables. */ if (idx) --- a/gas/config/tc-ia64.c +++ b/gas/config/tc-ia64.c @@ -1139,7 +1139,7 @@ obj_elf_vms_common (int ignore ATTRIBUTE obj_elf_change_section (sec_name, SHT_NOBITS, SHF_ALLOC | SHF_WRITE | SHF_IA_64_VMS_OVERLAID | SHF_IA_64_VMS_GLOBAL, - 0, NULL, 1, 0); + 0, NULL, true, false, 0); S_SET_VALUE (symbolP, 0); S_SET_SIZE (symbolP, size); --- a/gas/config/tc-microblaze.c +++ b/gas/config/tc-microblaze.c @@ -150,7 +150,7 @@ microblaze_s_data (int ignore ATTRIBUTE_ { #ifdef OBJ_ELF obj_elf_change_section (".data", SHT_PROGBITS, SHF_ALLOC+SHF_WRITE, - 0, 0, 0, 0); + 0, 0, false, false, 0); #else s_data (ignore); #endif @@ -163,7 +163,7 @@ microblaze_s_sdata (int ignore ATTRIBUTE { #ifdef OBJ_ELF obj_elf_change_section (".sdata", SHT_PROGBITS, SHF_ALLOC+SHF_WRITE, - 0, 0, 0, 0); + 0, 0, false, false, 0); #else s_data (ignore); #endif @@ -282,7 +282,7 @@ microblaze_s_rdata (int localvar) { /* rodata. */ obj_elf_change_section (".rodata", SHT_PROGBITS, SHF_ALLOC, - 0, 0, 0, 0); + 0, 0, false, false, 0); if (rodata_segment == 0) rodata_segment = subseg_new (".rodata", 0); } @@ -290,7 +290,7 @@ microblaze_s_rdata (int localvar) { /* 1 .sdata2. */ obj_elf_change_section (".sdata2", SHT_PROGBITS, SHF_ALLOC, - 0, 0, 0, 0); + 0, 0, false, false, 0); } #else s_data (ignore); @@ -303,12 +303,12 @@ microblaze_s_bss (int localvar) #ifdef OBJ_ELF if (localvar == 0) /* bss. */ obj_elf_change_section (".bss", SHT_NOBITS, SHF_ALLOC+SHF_WRITE, - 0, 0, 0, 0); + 0, 0, false, false, 0); else if (localvar == 1) { /* sbss. */ obj_elf_change_section (".sbss", SHT_NOBITS, SHF_ALLOC+SHF_WRITE, - 0, 0, 0, 0); + 0, 0, false, false, 0); if (sbss_segment == 0) sbss_segment = subseg_new (".sbss", 0); } --- a/gas/config/tc-mips.c +++ b/gas/config/tc-mips.c @@ -16435,7 +16435,7 @@ s_change_section (int ignore ATTRIBUTE_U section_type = SHT_PROGBITS; obj_elf_change_section (section_name, section_type, section_flag, - section_entry_size, 0, 0, 0); + section_entry_size, 0, false, false, 0); } void --- a/gas/config/tc-msp430.c +++ b/gas/config/tc-msp430.c @@ -622,7 +622,7 @@ msp430_profiler (int dummy ATTRIBUTE_UNU subseg = now_subseg; /* Now go to .profiler section. */ - obj_elf_change_section (".profiler", SHT_PROGBITS, 0, 0, 0, 0, 0); + obj_elf_change_section (".profiler", SHT_PROGBITS, 0, 0, 0, false, false, 0); /* Save flags. */ emit_expr (& exp, 2); --- a/gas/config/tc-rx.c +++ b/gas/config/tc-rx.c @@ -488,7 +488,7 @@ parse_rx_section (char * name) else type = SHT_NOBITS; - obj_elf_change_section (name, type, attr, 0, NULL, false, false); + obj_elf_change_section (name, type, attr, 0, NULL, false, false, 0); } else /* Try not to redefine a section, especially B_1. */ { @@ -503,7 +503,7 @@ parse_rx_section (char * name) | ((flags & SEC_STRINGS) ? SHF_STRINGS : 0) | ((flags & SEC_THREAD_LOCAL) ? SHF_TLS : 0); - obj_elf_change_section (name, type, attr, 0, NULL, false, false); + obj_elf_change_section (name, type, attr, 0, NULL, false, false, 0); } bfd_set_section_alignment (now_seg, align); --- a/gas/config/tc-tic6x.c +++ b/gas/config/tc-tic6x.c @@ -4662,7 +4662,7 @@ tic6x_start_unwind_section (const segT t } obj_elf_change_section (sec_name, type, flags, 0, &match, - linkonce, 0); + linkonce, false, 0); /* Set the section link for index tables. */ if (idx)