Christian Weisgerber: > I'm tired of seeing the stream of warnings when building devel/dwz, > so let's ANSIfy hashtab.c. > > While here, use the libc SHA1 functions instead of reinventing the > wheel yet another time. Those will soon be much faster on selected > hardware. > > OK?
Anybody? The SHA1 change is small, and if upstream ever pulls in a new version of hashtab.c, it will include ansification, so that's not the sort of local change that would be a pain to carry forward. > ----------------------------------------------- > commit 7130f9f1b5242720a2f0b07be022d28e8aee3dd16f223dadf2a4caa5f75e5a64 > (mystuff) > from: Christian Weisgerber <[email protected]> > date: Fri Jun 19 23:40:37 2026 UTC > > devel/dwz: ANSIfy and use libc SHA1 functions > > diff 74eeda0e90f50d930353b5d36e1ce0bdb44bc0756ccbff23abb491b727f9c308 > 7130f9f1b5242720a2f0b07be022d28e8aee3dd16f223dadf2a4caa5f75e5a64 > commit - 74eeda0e90f50d930353b5d36e1ce0bdb44bc0756ccbff23abb491b727f9c308 > commit + 7130f9f1b5242720a2f0b07be022d28e8aee3dd16f223dadf2a4caa5f75e5a64 > blob - 0f51bc85fc097cd693584520ccfc2944f78aab77c26be756b7de1f125286a1d5 > blob + 11edb981f0812ecf34c135806b11e6c1ee5aa6e7e9f4fd17aae027c32444b82b > --- devel/dwz/Makefile > +++ devel/dwz/Makefile > @@ -4,7 +4,7 @@ XXHASH_V = 0.8.3 > DISTFILES = ${PKGNAME}.tar.gz > DISTFILES.h= xxhash-${XXHASH_V}{xxhash}.h > > -REVISION = 1 > +REVISION = 2 > > CATEGORIES = devel > > blob - 7f7113633ebee95b2b4fdc2a5486c1eef3ad2441d7e9e448c7625429a655dcbf > blob + 29ad5cb06001172a4842e5947f5009a2eea26102eabe1175dc304e4c016a9ed8 > --- devel/dwz/patches/patch-Makefile > +++ devel/dwz/patches/patch-Makefile > @@ -41,7 +41,7 @@ Index: Makefile > datarootdir = $(prefix)/share > mandir = $(datarootdir)/man > -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 > ++OBJECTS = args.o dwz.o hashtab.o pool.o dwarfnames.o obstack.o > LIBS=-lelf > -ifneq "$(XXH_INLINE_ALL_WORKS)" "1" > -LIBS += -lxxhash > blob - 5b55b82fdf8dac934460312dd9e534088264f4fae81f1bf70eab9396ee5c52c3 > blob + 2e3200c398222e577e5c067c6e2a54b6bf969591af82709e2d472203497ba40b > --- devel/dwz/patches/patch-dwz_c > +++ devel/dwz/patches/patch-dwz_c > @@ -2,17 +2,19 @@ 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 > +Use libc SHA1 functions. > > Index: dwz.c > --- dwz.c.orig > +++ dwz.c > -@@ -21,13 +21,13 @@ > +@@ -21,13 +21,14 @@ > > #include <assert.h> > #include <errno.h> > -#include <error.h> > #include <fcntl.h> > #include <setjmp.h> > ++#include <sha1.h> > #include <string.h> > #include <stdbool.h> > #include <stddef.h> > @@ -21,7 +23,7 @@ Index: dwz.c > #include <inttypes.h> > #include <stdlib.h> > #include <unistd.h> > -@@ -38,7 +38,7 @@ > +@@ -38,11 +39,10 @@ > #include <sys/wait.h> > > #include <gelf.h> > @@ -30,6 +32,10 @@ Index: dwz.c > > #include "dwarf2.h" > #include "hashtab.h" > +-#include "sha1.h" > + #include "args.h" > + #include "util.h" > + #include "pool.h" > @@ -213,6 +213,29 @@ report_progress (void) > /* Where to longjmp on OOM. */ > static jmp_buf oom_buf; > @@ -96,15 +102,38 @@ Index: dwz.c > { > error (0, 0, "%s: elf_update failed", dso->filename); > unlink (file); > -@@ -16004,7 +16027,7 @@ optimize_multifile (unsigned int *die_count) > +@@ -15739,7 +15762,7 @@ optimize_multifile (unsigned int *die_count) > + : sizeof shstrtab_gnu); > + const char *p; > + unsigned char note[0x24], *np, *supp; > +- struct sha1_ctx ctx; > ++ SHA1_CTX ctx; > + > + if (multi_ehdr.e_ident[0] == '\0' > + || multi_ptr_size == 0 > +@@ -16004,17 +16027,17 @@ optimize_multifile (unsigned int *die_count) > error (0, 0, "Could not create new ELF headers"); > goto fail; > } > - elf_flagelf (elf, ELF_C_SET, ELF_F_LAYOUT | ELF_F_PERMISSIVE); > + elf_flagelf (elf, ELF_C_SET, ELF_F_LAYOUT); > > - sha1_init_ctx (&ctx); > +- sha1_init_ctx (&ctx); > ++ SHA1Init (&ctx); > for (i = 0; debug_sections[i].name; i++) > + { > + if (debug_sections[i].new_size == 0) > + continue; > +- sha1_process_bytes (debug_sections[i].new_data, > +- debug_sections[i].new_size, &ctx); > ++ SHA1Update (&ctx, debug_sections[i].new_data, > ++ debug_sections[i].new_size); > + } > +- sha1_finish_ctx (&ctx, multifile_sha1); > ++ SHA1Final (multifile_sha1, &ctx); > + > + memcpy (np, "GNU", sizeof ("GNU")); > + memcpy (np + 4, multifile_sha1, 0x14); > @@ -16097,7 +16120,7 @@ optimize_multifile (unsigned int *die_count) > data->d_off = 0; > data->d_align = 1; > blob - 6bf8c5e78156700c25a75e96ce5c62f086ee89f5fb742a24f59519cde72f4611 > blob + 1e622f44d093d8155fa68a65b19b9dcc93b666b028d23733b65c45a5b2d2549a > --- devel/dwz/patches/patch-hashtab_c > +++ devel/dwz/patches/patch-hashtab_c > @@ -1,6 +1,8 @@ > More portable endianness check > https://www.austingroupbugs.net/view.php?id=162#c665 > > +ANSIfy. > + > Index: hashtab.c > --- hashtab.c.orig > +++ hashtab.c > @@ -13,3 +15,225 @@ Index: hashtab.c > # define WORDS_BIGENDIAN 1 > #endif > > +@@ -66,8 +66,7 @@ htab_eq htab_eq_pointer = eq_pointer; > + greater than N, and near a power of two. */ > + > + unsigned long > +-higher_prime_number (n) > +- unsigned long n; > ++higher_prime_number (unsigned long n) > + { > + /* These are primes that are near, but slightly smaller than, a > + power of two. */ > +@@ -130,8 +129,7 @@ higher_prime_number (n) > + /* Returns a hash code for P. */ > + > + static hashval_t > +-hash_pointer (p) > +- const void * p; > ++hash_pointer (const void * p) > + { > + return (hashval_t) ((long)p >> 3); > + } > +@@ -139,9 +137,7 @@ hash_pointer (p) > + /* Returns non-zero if P1 and P2 are equal. */ > + > + static int > +-eq_pointer (p1, p2) > +- const void * p1; > +- const void * p2; > ++eq_pointer (const void * p1, const void * p2) > + { > + return p1 == p2; > + } > +@@ -152,11 +148,7 @@ eq_pointer (p1, p2) > + hash table. Memory allocation may fail; it may return NULL. */ > + > + htab_t > +-htab_try_create (size, hash_f, eq_f, del_f) > +- size_t size; > +- htab_hash hash_f; > +- htab_eq eq_f; > +- htab_del del_f; > ++htab_try_create (size_t size, htab_hash hash_f, htab_eq eq_f, htab_del > del_f) > + { > + htab_t result; > + > +@@ -184,8 +176,7 @@ htab_try_create (size, hash_f, eq_f, del_f) > + Naturally the hash table must already exist. */ > + > + void > +-htab_delete (htab) > +- htab_t htab; > ++htab_delete (htab_t htab) > + { > + int i; > + > +@@ -202,8 +193,7 @@ htab_delete (htab) > + /* This function clears all entries in the given hash table. */ > + > + void > +-htab_empty (htab) > +- htab_t htab; > ++htab_empty (htab_t htab) > + { > + int i; > + > +@@ -226,9 +216,7 @@ htab_empty (htab) > + HASH is the hash value for the element to be inserted. */ > + > + static void ** > +-find_empty_slot_for_expand (htab, hash) > +- htab_t htab; > +- hashval_t hash; > ++find_empty_slot_for_expand (htab_t htab, hashval_t hash) > + { > + size_t size = htab->size; > + unsigned int index = hash % size; > +@@ -264,8 +252,7 @@ find_empty_slot_for_expand (htab, hash) > + expanded. If all goes well, it will return a non-zero value. */ > + > + static int > +-htab_expand (htab) > +- htab_t htab; > ++htab_expand (htab_t htab) > + { > + void **oentries; > + void **olimit; > +@@ -311,10 +298,7 @@ htab_expand (htab) > + element. It cannot be used to insert or delete an element. */ > + > + void * > +-htab_find_with_hash (htab, element, hash) > +- htab_t htab; > +- const void * element; > +- hashval_t hash; > ++htab_find_with_hash (htab_t htab, const void * element, hashval_t hash) > + { > + unsigned int index; > + hashval_t hash2; > +@@ -350,9 +334,7 @@ htab_find_with_hash (htab, element, hash) > + element. */ > + > + void * > +-htab_find (htab, element) > +- htab_t htab; > +- const void * element; > ++htab_find (htab_t htab, const void * element) > + { > + return htab_find_with_hash (htab, element, (*htab->hash_f) (element)); > + } > +@@ -366,11 +348,8 @@ htab_find (htab, element) > + fails. */ > + > + void ** > +-htab_find_slot_with_hash (htab, element, hash, insert) > +- htab_t htab; > +- const void * element; > +- hashval_t hash; > +- enum insert_option insert; > ++htab_find_slot_with_hash (htab_t htab, const void * element, hashval_t hash, > ++ enum insert_option insert) > + { > + void **first_deleted_slot; > + unsigned int index; > +@@ -435,10 +414,7 @@ htab_find_slot_with_hash (htab, element, hash, insert) > + element. */ > + > + void ** > +-htab_find_slot (htab, element, insert) > +- htab_t htab; > +- const void * element; > +- enum insert_option insert; > ++htab_find_slot (htab_t htab, const void * element, enum insert_option > insert) > + { > + return htab_find_slot_with_hash (htab, element, (*htab->hash_f) (element), > + insert); > +@@ -449,9 +425,7 @@ htab_find_slot (htab, element, insert) > + function does nothing. */ > + > + void > +-htab_remove_elt (htab, element) > +- htab_t htab; > +- void * element; > ++htab_remove_elt (htab_t htab, void * element) > + { > + void **slot; > + > +@@ -471,9 +445,7 @@ htab_remove_elt (htab, element) > + again. */ > + > + void > +-htab_clear_slot (htab, slot) > +- htab_t htab; > +- void **slot; > ++htab_clear_slot (htab_t htab, void **slot) > + { > + if (slot < htab->entries || slot >= htab->entries + htab->size > + || *slot == EMPTY_ENTRY || *slot == DELETED_ENTRY) > +@@ -492,10 +464,7 @@ htab_clear_slot (htab, slot) > + argument. */ > + > + void > +-htab_traverse (htab, callback, info) > +- htab_t htab; > +- htab_trav callback; > +- void * info; > ++htab_traverse (htab_t htab, htab_trav callback, void * info) > + { > + void **slot = htab->entries; > + void **limit = slot + htab->size; > +@@ -514,8 +483,7 @@ htab_traverse (htab, callback, info) > + /* Return the current size of given hash table. */ > + > + size_t > +-htab_size (htab) > +- htab_t htab; > ++htab_size (htab_t htab) > + { > + return htab->size; > + } > +@@ -523,8 +491,7 @@ htab_size (htab) > + /* Return the current number of elements in given hash table. */ > + > + size_t > +-htab_elements (htab) > +- htab_t htab; > ++htab_elements (htab_t htab) > + { > + return htab->n_elements - htab->n_deleted; > + } > +@@ -533,8 +500,7 @@ htab_elements (htab) > + hash table. */ > + > + double > +-htab_collisions (htab) > +- htab_t htab; > ++htab_collisions (htab_t htab) > + { > + if (htab->searches == 0) > + return 0.0; > +@@ -544,10 +510,7 @@ htab_collisions (htab) > + > + #ifndef NDEBUG > + void > +-htab_dump (htab, name, dumpfn) > +- htab_t htab; > +- const char *name; > +- htab_dumpfn dumpfn; > ++htab_dump (htab_t htab, const char *name, htab_dumpfn dumpfn) > + { > + FILE *f = fopen (name, "w"); > + size_t i, j; > +@@ -579,10 +542,7 @@ htab_dump (htab, name, dumpfn) > + } > + > + void > +-htab_restore (htab, name, restorefn) > +- htab_t htab; > +- const char *name; > +- htab_restorefn restorefn; > ++htab_restore (htab_t htab, const char *name, htab_restorefn restorefn) > + { > + FILE *f = fopen (name, "r"); > + size_t size, n_elements, n_deleted, i, j, k; > -- Christian "naddy" Weisgerber [email protected]
