tools/elfutils: use gnulib module for posix_fallocate()
The version of posix_fallocate() patched into elfutils for macOS using code from Mozilla is now patched into gnulib. Import the fallocate-posix module and always link the corresponding object to libraries whenever it is built. Signed-off-by: Michael Pratt <mcpratt@pm.me> Link: https://github.com/openwrt/openwrt/pull/15690 Signed-off-by: Robert Marko <robimarko@gmail.com>
This commit is contained in:
parent
f07621e10b
commit
c07a234164
2 changed files with 3 additions and 34 deletions
|
@ -44,6 +44,7 @@ PKG_GNULIB_ARGS = \
|
||||||
|
|
||||||
PKG_GNULIB_MODS = \
|
PKG_GNULIB_MODS = \
|
||||||
argp \
|
argp \
|
||||||
|
fallocate-posix \
|
||||||
fnmatch-gnu \
|
fnmatch-gnu \
|
||||||
fts \
|
fts \
|
||||||
obstack \
|
obstack \
|
||||||
|
@ -54,6 +55,7 @@ PKG_GNULIB_MODS = \
|
||||||
include $(INCLUDE_DIR)/host-build.mk
|
include $(INCLUDE_DIR)/host-build.mk
|
||||||
|
|
||||||
export $(PKG_GNULIB_BASE)=$(HOST_BUILD_DIR)/$(PKG_GNULIB_BASE)/$(PKG_GNULIB_BASE).la
|
export $(PKG_GNULIB_BASE)=$(HOST_BUILD_DIR)/$(PKG_GNULIB_BASE)/$(PKG_GNULIB_BASE).la
|
||||||
|
export $(PKG_GNULIB_BASE)_fallocate-posix=$(HOST_BUILD_DIR)/$(PKG_GNULIB_BASE)/$(PKG_GNULIB_BASE)_la-posix_fallocate.lo
|
||||||
export $(PKG_GNULIB_BASE)_tsearch=$(HOST_BUILD_DIR)/$(PKG_GNULIB_BASE)/$(PKG_GNULIB_BASE)_la-tsearch.lo
|
export $(PKG_GNULIB_BASE)_tsearch=$(HOST_BUILD_DIR)/$(PKG_GNULIB_BASE)/$(PKG_GNULIB_BASE)_la-tsearch.lo
|
||||||
|
|
||||||
HOST_MAKE_FLAGS += \
|
HOST_MAKE_FLAGS += \
|
||||||
|
@ -62,6 +64,7 @@ HOST_MAKE_FLAGS += \
|
||||||
libelf_la_LIBADD='../lib/libeu.la -lz $$$$(zstd_LIBS) -lpthread' \
|
libelf_la_LIBADD='../lib/libeu.la -lz $$$$(zstd_LIBS) -lpthread' \
|
||||||
libdw_la_LIBADD='../libdwfl/libdwfl.la ../libdwelf/libdwelf.la ../libebl/libebl.la ../backends/libebl_backends.la ../libcpu/libcpu.la' \
|
libdw_la_LIBADD='../libdwfl/libdwfl.la ../libdwelf/libdwelf.la ../libebl/libebl.la ../backends/libebl_backends.la ../libcpu/libcpu.la' \
|
||||||
LIBS+='$$$$(if $$$$(findstring $(lastword $(PKG_SUBDIRS)),$$$$(subdir)), $$$$($(PKG_GNULIB_BASE)))' \
|
LIBS+='$$$$(if $$$$(findstring $(lastword $(PKG_SUBDIRS)),$$$$(subdir)), $$$$($(PKG_GNULIB_BASE)))' \
|
||||||
|
LIBS+='$$$$(wildcard $$$$($(PKG_GNULIB_BASE)_fallocate-posix))' \
|
||||||
LIBS+='$$$$(wildcard $$$$($(PKG_GNULIB_BASE)_tsearch))' \
|
LIBS+='$$$$(wildcard $$$$($(PKG_GNULIB_BASE)_tsearch))' \
|
||||||
REPLACE_FCNTL=0 REPLACE_FREE=0 REPLACE_FSTAT=0 REPLACE_OPEN=0 \
|
REPLACE_FCNTL=0 REPLACE_FREE=0 REPLACE_FSTAT=0 REPLACE_OPEN=0 \
|
||||||
bin_PROGRAMS='$(PKG_PROGRAMS)' EXEEXT=
|
bin_PROGRAMS='$(PKG_PROGRAMS)' EXEEXT=
|
||||||
|
|
|
@ -48,40 +48,6 @@
|
||||||
saved_LIBS="$LIBS"
|
saved_LIBS="$LIBS"
|
||||||
AC_SEARCH_LIBS([argp_parse], [argp])
|
AC_SEARCH_LIBS([argp_parse], [argp])
|
||||||
LIBS="$saved_LIBS"
|
LIBS="$saved_LIBS"
|
||||||
--- a/libelf/elf_update.c
|
|
||||||
+++ b/libelf/elf_update.c
|
|
||||||
@@ -37,6 +37,31 @@
|
|
||||||
|
|
||||||
#include "libelfP.h"
|
|
||||||
|
|
||||||
+#ifdef __APPLE__
|
|
||||||
+static int posix_fallocate(int fd, off_t offset, off_t len)
|
|
||||||
+{
|
|
||||||
+ off_t c_test;
|
|
||||||
+ int ret;
|
|
||||||
+ if (!__builtin_saddll_overflow(offset, len, &c_test)) {
|
|
||||||
+ fstore_t store = {F_ALLOCATECONTIG, F_PEOFPOSMODE, 0, offset + len, 0};
|
|
||||||
+ // Try to get a continuous chunk of disk space
|
|
||||||
+ ret = fcntl(fd, F_PREALLOCATE, &store);
|
|
||||||
+ if (ret < 0) {
|
|
||||||
+ // OK, perhaps we are too fragmented, allocate non-continuous
|
|
||||||
+ store.fst_flags = F_ALLOCATEALL;
|
|
||||||
+ ret = fcntl(fd, F_PREALLOCATE, &store);
|
|
||||||
+ if (ret < 0) {
|
|
||||||
+ return ret;
|
|
||||||
+ }
|
|
||||||
+ }
|
|
||||||
+ ret = ftruncate(fd, offset + len);
|
|
||||||
+ } else {
|
|
||||||
+ // offset+len would overflow.
|
|
||||||
+ ret = -1;
|
|
||||||
+ }
|
|
||||||
+ return ret;
|
|
||||||
+}
|
|
||||||
+#endif
|
|
||||||
|
|
||||||
static int64_t
|
|
||||||
write_file (Elf *elf, int64_t size, int change_bo, size_t shnum)
|
|
||||||
--- a/lib/eu-config.h
|
--- a/lib/eu-config.h
|
||||||
+++ b/lib/eu-config.h
|
+++ b/lib/eu-config.h
|
||||||
@@ -59,14 +59,18 @@
|
@@ -59,14 +59,18 @@
|
||||||
|
|
Loading…
Reference in a new issue