[prev in list] [next in list] [prev in thread] [next in thread] 

List:       binutils
Subject:    Suggested patch to dlltool
From:       Matthew Brett <matthew.brett () mrc-cbu ! cam ! ac ! uk>
Date:       2001-12-28 15:47:59
Message-ID: Pine.GSO.4.21.0112281546530.25391-200000 () sabik
[Download RAW message or body]

Dear friends,

I wonder if I could ask for comments on a suggested patch to dlltool.

I have made the changes to get round the problem I described in my ealier
email.  My motivation here is that I am trying to get g77 working as a
Fortran compiler for matlab, a matrix manipulation language by
Mathworks which is widely used in science.  For some time I have been
supporting gcc C/C++ as a compiler with matlab:

http://www.mrc-cbu.cam.ac.uk/Imaging/gnumex20.html

My problem is that the libraries provided with matlab expect the dll
function names to be decorated (MYFUNC@16), but the matlab Fortran files
do not generate decorated symbols (e.g. MYFUNC).  This is of course not
the usual way round; the WINAPI calls for example do not expect the
dll function names to be decorated, although they are stdcall.

My previous mail gives a test example of the problem, in C.

The only way I have found of successfully linking the matlab dlls to the
Fortran code, is to add an undecorated symbol for the functions in the
.text section of the library generated by dll, so the linker can resolve
the reference.  I have no idea why the fuzzy linking described for ld does
not solve the problem, but it doesn't.

So, I have added an option to dlltool, called --atless-lib-symbol, which
adds the required symbol to the library.  I know that this works on my
system (Win 2000), but I am afraid that I do not know enough about dlls to
know if this is safe, or if it is portable across platforms.  I would be
very grateful indeed for any feedback, suggestions.

Many thanks,

Matthew 


["dlltool.c.diff" (TEXT/PLAIN)]

386d385
< static int atless_lib_symbol;
2292c2291
<       asymbol *  ptrs[NSECS + 4 + EXTRA + 2];
---
>       asymbol *  ptrs[NSECS + 4 + EXTRA + 1];
2348,2370c2347,2353
< 	  /* function name; add atless lib symbol if required */
< 	  char * libsyms[2];
< 	  int i, symno = 1;
< 	  libsyms[0] = (char *) (exp->name);
< 	  if (atless_lib_symbol && strchr(exp->name, '@')) 
< 	    {
< 	      int lead_at = (*exp->name == '@');
< 	      char * atsym;
< 	      libsyms[1] = xstrdup (exp->name);
< 	      atsym = strchr (libsyms[1] + lead_at, '@');
< 	      if (*atsym)
< 		*atsym = '\0';
< 	      symno++;
< 	    }
< 	  for (i=0;i<symno;i++)
< 	    {
< 	      exp_label = bfd_make_empty_symbol (abfd);
< 	      exp_label->name = make_imp_label ("", libsyms[i]);
< 	      
< 	      /* On PowerPC, the function name points to a descriptor in
< 		 the rdata section, the first element of which is a
< 		 pointer to the code (..function_name), and the second
< 		 points to the .toc */
---
> 	  exp_label = bfd_make_empty_symbol (abfd);
> 	  exp_label->name = make_imp_label ("", exp->name);
> 
> 	  /* On PowerPC, the function name points to a descriptor in
> 	     the rdata section, the first element of which is a
> 	     pointer to the code (..function_name), and the second
> 	     points to the .toc */
2372,2374c2355,2357
< 	      if (machine == MPPC)
< 		exp_label->section = secdata[RDATA].sec;
< 	      else
---
> 	  if (machine == MPPC)
> 	    exp_label->section = secdata[RDATA].sec;
> 	  else
2376,2380c2359,2363
< 		exp_label->section = secdata[TEXT].sec;
< 	      
< 	      exp_label->flags = BSF_GLOBAL;
< 	      exp_label->value = 0;
< 	      
---
> 	    exp_label->section = secdata[TEXT].sec;
> 
> 	  exp_label->flags = BSF_GLOBAL;
> 	  exp_label->value = 0;
> 
2382,2383c2365,2366
< 	      if (machine == MTHUMB)
< 		bfd_coff_set_symbol_class (abfd, exp_label, C_THUMBEXTFUNC);
---
> 	  if (machine == MTHUMB)
> 	    bfd_coff_set_symbol_class (abfd, exp_label, C_THUMBEXTFUNC);
2385,2386c2368
< 	      ptrs[oidx++] = exp_label;
< 	    }
---
> 	  ptrs[oidx++] = exp_label;
3214d3195
<   fprintf (file, _("   -E --atless-lib-symbol    Add symbol to library to link without @<n>.\n"));
3253d3233
<   {"atless-lib-symbol", no_argument, NULL, 'E'},
3289c3269
< 			   "m:e:l:aD:d:z:b:xcCuUkAES:f:nvVhM:L:F:",
---
> 			   "m:e:l:aD:d:z:b:xcCuUkAS:f:nvVhM:L:F:",
3291c3271
< 			   "m:e:l:aD:d:z:b:xcCuUkAES:f:nvVh",
---
> 			   "m:e:l:aD:d:z:b:xcCuUkAS:f:nvVh",
3361,3363d3340
< 	  break;
< 	case 'E':
< 	  atless_lib_symbol = 1;


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic