From 0195824b4f5ba4954b5dd1c1f1ba5f461a2f43c8 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Tue, 26 May 2020 14:17:16 +0300 Subject: [PATCH] libelf: Swap to elftoolchain libelf --- extra/libelf/build | 50 ++++++++++++++++++++++--- extra/libelf/checksums | 3 +- extra/libelf/patches/libelf-linux.patch | 27 +++++++++++++ extra/libelf/sources | 3 +- extra/libelf/version | 2 +- 5 files changed, 76 insertions(+), 9 deletions(-) create mode 100644 extra/libelf/patches/libelf-linux.patch diff --git a/extra/libelf/build b/extra/libelf/build index a7a7f497..ae16a60e 100755 --- a/extra/libelf/build +++ b/extra/libelf/build @@ -1,10 +1,48 @@ #!/bin/sh -e +# +# Word splitting (for CFLAGS, CC, etc) is sadly required. +# shellcheck disable=2086 +# +# This package used to provide the old 'libelf' library. This had a sane +# build system and caused us no trouble. There are two issues with the +# old library, 1. It's been unmaintained for years. 2. The Linux kernel +# will (soon) no longer be compatible with it. +# +# elfutils is not an option (as an alternative) as it heavily depends on +# glibc. To package it for a musl based system 8 or so patches are needed +# as well as various libc "extensions" from glibc (fts, obstack, argp). +# +# elftoolchain requires BSD make to build. Rather than package BSD make, +# let's just do the equivalent ourselves in shell. This is fairly simple +# as all we're building is 'libelf' and not the entire toolchain. +export CFLAGS="-shared -fPIC -O2 $CFLAGS " -sed -i 's/-I/-isystem /g' libelf.pc.in +# Patch unneeded in next release. +patch -p1 < libelf-linux.patch -./configure \ - --prefix=/usr \ - --enable-nls=auto +# Generate needed header file. +common/native-elf-format > common/native-elf-format.h -make -make prefix="$1/usr" install +# Generate needed .c files using m4. +for file in libelf/*.m4; do + ${M4:-m4} -DSRCDIR=libelf "$file" > "${file%%.m4}.c" +done + +# Create all objects (.o). +for file in libelf/*.c; do + ${CC:-cc} -I./common $CFLAGS -c -o "${file%%.c}.o" "$file" +done + +mkdir -p "$1/usr/lib" + +# Create shared library. +${CC:-cc} $CFLAGS -I./common libelf/*.o -o "$1/usr/lib/libelf.so.1" + +# Create static library. +${AR:-ar} rc "$1/usr/lib/libelf.a" libelf/*.o + +# Install remaining headers/files. +ln -sf libelf.so.1 "$1/usr/lib/libelf.so" +install -Dm644 libelf/libelf.h "$1/usr/include/libelf.h" +install -Dm644 libelf/gelf.h "$1/usr/include/gelf.h" +install -Dm644 common/elfdefinitions.h "$1/usr/include/elfdefinitions.h" diff --git a/extra/libelf/checksums b/extra/libelf/checksums index 46a6d9a8..1945de05 100644 --- a/extra/libelf/checksums +++ b/extra/libelf/checksums @@ -1 +1,2 @@ -591a9b4ec81c1f2042a97aa60564e0cb79d041c52faa7416acb38bc95bd2c76d libelf-0.8.13.tar.gz +92bfe36f886024bbc433846483b026c7ce44d553b9b941a0fd13e451911ae297 elftoolchain-0.7.1.tgz +06200f356e309558942a378de07d2cf2e0dcaa3c25cc71542599e39f265c607c libelf-linux.patch diff --git a/extra/libelf/patches/libelf-linux.patch b/extra/libelf/patches/libelf-linux.patch new file mode 100644 index 00000000..a6efb513 --- /dev/null +++ b/extra/libelf/patches/libelf-linux.patch @@ -0,0 +1,27 @@ +From 4857158172f38c6f66a51f9249c7c49d846fa7e7 Mon Sep 17 00:00:00 2001 +From: jkoshy +Date: Sun, 9 Jun 2019 17:01:37 +0000 +Subject: [PATCH] Ensure that the value of a 32-bit parameter passed to the + ELF64_R_INFO() macro does not get lost. + +Submitted by: Michael Forney on -developers + +git-svn-id: svn://svn.code.sf.net/p/elftoolchain/code/trunk@3742 95820547-d848-0410-985e-9ae8fe0fa350 +--- + common/elfdefinitions.h | 3 ++- + 1 file changed, 2 insertions(+), 1 deletion(-) + +diff --git a/common/elfdefinitions.h b/common/elfdefinitions.h +index 0c207226..235b66dd 100644 +--- a/common/elfdefinitions.h ++++ b/common/elfdefinitions.h +@@ -2806,7 +2806,8 @@ typedef struct { + + #define ELF64_R_SYM(I) ((I) >> 32) + #define ELF64_R_TYPE(I) ((I) & 0xFFFFFFFFUL) +-#define ELF64_R_INFO(S,T) (((S) << 32) + ((T) & 0xFFFFFFFFUL)) ++#define ELF64_R_INFO(S,T) \ ++ (((Elf64_Xword) (S) << 32) + ((T) & 0xFFFFFFFFUL)) + + /* + * Symbol versioning structures. diff --git a/extra/libelf/sources b/extra/libelf/sources index d8f130e7..31dbbfdf 100644 --- a/extra/libelf/sources +++ b/extra/libelf/sources @@ -1 +1,2 @@ -https://fossies.org/linux/misc/old/libelf-0.8.13.tar.gz +https://downloads.sourceforge.net/sourceforge/elftoolchain/elftoolchain-0.7.1.tgz +patches/libelf-linux.patch diff --git a/extra/libelf/version b/extra/libelf/version index 5af15bd9..1078b9e9 100644 --- a/extra/libelf/version +++ b/extra/libelf/version @@ -1 +1 @@ -0.8.13 2 +0.7.1 1