PATCH: Properly handle STT_GNU_IFUNC symbols in do_sym

View: New views
4 Messages — Rating Filter:   Alert me  

PATCH: Properly handle STT_GNU_IFUNC symbols in do_sym

by H.J. Lu-10 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

do_sym should use DL_FIXUP_VALUE_XXX macros to call IFUNC function.
Otherwise, it won't compile on ia64. This patch fixes it and adds
a test.


H.J.
----
2009-11-01  H.J. Lu  <hongjiu.lu@...>

        * elf/dl-sym.c (do_sym): Properly handle STT_GNU_IFUNC symbols.

        * elf/ifuncmain3.c (main): Test dlopen STT_GNU_IFUNC symbol.

diff --git a/elf/dl-sym.c b/elf/dl-sym.c
index 459729f..0fa3b3a 100644
--- a/elf/dl-sym.c
+++ b/elf/dl-sym.c
@@ -193,8 +193,13 @@ RTLD_NEXT used in code not dynamically loaded"));
 
       /* Resolve indirect function address.  */
       if (__builtin_expect (ELFW(ST_TYPE) (ref->st_info) == STT_GNU_IFUNC, 0))
- value
-  = ((DL_FIXUP_VALUE_TYPE (*) (void)) DL_FIXUP_VALUE_ADDR (value)) ();
+ {
+  DL_FIXUP_VALUE_TYPE fixup
+    = DL_FIXUP_MAKE_VALUE (result, (ElfW(Addr)) value);
+  fixup =
+    ((DL_FIXUP_VALUE_TYPE (*) (void)) DL_FIXUP_VALUE_ADDR (fixup)) ();
+  value = (void *) DL_FIXUP_VALUE_CODE_ADDR (fixup);
+ }
 
 #ifdef SHARED
       /* Auditing checkpoint: we have a new binding.  Provide the
diff --git a/elf/ifuncmain3.c b/elf/ifuncmain3.c
index 5d067cc..1574dd5 100644
--- a/elf/ifuncmain3.c
+++ b/elf/ifuncmain3.c
@@ -46,6 +46,15 @@ main (void)
       return 1;
     }
 
+  p = dlsym (h, "foo");
+  if (p == NULL)
+    {
+      printf ("symbol not found: %s\n", dlerror ());
+      return 1;
+    }
+  if ((*p) () != -1)
+    abort ();
+
   f = dlsym (h, "get_foo_p");
   if (f == NULL)
     {

Re: PATCH: Properly handle STT_GNU_IFUNC symbols in do_sym

by Petr Baudis-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

  Hi!

On Sun, Nov 01, 2009 at 09:34:18AM -0800, H.J. Lu wrote:
> do_sym should use DL_FIXUP_VALUE_XXX macros to call IFUNC function.
> Otherwise, it won't compile on ia64. This patch fixes it and adds
> a test.

  BTW, are you sure the ifunc implementation in elf/dl-runtime.c is
correct on IA64? It seems to use struct fdesc * as function pointer, I
think it should use DL_FIXUP_VALUE_CODE_ADDR () instead.

--
                                Petr "Pasky" Baudis
A lot of people have my books on their bookshelves.
That's the problem, they need to read them. -- Don Knuth

Re: PATCH: Properly handle STT_GNU_IFUNC symbols in do_sym

by Petr Baudis-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Fri, Nov 06, 2009 at 03:06:07AM +0100, Petr Baudis wrote:
> On Sun, Nov 01, 2009 at 09:34:18AM -0800, H.J. Lu wrote:
> > do_sym should use DL_FIXUP_VALUE_XXX macros to call IFUNC function.
> > Otherwise, it won't compile on ia64. This patch fixes it and adds
> > a test.
>
>   BTW, are you sure the ifunc implementation in elf/dl-runtime.c is
> correct on IA64? It seems to use struct fdesc * as function pointer, I
> think it should use DL_FIXUP_VALUE_CODE_ADDR () instead.

Oh, never mind that, I got wrong impression about IA64 from the orignial
broken dl-sym.c code, apparently it's an ok thing to do.

                                Petr "Pasky" Baudis

Re: PATCH: Properly handle STT_GNU_IFUNC symbols in do_sym

by H.J. Lu-30 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Thu, Nov 5, 2009 at 7:06 PM, Petr Baudis <pasky@...> wrote:

>  Hi!
>
> On Sun, Nov 01, 2009 at 09:34:18AM -0800, H.J. Lu wrote:
>> do_sym should use DL_FIXUP_VALUE_XXX macros to call IFUNC function.
>> Otherwise, it won't compile on ia64. This patch fixes it and adds
>> a test.
>
>  BTW, are you sure the ifunc implementation in elf/dl-runtime.c is
> correct on IA64? It seems to use struct fdesc * as function pointer, I
> think it should use DL_FIXUP_VALUE_CODE_ADDR () instead.
>

We will fix any IFUNC problems when it is implemented on ia64.
Right now, it is OK on ia64 as long as it compiles.

--
H.J.