Sunday, June 04, 2023

UPDATE: devel/dwz 0.14 => 0.15

Index: Makefile
===================================================================
RCS file: /cvs/ports/devel/dwz/Makefile,v
retrieving revision 1.6
diff -u -p -r1.6 Makefile
--- Makefile 11 Mar 2022 18:50:00 -0000 1.6
+++ Makefile 29 Nov 2022 23:40:09 -0000
@@ -1,5 +1,8 @@
COMMENT = DWARF optimization and duplicate removal tool
-DISTNAME = dwz-0.14
+PKGNAME = dwz-0.15
+XXHASH_V = 0.8.1
+DISTFILES = ${PKGNAME}.tar.gz:0 \
+ xxhash-${XXHASH_V}{xxhash}.h:1

CATEGORIES = devel

@@ -11,7 +14,8 @@ PERMIT_PACKAGE = Yes

WANTLIB += c elf

-MASTER_SITES = https://sourceware.org/ftp/dwz/releases/
+MASTER_SITES0
= https://sourceware.org/ftp/dwz/releases/
+MASTER_SITES1
= https://raw.githubusercontent.com/Cyan4973/xxHash/v${XXHASH_V}/

DEBUG_PACKAGES = ${BUILD_PACKAGES}

@@ -25,5 +29,23 @@ WRKDIST = ${WRKDIR}/dwz
# XXX bootstrap: DEBUG_PACKAGES needs a dwz binary to work

DWZ = ${WRKBUILD}/dwz
+
+EXTRACT_ONLY = ${PKGNAME}.tar.gz
+
+post-extract:
+ cp ${DISTDIR}/xxhash-${XXHASH_V}.h ${WRKSRC}/xxhash.h
+
+.include <bsd.port.arch.mk>
+.if ${PROPERTIES:Mlp64}
+CFLAGS += -DNATIVE_POINTER_SIZE=8
+.else
+CFLAGS += -DNATIVE_POINTER_SIZE=4
+.endif
+
+.if ${PROPERTIES:Mle}
+CFLAGS += -DNATIVE_ENDIAN_VAL=ELFDATA2LSB
+.else
+CFLAGS += -DNATIVE_ENDIAN_VAL=ELFDATA2MSB
+.endif

