commit:     192d87260edaf85e501e4b21de1930208397089f
Author:     Signed-off-by: John Hansen <john <AT> mrhansen <DOT> id <DOT> au>
AuthorDate: Sun Jan 23 21:56:22 2022 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Tue Jan 25 03:58:30 2022 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=192d8726

dev-util/clippy: backport upstream big-endian build fix

Signed-off-by: John Hansen <john <AT> mrhansen.id.au>
Signed-off-by: Sam James <sam <AT> gentoo.org>
Closes: https://github.com/gentoo/gentoo/pull/23935
Signed-off-by: Sam James <sam <AT> gentoo.org>

 dev-util/clippy/clippy-8.1-r1.ebuild              | 46 ++++++++++++++++++
 dev-util/clippy/files/clippy-8.1-big-endian.patch | 57 +++++++++++++++++++++++
 2 files changed, 103 insertions(+)

diff --git a/dev-util/clippy/clippy-8.1-r1.ebuild 
b/dev-util/clippy/clippy-8.1-r1.ebuild
new file mode 100644
index 000000000000..bb8ff2d0c5d5
--- /dev/null
+++ b/dev-util/clippy/clippy-8.1-r1.ebuild
@@ -0,0 +1,46 @@
+# Copyright 2020-2022 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=8
+
+MY_P="frr-${PV}"
+PYTHON_COMPAT=( python3_{8..10} )
+inherit autotools python-single-r1
+
+DESCRIPTION="Standalone clippy tool built from FRR sources"
+HOMEPAGE="https://frrouting.org/";
+SRC_URI="https://github.com/FRRouting/frr/archive/${MY_P}.tar.gz -> 
${P}.tar.gz"
+S="${WORKDIR}/frr-${MY_P}"
+
+LICENSE="GPL-2"
+SLOT="0"
+KEYWORDS="~amd64 ~arm64 ~x86"
+REQUIRED_USE="${PYTHON_REQUIRED_USE}"
+
+# standalone clippy does not have any tests
+# restrict to prevent bug 811753
+RESTRICT="test"
+
+DEPEND="
+       ${PYTHON_DEPS}
+       virtual/libelf:=
+"
+RDEPEND="${DEPEND}"
+BDEPEND="sys-devel/flex"
+
+PATCHES=(
+       "${FILESDIR}"/${P}-big-endian.patch
+)
+
+src_prepare() {
+       default
+       eautoreconf
+}
+
+src_configure() {
+       econf --enable-clippy-only
+}
+
+src_install() {
+       dobin lib/clippy
+}

diff --git a/dev-util/clippy/files/clippy-8.1-big-endian.patch 
b/dev-util/clippy/files/clippy-8.1-big-endian.patch
new file mode 100644
index 000000000000..fa715cf23858
--- /dev/null
+++ b/dev-util/clippy/files/clippy-8.1-big-endian.patch
@@ -0,0 +1,57 @@
+https://github.com/FRRouting/frr/commit/cfc45e911e21820bc8b703b37e947a6a7e5d798a.patch
+https://github.com/FRRouting/frr/issues/10051
+
+From: David Lamparter <[email protected]>
+Date: Tue, 18 Jan 2022 09:50:25 +0100
+Subject: [PATCH] lib/clippy: don't endian-convert twice
+
+elf_getdata_rawchunk() already endian-converts; doing it again is, uh,
+counterproductive.
+
+Fixes: #10051
+Reported-by: Lucian Cristian <[email protected]>
+Signed-off-by: David Lamparter <[email protected]>
+--- a/lib/elf_py.c
++++ b/lib/elf_py.c
+@@ -1071,26 +1071,25 @@ static void elffile_add_dynreloc(struct elffile *w, 
Elf_Data *reldata,
+                        * always be a pointer...
+                        */
+                       if (elffile_virt2file(w, rel->r_offset, &offs)) {
+-                              Elf_Data *ptr, *conv;
+-                              GElf_Addr tmp;
+-                              Elf_Data mem = {
+-                                      .d_buf = (void *)&tmp,
+-                                      .d_type = ELF_T_ADDR,
+-                                      .d_version = EV_CURRENT,
+-                                      .d_size = sizeof(tmp),
+-                                      .d_off = 0,
+-                                      .d_align = 0,
+-                              };
++                              Elf_Data *ptr;
+ 
++                              /* NB: this endian-converts! */
+                               ptr = elf_getdata_rawchunk(w->elf, offs,
+                                                          w->elfclass / 8,
+                                                          ELF_T_ADDR);
+ 
+-                              conv = gelf_xlatetom(w->elf, &mem, ptr,
+-                                                   w->mmap[EI_DATA]);
+-                              if (conv) {
+-                                      memcpy(&rel_offs, conv->d_buf,
+-                                             conv->d_size);
++                              if (ptr) {
++                                      char *dst = (char *)&rel_offs;
++
++                                      /* sigh.  it endian-converts.  but
++                                       * doesn't size-convert.
++                                       */
++                                      if (BYTE_ORDER == BIG_ENDIAN &&
++                                          ptr->d_size < sizeof(rel_offs))
++                                              dst += sizeof(rel_offs) -
++                                                     ptr->d_size;
++
++                                      memcpy(dst, ptr->d_buf, ptr->d_size);
+ 
+                                       relw->relative = false;
+                                       relw->rela->r_addend = rel_offs;
+

Reply via email to