From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pl1-x62b.google.com (mail-pl1-x62b.google.com [IPv6:2607:f8b0:4864:20::62b]) by sourceware.org (Postfix) with ESMTPS id 236E03858C2C for ; Sun, 9 Jul 2023 17:46:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 236E03858C2C Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=google.com Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-1b52875b8d9so214165ad.0 for ; Sun, 09 Jul 2023 10:46:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1688924775; x=1691516775; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=j+wEML8Hl0/TD/zPwGehcPKkY9DkIPaZwvpeIQZq3tM=; b=utKHgFWr+Z/FLErHXLKK8ZVUr/AlWIfZ+uGjkzvfQew5hp/q5cmc8wKZ6L8G4pJOjH bAqNlh7yp2NnmVM2cIyUoEV19Gy5AcpMYH2KaZJ5jQV+aL5Q7eNQ58qKMmYyphcjBxqJ /DhiPTjUyMOouhwnQACETl3nS06fwYK9kjLxV9tXPfbR5pb/N9VUO6CNXgDCLSREkolY fEKJ7v08uyRH3tZN7EqoITGpTuAl+BMbJQmu6P+rQlXF5MiD0Xo+wmXYRJsDDF6clEC2 uF5a8SFLjfoiWzjZsUqRwl9DpNmZcxm6VBWpZ4UsL050plV6r8m48/yJbq93AsWk+P0J ALeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688924775; x=1691516775; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=j+wEML8Hl0/TD/zPwGehcPKkY9DkIPaZwvpeIQZq3tM=; b=JRuwX9G+Q2Y04vE7BYNevy2rRdvmHdo3ZTXnQMtNVY1wqZVkUho3T4EdckIeid1DPI nNkVbVPilIP+HBBWOChoJGAhmnCdfXVqHigLWOvtalubR1h2aV/GWjwsKzfK+GtWWwf6 Y+IkihSYyT9ctKuol26toDFA2ORuKR9JSlHlpcJpxvhAk2ZrqMzBPK7WIMnU2bKSZvb5 6+OD7brTLClNia3tuxspGItUtpQzNib4TRZM/Ysn65Wv7r5Hhqur0cWyaS2h2Ou7yrY5 /89PD+37NpnjZySbmvYUQeH+5Q/wErUW/YFQz58uQ82Euks8PqSrQX0ktqPl4MLOkXrB WUcQ== X-Gm-Message-State: ABy/qLZob4WpPP6UszrcfyNCI3+W80WeB9avLiK3BPXJs6K3dL+Csu2G Toi6M5wnuDP2pKv5UAfCPsuGVw== X-Google-Smtp-Source: APBJJlFsiUMof2DSghBbaoCVYOwKwz6Oex8uCEtC/GRzf/cX29NguUcniyVx10VcHixGRuLhcVjdSw== X-Received: by 2002:a17:902:eccc:b0:1b8:a39e:ff50 with SMTP id a12-20020a170902eccc00b001b8a39eff50mr269106plh.13.1688924774672; Sun, 09 Jul 2023 10:46:14 -0700 (PDT) Received: from google.com ([2620:15c:2d3:205:5aa0:7f75:caaa:6c67]) by smtp.gmail.com with ESMTPSA id a6-20020a170902b58600b001b694130c05sm6585362pls.1.2023.07.09.10.46.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Jul 2023 10:46:14 -0700 (PDT) Date: Sun, 9 Jul 2023 10:46:10 -0700 From: Fangrui Song To: Alan Modra Cc: binutils@sourceware.org Subject: Re: [PATCH v4] PR30592 objcopy: allow --set-section-flags to add or remove SHF_X86_64_LARGE Message-ID: <20230709174610.fidml5vy4ue6leme@google.com> References: <20230708053035.528911-1-maskray@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-19.9 required=5.0 tests=BAYES_00,DKIMWL_WL_MED,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,ENV_AND_HDR_SPF_MATCH,FSL_HELO_FAKE,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL 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: On 2023-07-09, Alan Modra wrote: >On Fri, Jul 07, 2023 at 10:30:35PM -0700, Fangrui Song via Binutils wrote: >> +static bool >> +elf_x86_64_copy_private_section_data (bfd *ibfd ATTRIBUTE_UNUSED, >> + asection *isec, >> + bfd *obfd ATTRIBUTE_UNUSED, >> + asection *osec) { >> + /* objcopy --set-section-flags without "large" drops SHF_X86_64_LARGE. */ >> + elf_section_flags (osec) = (elf_section_flags (isec) & ~SHF_X86_64_LARGE); >> + >> + return true; >> +} >> + > >Unlike the other two functions, this one replaces the standard >_bfd_elf_copy_private_section_data. You'll want to call it, and >distinguish between a call from objcopy.c and a call from ldwrite.c. >I think you're OK accessing elf_section_flags for osec without first >checking for an elf bfd, because bfd_copy_private_section_data invokes >the obfd xvec function. Like this: > >static bool >elf_x86_64_copy_private_section_data (bfd *ibfd, asection *isec, > bfd *obfd, asection *osec) >{ > if (!_bfd_elf_copy_private_section_data (ibfd, isec, obfd, osec)) > return false; > > /* objcopy --set-section-flags without "large" drops SHF_X86_64_LARGE. */ > if (ibfd != obfd) > elf_section_flags (osec) &= ~SHF_X86_64_LARGE; > > return true; >} > >The patch looks OK to me with the above replacement. Thank you. I see that we need to call _bfd_elf_copy_private_section_data first to respect a few other properties including sh_entsize and "readonly". For objcopy -I binary -O elf64-x86-64 pr25749-2.c a.o, ibfd may not be an ELF bfd, but obfd is guaranteed to be an ELF bfd. ld/ldwrite.c calls bfd_copy_private_section_data with ibfd == obfd.