diff --git a/extra/libelf/build b/extra/libelf/build index 15326337..d1299b15 100755 --- a/extra/libelf/build +++ b/extra/libelf/build @@ -1,51 +1,20 @@ #!/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="-fPIC -O2 $CFLAGS" -export LDFLAGS="-shared $LDFLAGS" -# Patch unneeded in next release. -patch -p1 < libelf-linux.patch +patch -p1 < musl-decls.patch -# Generate needed header file. -common/native-elf-format > common/native-elf-format.h +# Disable configure error for missing argp. +sed -i 's/as_fn_error.*libargp/: "/g' configure -# Generate needed .c files using m4. -for file in libelf/*.m4; do - ${M4:-m4} -DSRCDIR=libelf "$file" > "${file%%.m4}.c" -done +# Don't compile two unrelated C files which require argp. +sed -i 's/color.*printversion../#/g' lib/Makefile.in -# Create all objects (.o). -for file in libelf/*.c; do - ${CC:-cc} -I./libelf -I./common $CFLAGS $CPPFLAGS -c \ - -o "${file%%.c}.o" "$file" -done +./configure \ + --prefix=/usr \ + --disable-symbol-versioning \ + --disable-debuginfod \ + --disable-nls -mkdir -p "$1/usr/lib" - -# Create shared library. -${CC:-cc} $LDFLAGS $CFLAGS -I./libelf -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" +# Skip the default make target and build only what we need. +make -C lib +make -C libelf +make -C libelf DESTDIR="$1" install diff --git a/extra/libelf/checksums b/extra/libelf/checksums index ee7de55e..e978fe84 100644 --- a/extra/libelf/checksums +++ b/extra/libelf/checksums @@ -1,2 +1,3 @@ -92bfe36f886024bbc433846483b026c7ce44d553b9b941a0fd13e451911ae297 elftoolchain-0.7.1.tgz -239ed8fbc3393f7a39cbb6f3cad0278ac8b8d1306da9832c43dac1332a89ab28 libelf-linux.patch +b827b6e35c59d188ba97d7cf148fa8dc6f5c68eb6c5981888dfdbb758c0b569d elfutils-0.180.tar.bz2 +fd98976f5112b49f6469e7bd2e97d390cf90dc68392218dc713ac0449fc3e395 musl-decls.patch +bf11b56670c7919b44e33b5b0f3a216b7f20cf2859b74bf5e2e837532f8e0579 error.h diff --git a/extra/libelf/depends b/extra/libelf/depends index e8fb4a13..f22003e8 100644 --- a/extra/libelf/depends +++ b/extra/libelf/depends @@ -1 +1 @@ -m4 make +zlib diff --git a/extra/libelf/files/error.h b/extra/libelf/files/error.h new file mode 100644 index 00000000..ef06827a --- /dev/null +++ b/extra/libelf/files/error.h @@ -0,0 +1,27 @@ +#ifndef _ERROR_H_ +#define _ERROR_H_ + +#include +#include +#include +#include +#include + +static unsigned int error_message_count = 0; + +static inline void error(int status, int errnum, const char* format, ...) +{ + va_list ap; + fprintf(stderr, "%s: ", program_invocation_name); + va_start(ap, format); + vfprintf(stderr, format, ap); + va_end(ap); + if (errnum) + fprintf(stderr, ": %s", strerror(errnum)); + fprintf(stderr, "\n"); + error_message_count++; + if (status) + exit(status); +} + +#endif /* _ERROR_H_ */ diff --git a/extra/libelf/patches/libelf-linux.patch b/extra/libelf/patches/libelf-linux.patch deleted file mode 100644 index bbc55335..00000000 --- a/extra/libelf/patches/libelf-linux.patch +++ /dev/null @@ -1,40 +0,0 @@ -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/common/elfdefinitions.h b/common/elfdefinitions.h -index caa6a30..6484017 100644 ---- a/common/elfdefinitions.h -+++ b/common/elfdefinitions.h -@@ -42,6 +42,8 @@ - - #include - -+#define STN_UNDEF 0 -+ - /* - * Types of capabilities. - */ diff --git a/extra/libelf/patches/musl-decls.patch b/extra/libelf/patches/musl-decls.patch new file mode 100644 index 00000000..e3705695 --- /dev/null +++ b/extra/libelf/patches/musl-decls.patch @@ -0,0 +1,20 @@ +--- a/libelf/elf.h 2015-08-21 14:22:37.000000000 +0200 ++++ b/libelf/elf.h 2015-11-20 04:54:33.948081321 +0100 +@@ -21,6 +21,17 @@ + + #include + ++#if !defined(__GLIBC__) ++/* C++ needs to know that types and declarations are C, not C++. */ ++#ifdef __cplusplus ++# define __BEGIN_DECLS extern "C" { ++# define __END_DECLS } ++#else ++# define __BEGIN_DECLS ++# define __END_DECLS ++#endif ++#endif ++ + __BEGIN_DECLS + + /* Standard ELF types. */ diff --git a/extra/libelf/sources b/extra/libelf/sources index 31dbbfdf..91cdad42 100644 --- a/extra/libelf/sources +++ b/extra/libelf/sources @@ -1,2 +1,3 @@ -https://downloads.sourceforge.net/sourceforge/elftoolchain/elftoolchain-0.7.1.tgz -patches/libelf-linux.patch +https://sourceware.org/elfutils/ftp/0.180/elfutils-0.180.tar.bz2 +patches/musl-decls.patch +files/error.h lib diff --git a/extra/libelf/version b/extra/libelf/version index b2448c78..fd3e36c9 100644 --- a/extra/libelf/version +++ b/extra/libelf/version @@ -1 +1 @@ -0.7.1 2 +0.180 1