From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1062) id AE384384B112; Tue, 23 Apr 2024 12:38:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AE384384B112 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1713875885; bh=WaxXV4LirdrD4dseYu9CDZ/VxyEZySSS/k3Jd6QNnG4=; h=From:To:Subject:Date:From; b=JPFMz+cE7USP/zp2QkoyE8FAluMRFnwiHiKUr0P7e4c2Jo58jWIhcGNLVfwoEWxD9 a+0XpSaE1xCLDMeifzYDjNNU+XS9AulnzUXLsYX+ksvwmdnZbIEdScOM8dVZCpSVar UO+2cxzhZfZotVYmVie5EJ0X8Mwk/Wp24+UnLUM4= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Alan Modra To: binutils-cvs@sourceware.org Subject: [binutils-gdb] PR31667, objcopy/strip corrupts solaris binaries X-Act-Checkin: binutils-gdb X-Git-Author: Alan Modra X-Git-Refname: refs/heads/master X-Git-Oldrev: ef1c830f003acaf149bb9ee230be0d0067e1855c X-Git-Newrev: e79ee36b5ae4b60853e91896758bade48e804030 Message-Id: <20240423123805.AE384384B112@sourceware.org> Date: Tue, 23 Apr 2024 12:38:05 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3De79ee36b5ae4= b60853e91896758bade48e804030 commit e79ee36b5ae4b60853e91896758bade48e804030 Author: Alan Modra Date: Mon Apr 22 19:08:51 2024 +0930 PR31667, objcopy/strip corrupts solaris binaries =20 Using want_p_paddr_set_to_zero in commit 45d92439aebd was wrong. Even solaris targets don't have want_p_paddr_set_to_zero, but we should handle them at least somewhat reasonably. =20 PR 31667 * elf.c (IS_SECTION_IN_INPUT_SEGMENT): Remove bed arg, add paddr_valid. Don't use bed->want_p_paddr_set_to_zero. (INCLUDE_SECTION_IN_SEGMENT): Likewise. (rewrite_elf_program_header): Adjust to suit. Diff: --- bfd/elf.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/bfd/elf.c b/bfd/elf.c index 0f4907adc32..74236a658fd 100644 --- a/bfd/elf.c +++ b/bfd/elf.c @@ -7578,10 +7578,9 @@ rewrite_elf_program_header (bfd *ibfd, bfd *obfd, bf= d_vma maxpagesize) 7. SHF_TLS sections are only in PT_TLS or PT_LOAD segments. 8. PT_DYNAMIC should not contain empty sections at the beginning (with the possible exception of .dynamic). */ -#define IS_SECTION_IN_INPUT_SEGMENT(section, segment, bed, opb) \ +#define IS_SECTION_IN_INPUT_SEGMENT(section, segment, opb, paddr_valid) \ (((is_contained_by (section, segment, segment->p_paddr, \ - segment->p_vaddr, opb, \ - bed->want_p_paddr_set_to_zero) \ + segment->p_vaddr, opb, !paddr_valid) \ && (section->flags & SEC_ALLOC) !=3D 0) \ || is_note (section, segment)) \ && segment->p_type !=3D PT_GNU_STACK \ @@ -7600,8 +7599,8 @@ rewrite_elf_program_header (bfd *ibfd, bfd *obfd, bfd= _vma maxpagesize) =20 /* If the output section of a section in the input segment is NULL, it is removed from the corresponding output segment. */ -#define INCLUDE_SECTION_IN_SEGMENT(section, segment, bed, opb) \ - (IS_SECTION_IN_INPUT_SEGMENT (section, segment, bed, opb) \ +#define INCLUDE_SECTION_IN_SEGMENT(section, segment, opb, paddr_valid) \ + (IS_SECTION_IN_INPUT_SEGMENT (section, segment, opb, paddr_valid) \ && section->output_section !=3D NULL) =20 /* Returns TRUE iff seg1 starts after the end of seg2. */ @@ -7746,7 +7745,7 @@ rewrite_elf_program_header (bfd *ibfd, bfd *obfd, bfd= _vma maxpagesize) { /* Find the first section in the input segment, which may be removed from the corresponding output segment. */ - if (IS_SECTION_IN_INPUT_SEGMENT (section, segment, bed, opb)) + if (IS_SECTION_IN_INPUT_SEGMENT (section, segment, opb, p_paddr_valid)) { if (first_section =3D=3D NULL) first_section =3D section; @@ -7882,7 +7881,7 @@ rewrite_elf_program_header (bfd *ibfd, bfd *obfd, bfd= _vma maxpagesize) section !=3D NULL; section =3D section->next) { - if (INCLUDE_SECTION_IN_SEGMENT (section, segment, bed, opb)) + if (INCLUDE_SECTION_IN_SEGMENT (section, segment, opb, p_paddr_valid)) { output_section =3D section->output_section;