.include <bsd.port.mk>
Index: distinfo
===================================================================
RCS file: /cvs/ports/devel/dwz/distinfo,v
retrieving revision 1.2
diff -u -p -r1.2 distinfo
--- distinfo 8 Mar 2021 16:51:11 -0000 1.2
+++ distinfo 29 Nov 2022 23:40:09 -0000
@@ -1,2 +1,4 @@
-SHA256 (dwz-0.14.tar.gz) = MwBuq4df8KB/E/yIWIPFvZUU2D7OqfGLxGtXMt3fDR8=
-SIZE (dwz-0.14.tar.gz) = 186623
+SHA256 (dwz-0.15.tar.gz) = 7VnGEuIEFeaX+8RRH1J+91cAe8VvoalU5JrKHans+0Q=
+SHA256 (xxhash-0.8.1.h) = 1PK5G1R8eQYWSRhnIaazMWCfK/hZVIWiHqYxyC7D75M=
+SIZE (dwz-0.15.tar.gz) = 192777
+SIZE (xxhash-0.8.1.h) = 209646
Index: patches/patch-Makefile
===================================================================
RCS file: /cvs/ports/devel/dwz/patches/patch-Makefile,v
retrieving revision 1.3
diff -u -p -r1.3 patch-Makefile
--- patches/patch-Makefile 11 Mar 2022 18:50:00 -0000 1.3
+++ patches/patch-Makefile 29 Nov 2022 23:40:09 -0000
@@ -6,31 +6,76 @@ Convert to bsd make
Index: Makefile
--- Makefile.orig
+++ Makefile
-@@ -1,20 +1,16 @@
+@@ -1,51 +1,21 @@
-ifneq ($(srcdir),)
-VPATH = $(srcdir)
-else
-srcdir=$(shell pwd)
-endif
+-
-CFLAGS = -O2 -g
-DWZ_VERSION := $(shell cat $(srcdir)/VERSION)
--override CFLAGS += -Wall -W -D_FILE_OFFSET_BITS=64 \
-- -DDWZ_VERSION='"$(DWZ_VERSION)"' $(shell cat $(srcdir)/COPYRIGHT_YEARS)
+-CFLAGS_VERSION = -DDWZ_VERSION='"$(DWZ_VERSION)"'
+-CFLAGS_COPYRIGHT = $(shell cat $(srcdir)/COPYRIGHT_YEARS)
+-CFLAGS_COMMON = -Wall -W -D_FILE_OFFSET_BITS=64
+-XXH_PROG = "\#define XXH_INLINE_ALL 1\n\#include <xxhash.h>\n"
+-XXH_INLINE_ALL_WORKS = $(shell printf $(XXH_PROG) \
+- | $(CC) -xc -c - -o /dev/null 2>/dev/null \
+- && echo -n 1)
+-ifeq "$(XXH_INLINE_ALL_WORKS)" "1"
+- CFLAGS_COMMON += -DXXH_INLINE_ALL=1
+-endif
+-
+-override CFLAGS += $(CFLAGS_COMMON) $(CFLAGS_VERSION) $(CFLAGS_COPYRIGHT)
+-
+srcdir = .
+CFLAGS ?= -O2 -g
+DWZ_VERSION != cat $(srcdir)/VERSION
+CFLAGS += -DDWZ_VERSION='"$(DWZ_VERSION)"'
+CFLAGS !+= cat $(srcdir)/COPYRIGHT_YEARS
++CFLAGS += -D_FILE_OFFSET_BITS=64
++CFLAGS += -DXXH_INLINE_ALL=1
prefix = /usr
exec_prefix = $(prefix)
bindir = $(exec_prefix)/bin
datarootdir = $(prefix)/share
mandir = $(datarootdir)/man
--OBJECTS = dwz.o hashtab.o sha1.o dwarfnames.o
-+OBJECTS = dwz.o hashtab.o sha1.o dwarfnames.o obstack.o
+-OBJECTS = args.o dwz.o hashtab.o pool.o sha1.o dwarfnames.o
++OBJECTS = args.o dwz.o hashtab.o pool.o sha1.o dwarfnames.o obstack.o
+ LIBS=-lelf
+-ifneq "$(XXH_INLINE_ALL_WORKS)" "1"
+-LIBS += -lxxhash
+-endif
dwz: $(OBJECTS)
-- $(CC) $(LDFLAGS) -o $@ $^ -lelf
-+ $(CC) $(LDFLAGS) -o $@ $(OBJECTS) -lelf
+- $(CC) $(LDFLAGS) -o $@ $^ $(LIBS)
+-args.o: native.o
+-args.o: CFLAGS_FOR_SOURCE = \
+- -DNATIVE_ENDIAN_VAL=$(NATIVE_ENDIAN_VAL) \
+- -DNATIVE_POINTER_SIZE=$(NATIVE_POINTER_SIZE)
+-NATIVE_ENDIAN=$(shell readelf -h native.o \
+- | grep Data \
+- | sed 's/.*, //;s/ endian//')
+-NATIVE_ENDIAN_LITTLE=$(findstring $(NATIVE_ENDIAN),$(findstring little,$(NATIVE_ENDIAN)))
+-NATIVE_ENDIAN_BIG=$(findstring $(NATIVE_ENDIAN),$(findstring big,$(NATIVE_ENDIAN)))
+-NATIVE_ENDIAN_VAL=$(if $(NATIVE_ENDIAN_LITTLE),ELFDATA2LSB,$(if $(NATIVE_ENDIAN_BIG),ELFDATA2MSB,ELFDATANONE))
+-NATIVE_POINTER_SIZE=$(shell readelf -wi native.o \
+- | grep "Pointer Size:" \
+- | sed 's/.*: *//')
++ $(CC) $(LDFLAGS) -o $@ $(OBJECTS) $(LIBS)
+ %.o: %.c
+- $(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $< $(CFLAGS_FOR_SOURCE)
++ $(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
install: dwz
install -D dwz $(DESTDIR)$(bindir)/dwz
install -D -m 644 $(srcdir)/dwz.1 $(DESTDIR)$(mandir)/man1/dwz.1
+@@ -53,10 +23,6 @@ clean:
+ rm -f $(OBJECTS) *~ core* dwz $(TEST_EXECS) $(DWZ_TEST_OBJECTS) \
+ dwz.log dwz.sum native.c native.o
+ rm -Rf testsuite-bin tmp.*
+-native.c:
+- echo "int main (void) { return 0; }" > $@
+-native.o: native.c
+- $(CC) -o $@ $< -c -g
+
+ PWD:=$(shell pwd -P)
+
Index: patches/patch-args_c
===================================================================
RCS file: patches/patch-args_c
diff -N patches/patch-args_c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ patches/patch-args_c 29 Nov 2022 23:40:09 -0000
@@ -0,0 +1,32 @@
+Correctly get processors online.
+
+Index: args.c
+--- args.c.orig
++++ args.c
+@@ -25,14 +25,15 @@
+ #include <stdio.h>
+ #include <string.h>
+ #include <stdlib.h>
+-#include <error.h>
++#include <unistd.h>
+ #include <gelf.h>
+-#include <sys/sysinfo.h>
+
+ #include "args.h"
+
+ #include "util.h"
+
++extern void error(int, int, const char *, ...);
++
+ #if DEVEL
+ int tracing;
+ int ignore_size;
+@@ -735,7 +736,7 @@ parse_args (int argc, char *argv[], bool *hardlink, co
+
+ if (max_forks == -1)
+ {
+- long nprocs = get_nprocs ();
++ long nprocs = sysconf(_SC_NPROCESSORS_ONLN);
+ /* Be conservative on max forks: 4 procs may be actually be 4 SMT
+ threads with only 2 cores. */
+ max_forks = nprocs / 2;
Index: patches/patch-dwz_c
===================================================================
RCS file: /cvs/ports/devel/dwz/patches/patch-dwz_c,v
retrieving revision 1.3
diff -u -p -r1.3 patch-dwz_c
--- patches/patch-dwz_c 11 Mar 2022 18:50:00 -0000 1.3
+++ patches/patch-dwz_c 29 Nov 2022 23:40:09 -0000
@@ -1,39 +1,46 @@
Create error() function, Linux-ism.
Our libelf doesn't have some of these defines.
obstack is not a system header
+xxhash is not a system header

Index: dwz.c
--- dwz.c.orig
+++ dwz.c
-@@ -20,11 +20,11 @@
+@@ -20,13 +20,13 @@

#include <assert.h>
#include <errno.h>
-#include <error.h>
#include <fcntl.h>
- #include <getopt.h>
#include <setjmp.h>
#include <string.h>
-+#include <stdarg.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
-@@ -36,7 +36,7 @@
- #include <sys/types.h>
++#include <stdarg.h>
+ #include <inttypes.h>
+ #include <stdlib.h>
+ #include <unistd.h>
+@@ -36,10 +36,10 @@
#include <sys/times.h>
+ #include <sys/wait.h>

-#include <obstack.h>
+#include "obstack.h"

#include <gelf.h>
+-#include <xxhash.h>
++#include "xxhash.h"
+
#include "dwarf2.h"
-@@ -165,6 +165,29 @@ report_progress (void)
+ #include "hashtab.h"
+@@ -216,6 +216,29 @@ report_progress (void)
/* Where to longjmp on OOM. */
static jmp_buf oom_buf;

+/* error () wrapper based on the Linux manual page at
+ http://man7.org/linux/man-pages/man3/error.3.html. */
-+static void
++void
+error (int status, int errnum, const char *fmt, ...)
+{
+ va_list ap;
@@ -57,7 +64,7 @@ Index: dwz.c
/* Handle OOM situation. If handling more than one file, we might
just fail to handle some large file due to OOM, but could very well
handle other smaller files after it. */
-@@ -13723,7 +13746,7 @@ fdopen_dso (int fd, const char *name)
+@@ -13675,7 +13698,7 @@ fdopen_dso (int fd, const char *name)
int i;
DSO *dso = NULL;

@@ -66,7 +73,7 @@ Index: dwz.c
if (elf == NULL)
{
error (0, 0, "cannot open ELF file: %s", elf_errmsg (-1));
-@@ -13761,7 +13784,7 @@ fdopen_dso (int fd, const char *name)
+@@ -13713,7 +13736,7 @@ fdopen_dso (int fd, const char *name)
goto error_out;
}

@@ -75,7 +82,7 @@ Index: dwz.c

memset (dso, 0, sizeof(DSO));
dso->elf = elf;
-@@ -14258,7 +14281,7 @@ write_dso (DSO *dso, const char *file, struct stat *st
+@@ -14210,7 +14233,7 @@ write_dso (DSO *dso, const char *file, struct stat *st
free (shstrtab);
return 1;
}
@@ -84,7 +91,7 @@ Index: dwz.c
for (i = 0; i < ehdr.e_phnum; ++i)
{
GElf_Phdr *phdr, phdr_mem;
-@@ -14331,7 +14354,7 @@ write_dso (DSO *dso, const char *file, struct stat *st
+@@ -14283,7 +14306,7 @@ write_dso (DSO *dso, const char *file, struct stat *st
}
}

@@ -93,7 +100,7 @@ Index: dwz.c
{
error (0, 0, "%s: elf_update failed", dso->filename);
unlink (file);
-@@ -15917,7 +15940,7 @@ optimize_multifile (unsigned int *die_count)
+@@ -15902,7 +15925,7 @@ optimize_multifile (unsigned int *die_count)
error (0, 0, "Could not create new ELF headers");
goto fail;
}
@@ -102,7 +109,7 @@ Index: dwz.c

sha1_init_ctx (&ctx);
for (i = 0; debug_sections[i].name; i++)
-@@ -16010,7 +16033,7 @@ optimize_multifile (unsigned int *die_count)
+@@ -15995,7 +16018,7 @@ optimize_multifile (unsigned int *die_count)
data->d_off = 0;
data->d_align = 1;

Hi ports --

Attached is an update to devel/dwz. The main benefit for us is a modest
speedup.

The full announcement with changes is here:
https://sourceware.org/pipermail/dwz/2022q4/001385.html

Seems OK on my end on amd64. But since dwz is integral for debug
packages, looking for more eyeballs.

OK?

~Brian

No comments:

Post a Comment