libelf: all hail elfutils 0.180

linux 5.8 is set to release soon and it is incompatible with
elftoolchain's libelf (dejavu). we are moving to the last
libelf library available(?), elfutils.
This commit is contained in:
Dylan Araps 2020-08-01 13:27:23 +03:00
parent 7cbea70bb3
commit ee62c900f9
No known key found for this signature in database
GPG Key ID: 46D62DD9F1DE636E
8 changed files with 69 additions and 91 deletions

View File

@ -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

View File

@ -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

View File

@ -1 +1 @@
m4 make
zlib

View File

@ -0,0 +1,27 @@
#ifndef _ERROR_H_
#define _ERROR_H_
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
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_ */

View File

@ -1,40 +0,0 @@
From 4857158172f38c6f66a51f9249c7c49d846fa7e7 Mon Sep 17 00:00:00 2001
From: jkoshy <jkoshy@95820547-d848-0410-985e-9ae8fe0fa350>
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 <stdint.h>
+#define STN_UNDEF 0
+
/*
* Types of capabilities.
*/

View File

@ -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 <features.h>
+#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. */

View File

@ -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

View File

@ -1 +1 @@
0.7.1 2
0.180 1