From owner-freebsd-mips@freebsd.org Fri Nov 9 21:45:50 2018 Return-Path: Delivered-To: freebsd-mips@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 2BE071109193 for ; Fri, 9 Nov 2018 21:45:50 +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 9A52C8F8ED for ; Fri, 9 Nov 2018 21:45:49 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: by mailman.ysv.freebsd.org (Postfix) id 5A71D1109192; Fri, 9 Nov 2018 21:45:49 +0000 (UTC) Delivered-To: mips@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 3882E1109191 for ; Fri, 9 Nov 2018 21:45:49 +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.3 with cipher TLS_AES_256_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 B57E98F8E1 for ; Fri, 9 Nov 2018 21:45:48 +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 E4D4C15B56 for ; Fri, 9 Nov 2018 21:45:47 +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 wA9LjlSs038183 for ; Fri, 9 Nov 2018 21:45:47 GMT (envelope-from bugzilla-noreply@freebsd.org) Received: (from bugzilla@localhost) by kenobi.freebsd.org (8.15.2/8.15.2/Submit) id wA9LjllC038182 for mips@FreeBSD.org; Fri, 9 Nov 2018 21:45:47 GMT (envelope-from bugzilla-noreply@freebsd.org) X-Authentication-Warning: kenobi.freebsd.org: bugzilla set sender to bugzilla-noreply@freebsd.org using -f From: bugzilla-noreply@freebsd.org To: mips@FreeBSD.org Subject: [Bug 231790] objcopy: corrupts relocation entries in big-endian mips64 output when adjusting symbol indexes Date: Fri, 09 Nov 2018 21:45:47 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: Base System X-Bugzilla-Component: kern X-Bugzilla-Version: CURRENT X-Bugzilla-Keywords: regression X-Bugzilla-Severity: Affects Only Me X-Bugzilla-Who: commit-hook@freebsd.org X-Bugzilla-Status: Closed X-Bugzilla-Resolution: FIXED X-Bugzilla-Priority: --- X-Bugzilla-Assigned-To: emaste@freebsd.org X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: 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-Rspamd-Queue-Id: 9A52C8F8ED X-Spamd-Result: default: False [-106.85 / 200.00]; ARC_NA(0.00)[]; FORGED_RECIPIENTS_FORWARDING(0.00)[]; ALLOW_DOMAIN_WHITELIST(-100.00)[freebsd.org]; NEURAL_HAM_MEDIUM(-1.00)[-1.000,0]; FORWARDED(0.00)[mips@mailman.ysv.freebsd.org]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; MIME_GOOD(-0.10)[text/plain]; TO_DN_NONE(0.00)[]; HAS_XAW(0.00)[]; R_SPF_SOFTFAIL(0.00)[~all]; RCPT_COUNT_ONE(0.00)[1]; SPF_FAIL_FORWARDING(0.00)[]; DMARC_NA(0.00)[freebsd.org]; RCVD_IN_DNSWL_MED(-0.20)[5.0.0.0.0.5.0.0.0.0.0.0.0.0.0.0.a.6.0.2.4.5.2.2.0.0.9.1.1.0.0.2.list.dnswl.org : 127.0.9.2]; MX_GOOD(-0.01)[cached: mx66.freebsd.org]; FROM_NO_DN(0.00)[]; NEURAL_HAM_SHORT(-1.00)[-1.000,0]; RCVD_NO_TLS_LAST(0.10)[]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(0.00)[]; IP_SCORE(-3.64)[ip: (-9.80), ipnet: 2001:1900:2254::/48(-4.69), asn: 10310(-3.62), country: US(-0.09)]; ASN(0.00)[asn:10310, ipnet:2001:1900:2254::/48, country:US]; FORGED_RECIPIENTS(0.00)[mips@FreeBSD.org,freebsd-mips@freebsd.org]; RCVD_COUNT_SEVEN(0.00)[7]; TO_DOM_EQ_FROM_DOM(0.00)[] X-Rspamd-Server: mx1.freebsd.org X-BeenThere: freebsd-mips@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Porting FreeBSD to MIPS List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 09 Nov 2018 21:45:50 -0000 https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D231790 --- Comment #12 from commit-hook@freebsd.org --- A commit references this bug: Author: emaste Date: Fri Nov 9 21:45:44 UTC 2018 New revision: 340309 URL: https://svnweb.freebsd.org/changeset/base/340309 Log: Fix objcopy for little-endian MIPS64 objects. MFC r338478 (jhb): Fix objcopy for little-endian MIPS64 objects. MIPS64 does not store the 'r_info' field of a relocation table entry as a 64-bit value consisting of a 32-bit symbol index in the high 32 bits and a 32-bit type in the low 32 bits as on other architectures. Instead, the 64-bit 'r_info' field is really a 32-bit symbol index followed by four individual byte type fields. For big-endian MIPS64, treating this as a 64-bit integer happens to be compatible with the layout expected by other architectures (symbol index in upper 32-bits of resulting "native" 64-bit integer). However, for little-endian MIPS64 the parsed 64-bit integer contains the symbol index in the low 32 bits and the 4 individual byte type fields in the upper 32-bits (but as if the upper 32-bits were byte-swapped). To cope, add two helper routines in gelf_getrel.c to translate between the correct native 'r_info' value and the value obtained after the normal byte-swap translation. Use these routines in gelf_getrel(), gelf_getrela= (), gelf_update_rel(), and gelf_update_rela(). This fixes 'readelf -r' on little-endian MIPS64 objects which was previously decoding incorrect relocations as well as 'objcopy: invalid symbox index' warnings from objcopy when extracting debug symbols from kernel modules. Even with this fixed, objcopy was still crashing when trying to extract debug symbols from little-endian MIPS64 modules. The workaround in gelf_*rel*() depends on the current ELF object having a valid ELF header so that the 'e_machine' field can be compared against EM_MIPS. objcopy was parsing the relocation entries to possibly rewrite the 'r_info' fields in the update_relocs() function before writing the initial ELF header to the destination object file. Move the initial write of the ELF header earlier before copy_contents() so that update_relocs() uses the correct symbol index values. Note that this change should really go upstream. The binutils readelf source has a similar hack for MIPS64EL though I implemented this version from scratch using the MIPS64 ABI PDF as a reference. MFC r339083 (emaste): libelf: correct mips64el test to use ELF header libelf maintains two views of endianness: e_byteorder, and e_ident[EI_DATA] in the ELF header itself. e_byteorder is not always kept in sync, so use the ELF header endianness to test for mips64el. MFC r339473 (emaste): libelf: also test for 64-bit ELF in _libelf_is_mips= 64el Although _libelf_is_mips64el is only called in contexts where we've already checked that e_class is ELFCLASS64 but this may change in the future. Add a safety belt so that we don't access an invalid e_ehdr64 union member if it does. PR: 231790 Changes: _U stable/11/ stable/11/contrib/elftoolchain/elfcopy/main.c stable/11/contrib/elftoolchain/libelf/Makefile stable/11/contrib/elftoolchain/libelf/_libelf.h stable/11/contrib/elftoolchain/libelf/gelf_mips64el.c stable/11/contrib/elftoolchain/libelf/gelf_rel.c stable/11/contrib/elftoolchain/libelf/gelf_rela.c stable/11/sys/sys/param.h --=20 You are receiving this mail because: You are on the CC list for the bug.=