]> git.eshelyaron.com Git - emacs.git/commitdiff
Avoid name clashes with static GnuTLS
authorPaul Eggert <eggert@cs.ucla.edu>
Sun, 20 Apr 2025 01:44:52 +0000 (18:44 -0700)
committerEshel Yaron <me@eshelyaron.com>
Mon, 21 Apr 2025 20:41:19 +0000 (22:41 +0200)
Work around a bug in GnuTLS 3.7.11 and earlier: when built
statically, its mistakenly exports symbols hash_lookup and
hash_string, which collide with Emacs symbols of the same name,
preventing temacs from linking statically.  Problem reported by
Greg A. Woods (Bug#77476).

Because GnuTLS never uses hash_lookup or hash_string this issue
ordinarily doesn’t seem to prevent temacs from linking to GnuTLS
on GNU/Linux, as it’s linked dynamically and the dynamic linker
never needs to resolve references to either symbol.  However, I
suppose a clash or bug could occur even with dynamic linking if
Emacs later loads a module that uses either symbol.

Although GnuTLS should be fixed, Emacs should link statically to
current and older GnuTLS versions in the meantime, and it should
avoid potential problems with dynamic linking.  Renaming the two
clashing names is an easy way to do this.  For consistency with
the new name for hash_lookup, also rename hash_lookup_with_hash
and hash_lookup_get_hash.

* src/fns.c (hash_find_with_hash): Rename from hash_lookup_with_hash.
(hash_find): Rename from hash_lookup.
(hash_find_get_hash): Rename from hash_lookup_get_hash.
(hash_char_array): Rename from hash_string.
All uses changed.

(cherry picked from commit c8eed90eb4d0583dc3463edfad176b9d3f98d11f)

15 files changed:
src/bytecode.c
src/category.c
src/ccl.c
src/charset.c
src/charset.h
src/coding.h
src/composite.c
src/emacs-module.c
src/fns.c
src/image.c
src/json.c
src/lisp.h
src/lread.c
src/macfont.m
src/minibuf.c

index ecea0c6df367df70c45fc5824bb33568ca8938b1..4475d4a0b30d5cceae5d7d46962f0ac4ebbdfb02 100644 (file)
@@ -1763,7 +1763,7 @@ exec_byte_code (Lisp_Object fun, ptrdiff_t args_template,
               }
             else
              {
-               ptrdiff_t i = hash_lookup (h, v1);
+               ptrdiff_t i = hash_find (h, v1);
                if (i >= 0)
                  {
                    op = XFIXNUM (HASH_VALUE (h, i));
index 297ba94c73d459b7993488bf303197653eae2221..f65c7d94331fd45a905f25e6fa426d72cf76ea6b 100644 (file)
@@ -54,7 +54,7 @@ hash_get_category_set (Lisp_Object table, Lisp_Object category_set)
        make_hash_table (&hashtest_equal, DEFAULT_HASH_SIZE, Weak_None));
   struct Lisp_Hash_Table *h = XHASH_TABLE (XCHAR_TABLE (table)->extras[1]);
   hash_hash_t hash;
-  ptrdiff_t i = hash_lookup_get_hash (h, category_set, &hash);
+  ptrdiff_t i = hash_find_get_hash (h, category_set, &hash);
   if (i >= 0)
     return HASH_KEY (h, i);
   hash_put (h, category_set, Qnil, hash);
index a45fe0439c4ffec80eb0c38bf8c7c56ef521f69e..36094ca627e9febbe746356a1ec18b108df70a74 100644 (file)
--- a/src/ccl.c
+++ b/src/ccl.c
@@ -1375,7 +1375,7 @@ ccl_driver (struct ccl_program *ccl, int *source, int *destination, int src_size
 
                eop = (FIXNUM_OVERFLOW_P (reg[RRR])
                       ? -1
-                      : hash_lookup (h, make_fixnum (reg[RRR])));
+                      : hash_find (h, make_fixnum (reg[RRR])));
                if (eop >= 0)
                  {
                    Lisp_Object opl;
@@ -1404,7 +1404,7 @@ ccl_driver (struct ccl_program *ccl, int *source, int *destination, int src_size
 
                eop = (FIXNUM_OVERFLOW_P (i)
                       ? -1
-                      : hash_lookup (h, make_fixnum (i)));
+                      : hash_find (h, make_fixnum (i)));
                if (eop >= 0)
                  {
                    Lisp_Object opl;
index 797dfde276f129203d04f5a825150dd3f7d0d9ba..3264d75f92ec192ae5926de8886506332ee6b8c3 100644 (file)
@@ -1112,8 +1112,7 @@ usage: (define-charset-internal ...)  */)
 
   hash_hash_t hash_code;
   ptrdiff_t hash_index
-    = hash_lookup_get_hash (hash_table, args[charset_arg_name],
-                           &hash_code);
+    = hash_find_get_hash (hash_table, args[charset_arg_name], &hash_code);
   if (hash_index >= 0)
     {
       new_definition_p = false;
index 0217ec321ff9a4ceca3f939813d32b4b9bbb45b6..f76e9100892340fcc6e412ca04e63bd28a75f35c 100644 (file)
@@ -285,7 +285,7 @@ extern int emacs_mule_charset[256];
 /* Return an index to Vcharset_hash_table of the charset whose symbol
    is SYMBOL.  */
 #define CHARSET_SYMBOL_HASH_INDEX(symbol)      \
-  hash_lookup (XHASH_TABLE (Vcharset_hash_table), symbol)
+  hash_find (XHASH_TABLE (Vcharset_hash_table), symbol)
 
 /* Return the attribute vector of CHARSET.  */
 #define CHARSET_ATTRIBUTES(charset) (charset)->attributes
index b72ffde3c55023e5d9cbd7279903bf38e0131266..2d538ba69d30dcc9cdffa218fd6413d91b414d1f 100644 (file)
@@ -193,7 +193,7 @@ enum coding_attr_index
 /* Return the ID of CODING_SYSTEM_SYMBOL.  */
 
 #define CODING_SYSTEM_ID(coding_system_symbol)                 \
-  hash_lookup (XHASH_TABLE (Vcoding_system_hash_table),                \
+  hash_find (XHASH_TABLE (Vcoding_system_hash_table),          \
               coding_system_symbol)
 
 /* Return true if CODING_SYSTEM_SYMBOL is a coding system.  */
index 2ef72a33d2e1793ee70bd46da3ad6923d1735774..b6c5b61a6a9937f01feb11c3107c6aebc3348e1a 100644 (file)
@@ -241,7 +241,7 @@ get_composition_id (ptrdiff_t charpos, ptrdiff_t bytepos, ptrdiff_t nchars,
     goto invalid_composition;
 
   hash_hash_t hash_code;
-  hash_index = hash_lookup_get_hash (hash_table, key, &hash_code);
+  hash_index = hash_find_get_hash (hash_table, key, &hash_code);
   if (hash_index >= 0)
     {
       /* We have already registered the same composition.  Change PROP
index 7797b04e026574627320df6fb1d1e541537b5341..2feca41e7ae8b9642219db5c89fa20df3af248f1 100644 (file)
@@ -413,7 +413,7 @@ static bool
 module_global_reference_p (emacs_value v, ptrdiff_t *n)
 {
   struct Lisp_Hash_Table *h = XHASH_TABLE (Vmodule_refs_hash);
-  /* Note that we can't use `hash_lookup' because V might be a local
+  /* Note that we can't use `hash_find' because V might be a local
      reference that's identical to some global reference.  */
   DOHASH (h, k, val)
     if (&XMODULE_GLOBAL_REFERENCE (val)->value == v)
@@ -431,7 +431,7 @@ module_make_global_ref (emacs_env *env, emacs_value value)
   struct Lisp_Hash_Table *h = XHASH_TABLE (Vmodule_refs_hash);
   Lisp_Object new_obj = value_to_lisp (value);
   hash_hash_t hashcode;
-  ptrdiff_t i = hash_lookup_get_hash (h, new_obj, &hashcode);
+  ptrdiff_t i = hash_find_get_hash (h, new_obj, &hashcode);
 
   /* Note: This approach requires the garbage collector to never move
      objects.  */
@@ -470,7 +470,7 @@ module_free_global_ref (emacs_env *env, emacs_value global_value)
   MODULE_FUNCTION_BEGIN ();
   struct Lisp_Hash_Table *h = XHASH_TABLE (Vmodule_refs_hash);
   Lisp_Object obj = value_to_lisp (global_value);
-  ptrdiff_t i = hash_lookup (h, obj);
+  ptrdiff_t i = hash_find (h, obj);
 
   if (module_assertions)
     {
index afca20d67ae9a772ac53c9c66f9fa1eef96ccc62..fd240d55f6da2b5f2ed75a836ee382c6e8153c59 100644 (file)
--- a/src/fns.c
+++ b/src/fns.c
@@ -2815,8 +2815,8 @@ equal_no_quit (Lisp_Object o1, Lisp_Object o2)
   return internal_equal (o1, o2, EQUAL_NO_QUIT, 0, Qnil);
 }
 
-static ptrdiff_t hash_lookup_with_hash (struct Lisp_Hash_Table *h,
-                                       Lisp_Object key, hash_hash_t hash);
+static ptrdiff_t hash_find_with_hash (struct Lisp_Hash_Table *h,
+                                     Lisp_Object key, hash_hash_t hash);
 
 
 /* Return true if O1 and O2 are equal.  EQUAL_KIND specifies what kind
@@ -2848,7 +2848,7 @@ internal_equal_1 (Lisp_Object o1, Lisp_Object o2, enum equal_kind equal_kind,
          {
            struct Lisp_Hash_Table *h = XHASH_TABLE (*ht);
            hash_hash_t hash = hash_from_key (h, o1);
-           ptrdiff_t i = hash_lookup_with_hash (h, o1, hash);
+           ptrdiff_t i = hash_find_with_hash (h, o1, hash);
            if (i >= 0)
              { /* `o1' was seen already.  */
                Lisp_Object o2s = HASH_VALUE (h, i);
@@ -5032,8 +5032,8 @@ hash_table_thaw (Lisp_Object hash_table)
 /* Look up KEY with hash HASH in table H.
    Return entry index or -1 if none.  */
 static ptrdiff_t
-hash_lookup_with_hash (struct Lisp_Hash_Table *h,
-                      Lisp_Object key, hash_hash_t hash)
+hash_find_with_hash (struct Lisp_Hash_Table *h,
+                    Lisp_Object key, hash_hash_t hash)
 {
   ptrdiff_t start_of_bucket = hash_index_index (h, hash);
   for (ptrdiff_t i = HASH_INDEX (h, start_of_bucket);
@@ -5049,20 +5049,20 @@ hash_lookup_with_hash (struct Lisp_Hash_Table *h,
 
 /* Look up KEY in table H.  Return entry index or -1 if none.  */
 ptrdiff_t
-hash_lookup (struct Lisp_Hash_Table *h, Lisp_Object key)
+hash_find (struct Lisp_Hash_Table *h, Lisp_Object key)
 {
-  return hash_lookup_with_hash (h, key, hash_from_key (h, key));
+  return hash_find_with_hash (h, key, hash_from_key (h, key));
 }
 
 /* Look up KEY in hash table H.  Return its hash value in *PHASH.
    Value is the index of the entry in H matching KEY, or -1 if not found.  */
 ptrdiff_t
-hash_lookup_get_hash (struct Lisp_Hash_Table *h, Lisp_Object key,
-                     hash_hash_t *phash)
+hash_find_get_hash (struct Lisp_Hash_Table *h, Lisp_Object key,
+                   hash_hash_t *phash)
 {
   EMACS_UINT hash = hash_from_key (h, key);
   *phash = hash;
-  return hash_lookup_with_hash (h, key, hash);
+  return hash_find_with_hash (h, key, hash);
 }
 
 static void
@@ -5287,7 +5287,7 @@ sweep_weak_table (struct Lisp_Hash_Table *h, bool remove_entries_p)
    can be any EMACS_UINT value.  */
 
 EMACS_UINT
-hash_string (char const *ptr, ptrdiff_t len)
+hash_char_array (char const *ptr, ptrdiff_t len)
 {
   char const *p   = ptr;
   char const *end = ptr + len;
@@ -5460,7 +5460,7 @@ sxhash_obj (Lisp_Object obj, int depth)
       return XHASH (obj);
 
     case Lisp_String:
-      return hash_string (SSDATA (obj), SBYTES (obj));
+      return hash_char_array (SSDATA (obj), SBYTES (obj));
 
     case Lisp_Vectorlike:
       {
@@ -5862,7 +5862,7 @@ usage: (gethash KEY TABLE &optional DEFAULT)  */)
   (Lisp_Object key, Lisp_Object table, Lisp_Object dflt)
 {
   struct Lisp_Hash_Table *h = check_hash_table (table);
-  ptrdiff_t i = hash_lookup (h, key);
+  ptrdiff_t i = hash_find (h, key);
   return i >= 0 ? HASH_VALUE (h, i) : dflt;
 }
 
@@ -5877,7 +5877,7 @@ VALUE.  In any case, return VALUE.  */)
   check_mutable_hash_table (table, h);
 
   EMACS_UINT hash = hash_from_key (h, key);
-  ptrdiff_t i = hash_lookup_with_hash (h, key, hash);
+  ptrdiff_t i = hash_find_with_hash (h, key, hash);
   if (i >= 0)
     set_hash_value_slot (h, i, value);
   else
index 65d8db24adc35149847bd8bf4c16bebdeb5322a9..1d3faecf5076361f1e44f4d320e9291b97a6c8a3 100644 (file)
@@ -5552,7 +5552,7 @@ xpm_free_color_cache (void)
 static int
 xpm_color_bucket (char *color_name)
 {
-  EMACS_UINT hash = hash_string (color_name, strlen (color_name));
+  EMACS_UINT hash = hash_char_array (color_name, strlen (color_name));
   return hash % XPM_COLOR_CACHE_BUCKETS;
 }
 
@@ -6238,7 +6238,7 @@ xpm_put_color_table_h (Lisp_Object color_table,
   Lisp_Object chars = make_unibyte_string (chars_start, chars_len);
 
   hash_hash_t hash_code;
-  hash_lookup_get_hash (table, chars, &hash_code);
+  hash_find_get_hash (table, chars, &hash_code);
   hash_put (table, chars, color, hash_code);
 }
 
@@ -6249,7 +6249,7 @@ xpm_get_color_table_h (Lisp_Object color_table,
 {
   struct Lisp_Hash_Table *table = XHASH_TABLE (color_table);
   ptrdiff_t i =
-    hash_lookup (table, make_unibyte_string (chars_start, chars_len));
+    hash_find (table, make_unibyte_string (chars_start, chars_len));
 
   return i >= 0 ? HASH_VALUE (table, i) : Qnil;
 }
index 5795c582ce058910e9396071860ee32fd01dedb0..beac242b709dabdc421a390b3690adc627999392 100644 (file)
@@ -1571,7 +1571,7 @@ json_parse_object (struct json_parser *parser)
            hash_hash_t hash;
            Lisp_Object key = parser->object_workspace[i];
            Lisp_Object value = parser->object_workspace[i + 1];
-           ptrdiff_t i = hash_lookup_get_hash (h, key, &hash);
+           ptrdiff_t i = hash_find_get_hash (h, key, &hash);
            if (i < 0)
              hash_put (h, key, value, hash);
            else
index 079825cd0f41292695de31f8b24cf2bee2c2df71..7a40bdcd76092f9da727327ba11f0c29275cb5c6 100644 (file)
@@ -4261,14 +4261,14 @@ extern Lisp_Object larger_vector (Lisp_Object, ptrdiff_t, ptrdiff_t);
 extern bool sweep_weak_table (struct Lisp_Hash_Table *, bool);
 extern void hexbuf_digest (char *, void const *, int);
 extern char *extract_data_from_object (Lisp_Object, ptrdiff_t *, ptrdiff_t *);
-EMACS_UINT hash_string (char const *, ptrdiff_t);
+EMACS_UINT hash_char_array (char const *, ptrdiff_t);
 EMACS_UINT sxhash (Lisp_Object);
 Lisp_Object make_hash_table (const struct hash_table_test *, EMACS_INT,
                              hash_table_weakness_t);
 Lisp_Object hash_table_weakness_symbol (hash_table_weakness_t weak);
-ptrdiff_t hash_lookup (struct Lisp_Hash_Table *, Lisp_Object);
-ptrdiff_t hash_lookup_get_hash (struct Lisp_Hash_Table *h, Lisp_Object key,
-                               hash_hash_t *phash);
+ptrdiff_t hash_find (struct Lisp_Hash_Table *, Lisp_Object);
+ptrdiff_t hash_find_get_hash (struct Lisp_Hash_Table *h, Lisp_Object key,
+                             hash_hash_t *phash);
 ptrdiff_t hash_put (struct Lisp_Hash_Table *, Lisp_Object, Lisp_Object,
                    hash_hash_t);
 void hash_remove_from_table (struct Lisp_Hash_Table *, Lisp_Object);
index d39330bd0eba80e126e2e9694e5061154acf1ef3..5c8bbe7da9f4cc6b7cf031a55f53705197ae7e49 100644 (file)
@@ -4266,7 +4266,7 @@ read0 (Lisp_Object readcharfun, bool locate_syms)
                          = XHASH_TABLE (read_objects_map);
                        Lisp_Object number = make_fixnum (n);
                        hash_hash_t hash;
-                       ptrdiff_t i = hash_lookup_get_hash (h, number, &hash);
+                       ptrdiff_t i = hash_find_get_hash (h, number, &hash);
                        if (i >= 0)
                          /* Not normal, but input could be malformed.  */
                          set_hash_value_slot (h, i, placeholder);
@@ -4284,7 +4284,7 @@ read0 (Lisp_Object readcharfun, bool locate_syms)
                        /* #N# -- reference to numbered object */
                        struct Lisp_Hash_Table *h
                          = XHASH_TABLE (read_objects_map);
-                       ptrdiff_t i = hash_lookup (h, make_fixnum (n));
+                       ptrdiff_t i = hash_find (h, make_fixnum (n));
                        if (i < 0)
                          INVALID_SYNTAX_WITH_BUFFER ();
                        obj = HASH_VALUE (h, i);
@@ -4579,7 +4579,7 @@ read0 (Lisp_Object readcharfun, bool locate_syms)
                struct Lisp_Hash_Table *h2
                  = XHASH_TABLE (read_objects_completed);
                hash_hash_t hash;
-               ptrdiff_t i = hash_lookup_get_hash (h2, placeholder, &hash);
+               ptrdiff_t i = hash_find_get_hash (h2, placeholder, &hash);
                eassert (i < 0);
                hash_put (h2, placeholder, Qnil, hash);
                obj = placeholder;
@@ -4594,7 +4594,7 @@ read0 (Lisp_Object readcharfun, bool locate_syms)
                    struct Lisp_Hash_Table *h2
                      = XHASH_TABLE (read_objects_completed);
                    hash_hash_t hash;
-                   ptrdiff_t i = hash_lookup_get_hash (h2, obj, &hash);
+                   ptrdiff_t i = hash_find_get_hash (h2, obj, &hash);
                    eassert (i < 0);
                    hash_put (h2, obj, Qnil, hash);
                  }
@@ -4606,8 +4606,8 @@ read0 (Lisp_Object readcharfun, bool locate_syms)
                /* ...and #n# will use the real value from now on.  */
                struct Lisp_Hash_Table *h = XHASH_TABLE (read_objects_map);
                hash_hash_t hash;
-               ptrdiff_t i = hash_lookup_get_hash (h, e->u.numbered.number,
-                                                   &hash);
+               ptrdiff_t i = hash_find_get_hash (h, e->u.numbered.number,
+                                                 &hash);
                eassert (i >= 0);
                set_hash_value_slot (h, i, obj);
              }
@@ -4661,7 +4661,7 @@ substitute_object_recurse (struct subst *subst, Lisp_Object subtree)
      by #n=, which means that we can find it as a value in
      COMPLETED.  */
   if (EQ (subst->completed, Qt)
-      || hash_lookup (XHASH_TABLE (subst->completed), subtree) >= 0)
+      || hash_find (XHASH_TABLE (subst->completed), subtree) >= 0)
     subst->seen = Fcons (subtree, subst->seen);
 
   /* Recurse according to subtree's type.
@@ -5173,7 +5173,7 @@ OBARRAY, if nil, defaults to the value of the variable `obarray'.  */)
 static ptrdiff_t
 obarray_index (struct Lisp_Obarray *oa, const char *str, ptrdiff_t size_byte)
 {
-  EMACS_UINT hash = hash_string (str, size_byte);
+  EMACS_UINT hash = hash_char_array (str, size_byte);
   return knuth_hash (reduce_emacs_uint_to_hash_hash (hash), oa->size_bits);
 }
 
index 4ff720c5dd21b13c69bda4661d34f55b0960594d..2a0b9aa25540e4de8414665a31562da0774988d5 100644 (file)
@@ -1018,7 +1018,7 @@ macfont_get_family_cache_if_present (Lisp_Object symbol, CFStringRef *string)
   if (HASH_TABLE_P (macfont_family_cache))
     {
       struct Lisp_Hash_Table *h = XHASH_TABLE (macfont_family_cache);
-      ptrdiff_t i = hash_lookup (h, symbol);
+      ptrdiff_t i = hash_find (h, symbol);
 
       if (i >= 0)
        {
@@ -1045,7 +1045,7 @@ macfont_set_family_cache (Lisp_Object symbol, CFStringRef string)
 
   h = XHASH_TABLE (macfont_family_cache);
   hash_hash_t hash;
-  i = hash_lookup_get_hash (h, symbol, &hash);
+  i = hash_find_get_hash (h, symbol, &hash);
   value = string ? make_mint_ptr ((void *) CFRetain (string)) : Qnil;
   if (i >= 0)
     {
index 8c2534bf7cf484ab2ce8501e60251236c5c97856..40ee56f7c06cee29edb6ef1d60c49fe38908eac2 100644 (file)
@@ -1984,7 +1984,7 @@ the values STRING, PREDICATE and `lambda'.  */)
   else if (HASH_TABLE_P (collection))
     {
       struct Lisp_Hash_Table *h = XHASH_TABLE (collection);
-      ptrdiff_t i = hash_lookup (h, string);
+      ptrdiff_t i = hash_find (h, string);
       if (i >= 0)
         {
           tem = HASH_KEY (h, i);