libtool
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: dlpreopening not working for __stdcall functions


From: Carlos Sánchez de La Lama
Subject: Re: dlpreopening not working for __stdcall functions
Date: Wed, 08 Aug 2018 14:01:22 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux)

I somehow sent it before attaching the files :S

Attachment: Makefile
Description: Binary data

#include <stdlib.h>
#include "ltdl.h"

#ifdef STDCALL
#define MODULE_STDCALL __stdcall
#define MODULE_SUFFIX "_stdcall"
#else
#define MODULE_STDCALL
#define MODULE_SUFFIX ""
#endif

#define module_foo (*module_foo_p)

static int MODULE_STDCALL module_foo ();

static lt_dlhandle module;

int
main (void)
{
  LTDL_SET_PRELOADED_SYMBOLS();

  lt_dlinit ();

  lt_dlsetsearchpath(".libs");

  module = lt_dlopenext ("libmodule" MODULE_SUFFIX);
  if (module == NULL)
    module = lt_dlopen ("libmodule" MODULE_SUFFIX ".a");
  if (module == NULL)
    {
      puts (lt_dlerror ());
      lt_dlexit ();
      exit (EXIT_FAILURE);
    }
      
  *(void **) (&module_foo_p) =
    lt_dlsym (module, "module_foo");

  module_foo ();

  exit (EXIT_SUCCESS);
}
#include <stdio.h>

#ifdef STDCALL
#define MODULE_STDCALL __stdcall
#else
#define MODULE_STDCALL
#endif

/* Dummy sumbol to ensure table is generated. */
int dummy;

int MODULE_STDCALL
module_foo (int x, int y)
{
  printf("foo\n");
}
--- libtool.old 2018-08-08 08:03:29 +0000
+++ libtool     2018-08-08 11:48:34 +0000
@@ -167,10 +167,10 @@
 LTCFLAGS="-O3 -s -mms-bitfields -march=i386 -mtune=i686"
 
 # Take the output of nm and produce a listing of raw symbols and C names.
-global_symbol_pipe="sed -n -e 's/^.*[   ]\\([ABCDGIRSTW][ABCDGIRSTW]*\\)[      
 ][      ]*_\\([_A-Za-z][_A-Za-z0-9]*\\)\\{0,1\\}\$/\\1 _\\2 \\2/p' | sed '/ 
__gnu_lto/d'"
+global_symbol_pipe="sed -n -e 's/^.*[   ]\\([ABCDGIRSTW][ABCDGIRSTW]*\\)[      
 ][      
]*_\\(\\([_A-Za-z][_A-Za-z0-9]*\\)\\(@[0-9][0-9]*\\)\\?\\)\\{0,1\\}\$/\\1 _\\2 
\\3/p' | sed '/ __gnu_lto/d'"
 
 # Transform the output of nm in a proper C declaration.
-global_symbol_to_cdecl="sed -n -e 's/^T .* \\(.*\\)\$/extern int \\1();/p' -e 
's/^[ABCDGIRSTW]* .* \\(.*\\)\$/extern char \\1;/p'"
+global_symbol_to_cdecl="(sed -n -e 's/^T address@hidden([0-9][0-9]*\\) 
\\(.*\\)\$/extern int __stdcall \\2(@\\1@);/p' -e 's/^T .* \\(.*\\)\$/extern 
int \\1();/p' -e 's/^[ABCDGIRSTW]* .* \\(.*\\)\$/extern char \\1;/p' | awk -F @ 
'{printf(\$1); if (\$2 > 0) {printf(\"int\"); for (i=4; i < \$2; i=i+4) 
{printf(\", int\")}}; printf(\$3)}')"
 
 # Transform the output of nm in a C name address pair.
 global_symbol_to_c_name_address="sed -n -e 's/^: \\([^ ]*\\)[ ]*\$/  
{\\\"\\1\\\", (void *) 0},/p' -e 's/^[ABCDGIRSTW]* \\([^ ]*\\) \\([^ ]*\\)\$/  
{\"\\2\", (void *) \\&\\2},/p'"
address@hidden (Carlos Sánchez de La Lama) writes:

> Hi all,
>
> it seems stdcall function decorations prevent those symbols to be
> recognized in func_generate_dlsyms. I attach a small example of this
> (only can be replicated on win32 hosts, I am using mingw32).
>
> The makefile generates 4 files:
> loader -> works
> loader_static -> works (dlpreloads the module)
> loader_stdcall -> works (uses stdcall but no dlpreloads)
> loader_stdcall_static -> segfaults (module_foo symbol is not there)
>
> I also attach a patch for main libtool script that makes it work. I am
> going to prepare a proper patch over HEAD libtool.m4, but if anyone has
> any comments please let me know.
>
> BR
>
> Carlos

-- 
Carlos

reply via email to

[Prev in Thread] Current Thread [Next in Thread]