PATCH: libc/2251: Weak undefined symbol doesn't work properly with PIE

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

PATCH: libc/2251: Weak undefined symbol doesn't work properly with PIE

H.J. Lu-27
The problem is ld.so looks up undefined hidden or internal symbol.
There is no need to do so in the first place.


H.J.
----
2006-01-31  H.J. Lu  <[hidden email]>

        PR libc/2251
        * elf/dl-lookup.c (_dl_lookup_symbol_x): Don't lookup hidden
        or internal symbol.

--- elf/dl-lookup.c.pie 2006-01-03 14:01:28.000000000 -0800
+++ elf/dl-lookup.c 2006-01-31 10:43:07.000000000 -0800
@@ -216,6 +216,15 @@ _dl_lookup_symbol_x (const char *undef_n
      up a versioned symbol.  */
   assert (version == NULL || flags == 0 || flags == DL_LOOKUP_ADD_DEPENDENCY);
 
+  int hidden = (*ref
+ && (ELFW(ST_VISIBILITY) ((*ref)->st_other) == STV_INTERNAL
+    || ELFW(ST_VISIBILITY) ((*ref)->st_other) == STV_HIDDEN));
+  if (__builtin_expect (hidden != 0, 0))
+    {
+      /* It is a hidden/internal symbol. We won't look elsewhere.  */
+      goto not_found;
+    }
+
   size_t i = 0;
   if (__builtin_expect (skip_map != NULL, 0))
     {
@@ -261,6 +270,7 @@ _dl_lookup_symbol_x (const char *undef_n
 
   if (__builtin_expect (current_value.s == NULL, 0))
     {
+not_found:
       if ((*ref == NULL || ELFW(ST_BIND) ((*ref)->st_info) != STB_WEAK)
   && skip_map == NULL)
  {