From owner-freebsd-bugs@freebsd.org Thu Oct 11 12:57:07 2018 Return-Path: Delivered-To: freebsd-bugs@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id E583910BA291 for ; Thu, 11 Oct 2018 12:57:06 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from mailman.ysv.freebsd.org (mailman.ysv.freebsd.org [IPv6:2001:1900:2254:206a::50:5]) by mx1.freebsd.org (Postfix) with ESMTP id 83392971FA for ; Thu, 11 Oct 2018 12:57:06 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: by mailman.ysv.freebsd.org (Postfix) id 46F3510BA28E; Thu, 11 Oct 2018 12:57:06 +0000 (UTC) Delivered-To: bugs@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 24C5E10BA28D for ; Thu, 11 Oct 2018 12:57:06 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from mxrelay.ysv.freebsd.org (mxrelay.ysv.freebsd.org [IPv6:2001:1900:2254:206a::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.ysv.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 9DA46971F6 for ; Thu, 11 Oct 2018 12:57:05 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from kenobi.freebsd.org (kenobi.freebsd.org [IPv6:2001:1900:2254:206a::16:76]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.ysv.freebsd.org (Postfix) with ESMTPS id D210E49CB for ; Thu, 11 Oct 2018 12:57:04 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from kenobi.freebsd.org ([127.0.1.118]) by kenobi.freebsd.org (8.15.2/8.15.2) with ESMTP id w9BCv44h069356 for ; Thu, 11 Oct 2018 12:57:04 GMT (envelope-from bugzilla-noreply@freebsd.org) Received: (from www@localhost) by kenobi.freebsd.org (8.15.2/8.15.2/Submit) id w9BCv4el069355 for bugs@FreeBSD.org; Thu, 11 Oct 2018 12:57:04 GMT (envelope-from bugzilla-noreply@freebsd.org) X-Authentication-Warning: kenobi.freebsd.org: www set sender to bugzilla-noreply@freebsd.org using -f From: bugzilla-noreply@freebsd.org To: bugs@FreeBSD.org Subject: [Bug 232176] elftoolchain elfcopy/strip incorrectly strips relocations Date: Thu, 11 Oct 2018 12:57:04 +0000 X-Bugzilla-Reason: AssignedTo X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: Base System X-Bugzilla-Component: bin X-Bugzilla-Version: CURRENT X-Bugzilla-Keywords: X-Bugzilla-Severity: Affects Only Me X-Bugzilla-Who: emaste@freebsd.org X-Bugzilla-Status: New X-Bugzilla-Resolution: X-Bugzilla-Priority: --- X-Bugzilla-Assigned-To: bugs@FreeBSD.org X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version rep_platform op_sys bug_status bug_severity priority component assigned_to reporter blocked Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: https://bugs.freebsd.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 11 Oct 2018 12:57:07 -0000 https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D232176 Bug ID: 232176 Summary: elftoolchain elfcopy/strip incorrectly strips relocations Product: Base System Version: CURRENT Hardware: Any OS: Any Status: New Severity: Affects Only Me Priority: --- Component: bin Assignee: bugs@FreeBSD.org Reporter: emaste@freebsd.org Blocks: 231882 When using ifuncs in static binaries we'll have R_X86_64_IRELATIVE relocati= ons in .rela.plt: nuc% readelf -r ifunc_reproducer/make.full=20 Relocation section with addend (.rela.plt): r_offset r_info r_type st_value st_name + r_addend 0000002edaa0 000000000025 R_X86_64_IRELATIVE 0000000000000000 + 2e91f0 Relevant sections: % readelf -S ifunc_reproducer/make.full=20 There are 36 section headers, starting at offset 0x434420: Section Headers: [Nr] Name Type Address Offset Size EntSize Flags Link Info Align [ 0] NULL 0000000000000000 00000000 0000000000000000 0000000000000000 0 0 0 [ 3] .rela.plt RELA 00000000002181a0 000181a0 0000000000000018 0000000000000018 A 33 11 8 [ 9] .plt PROGBITS 00000000002e9c20 000e9c20 0000000000000010 0000000000000000 AX 0 0 16 [11] .got.plt PROGBITS 00000000002edaa0 000edaa0 0000000000000008 0000000000000000 WA 0 0 8 [33] .symtab SYMTAB 0000000000000000 004148f8 0000000000012d38 0000000000000018 35 1582 8 [34] .shstrtab STRTAB 0000000000000000 00427630 000000000000016f 0000000000000000 0 0 1 [35] .strtab STRTAB 0000000000000000 0042779f 000000000000cc7b 0000000000000000 0 0 1 Stripping with objcopy: % objcopy --strip-all ifunc_reproducer/make.full make.stripped results in a broken binary: % ./make.stripped : jemalloc_arena.c:230: Failed assertion: "!bitmap_full(slab_data->bitmap, &bin_info->bitmap_info)" zsh: abort (core dumped) ./make.stripped because the relocation has been removed: % readelf -r make.stripped Relocation section with addend (.rela.plt): r_offset r_info r_type st_value st_name + r_addend Due to this snippet in elfcopy/sections.c::filter_reloc() /* We don't want to touch relocation info for dynamic symbols. */ if ((ecp->flags & SYMTAB_EXIST) =3D=3D 0) { if (ish.sh_link =3D=3D 0 || ecp->secndx[ish.sh_link] =3D=3D= 0) { /* * This reloc section applies to the symbol table * that was stripped, so discard whole section. */ s->nocopy =3D 1; s->sz =3D 0; } return; This is invalid - we can remove the reloc section if the section to which it refers is being stripped, as in create_scn(): if (ish.sh_type =3D=3D SHT_REL || ish.sh_type =3D=3D SHT_RE= LA) if (ish.sh_info !=3D 0 && is_remove_reloc_sec(ecp, ish.sh_info)) continue; but removing based on the string table results in broken output. Referenced Bugs: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D231882 [Bug 231882] multiple toolchain issues with statically linked binaries --=20 You are receiving this mail because: You are the assignee for the bug.=