This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: Patch[mingw/cygwin]: Fix dllimport "unmarking" thinko in winnt.c [Take 2]
- From: Danny Smith <danny_r_smith_2001 at yahoo dot co dot nz>
- To: gcc-patches at gcc dot gnu dot org
- Cc: cgf at redhat dot com, chorns at users dot sourceforge dot net
- Date: Tue, 11 Mar 2003 20:17:19 +1100 (EST)
- Subject: Re: Patch[mingw/cygwin]: Fix dllimport "unmarking" thinko in winnt.c [Take 2]
"Christopher Faylor" wrote:
> On Thu, Mar 06, 2003 at 09:16:18AM +1100, Danny Smith wrote:
> >Hello,
> >
> >The modifications to provide __fastcall support
> >
> >http://gcc.gnu.org/ml/gcc-cvs/2002-12/msg00633.html
> >
> >introduced mistakes in config/i386/winnt.c.
== 8< ==
> Rather than using oldname += 3, wouldn't it make sense to define a
constant
> so that it was little more obvious what the "3" referred to?
>
> cgf
Well, this cleans up a bit more than that to get rid of most of the magic
numbers.
I've replaced the use of DLL_IMPORT_EXPORT_PREFIX combined with the
strings "e." and "i." with two new defines: DLL_IMPORT_PREFIX and
DLL_EXPORT_PREFIX. These new symbolic constants get used throughout.
This seemed to be easier to follow than fooling around with a lot of
string/char concatenations
Danny
ChangeLog
2003-03-11 Danny Smith <dannysmith at users dot sourceforge dot net>
* config/i386/winnt.c (DLL_IMPORT_PREFIX): New define.
Use throughout instead of DLL_IMPORT_EXPORT_PREFIX and "e."
(DLL_EXPORT_PREFIX): New define.
Use throughout instead of DLL_IMPORT_EXPORT_PREFIX and "i."
(i386_pe_dllexport_name_p): Here.
(i386_pe_dllimport_name_p): Here.
(i386_pe_mark_dllexport): Here. Remove leading 3 chars,
not 9 when getting identifier name.
(i386_pe_mark_dllimport): Here.
(i386_pe_encode_section_info): Here. Remove leading 3 chars,
not 9 when getting identifier name. Correct comment.
(i386_pe_strip_name_encoding): Here. Add comments for different
cases.
(gen_fastcall_suffix): Break down xmalloc() argument to
components.
(gen_stdcall_suffix): Likewise.
Update copyright year.
Index: winnt.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/i386/winnt.c,v
retrieving revision 1.40
diff -c -3 -p -r1.40 winnt.c
*** winnt.c 26 Dec 2002 18:45:04 -0000 1.40
--- winnt.c 11 Mar 2003 08:54:48 -0000
***************
*** 1,6 ****
/* Subroutines for insn-output.c for Windows NT.
Contributed by Douglas Rupp (drupp at cs dot washington dot edu)
! Copyright (C) 1995, 1997, 1998, 1999, 2000, 2001, 2002
Free Software Foundation, Inc.
This file is part of GNU CC.
--- 1,6 ----
/* Subroutines for insn-output.c for Windows NT.
Contributed by Douglas Rupp (drupp at cs dot washington dot edu)
! Copyright (C) 1995, 1997, 1998, 1999, 2000, 2001, 2002, 2003
Free Software Foundation, Inc.
This file is part of GNU CC.
*************** int i386_pe_dllimport_p PARAMS ((tree));
*** 54,59 ****
--- 54,68 ----
void i386_pe_mark_dllexport PARAMS ((tree));
void i386_pe_mark_dllimport PARAMS ((tree));
+ /* This is we how mark internal identifiers with dllimport or dllexport
+ attributes. */
+ #ifndef DLL_IMPORT_PREFIX
+ #define DLL_IMPORT_PREFIX "#i."
+ #endif
+ #ifndef DLL_EXPORT_PREFIX
+ #define DLL_EXPORT_PREFIX "#e."
+ #endif
+
/* Handle a "dllimport" or "dllexport" attribute;
arguments as in struct attribute_spec.handler. */
tree
*************** int
*** 202,209 ****
i386_pe_dllexport_name_p (symbol)
const char *symbol;
{
! return symbol[0] == DLL_IMPORT_EXPORT_PREFIX
! && symbol[1] == 'e' && symbol[2] == '.';
}
/* Return nonzero if SYMBOL is marked as being dllimport'd. */
--- 211,218 ----
i386_pe_dllexport_name_p (symbol)
const char *symbol;
{
! return (strncmp (DLL_EXPORT_PREFIX, symbol,
! strlen (DLL_EXPORT_PREFIX)) == 0);
}
/* Return nonzero if SYMBOL is marked as being dllimport'd. */
*************** int
*** 212,219 ****
i386_pe_dllimport_name_p (symbol)
const char *symbol;
{
! return symbol[0] == DLL_IMPORT_EXPORT_PREFIX
! && symbol[1] == 'i' && symbol[2] == '.';
}
/* Mark a DECL as being dllexport'd.
--- 221,228 ----
i386_pe_dllimport_name_p (symbol)
const char *symbol;
{
! return (strncmp (DLL_IMPORT_PREFIX, symbol,
! strlen (DLL_IMPORT_PREFIX)) == 0);
}
/* Mark a DECL as being dllexport'd.
*************** i386_pe_mark_dllexport (decl)
*** 237,248 ****
else
abort ();
if (i386_pe_dllimport_name_p (oldname))
! oldname += 9;
else if (i386_pe_dllexport_name_p (oldname))
return; /* already done */
! newname = alloca (strlen (oldname) + 4);
! sprintf (newname, "%ce.%s", DLL_IMPORT_EXPORT_PREFIX, oldname);
/* We pass newname through get_identifier to ensure it has a unique
address. RTL processing can sometimes peek inside the symbol ref
--- 246,258 ----
else
abort ();
if (i386_pe_dllimport_name_p (oldname))
! /* Remove DLL_IMPORT_PREFIX. */
! oldname += strlen (DLL_IMPORT_PREFIX);
else if (i386_pe_dllexport_name_p (oldname))
return; /* already done */
! newname = alloca (strlen (DLL_EXPORT_PREFIX) + strlen (oldname) + 1);
! sprintf (newname, "%s%s", DLL_EXPORT_PREFIX, oldname);
/* We pass newname through get_identifier to ensure it has a unique
address. RTL processing can sometimes peek inside the symbol ref
*************** i386_pe_mark_dllimport (decl)
*** 316,323 ****
return;
}
! newname = alloca (strlen (oldname) + 4);
! sprintf (newname, "%ci.%s", DLL_IMPORT_EXPORT_PREFIX, oldname);
/* We pass newname through get_identifier to ensure it has a unique
address. RTL processing can sometimes peek inside the symbol ref
--- 326,333 ----
return;
}
! newname = alloca (strlen (DLL_IMPORT_PREFIX) + strlen (oldname) + 1);
! sprintf (newname, "%s%s", DLL_IMPORT_PREFIX, oldname);
/* We pass newname through get_identifier to ensure it has a unique
address. RTL processing can sometimes peek inside the symbol ref
*************** gen_fastcall_suffix (decl)
*** 366,372 ****
}
}
! newsym = xmalloc (strlen (asmname) + 11);
sprintf (newsym, "%c%s at %d", FASTCALL_PREFIX, asmname, total/BITS_PER_UNIT);
return IDENTIFIER_POINTER (get_identifier (newsym));
}
--- 376,383 ----
}
}
! /* Assume max of 8 base 10 digits in the suffix. */
! newsym = xmalloc (1 + strlen (asmname) + 1 + 8 + 1);
sprintf (newsym, "%c%s at %d", FASTCALL_PREFIX, asmname, total/BITS_PER_UNIT);
return IDENTIFIER_POINTER (get_identifier (newsym));
}
*************** gen_stdcall_suffix (decl)
*** 404,410 ****
}
}
! newsym = xmalloc (strlen (asmname) + 10);
sprintf (newsym, "%s at %d", asmname, total/BITS_PER_UNIT);
return IDENTIFIER_POINTER (get_identifier (newsym));
}
--- 415,422 ----
}
}
! /* Assume max of 8 base 10 digits in the suffix. */
! newsym = xmalloc (strlen (asmname) + 1 + 8 + 1);
sprintf (newsym, "%s at %d", asmname, total/BITS_PER_UNIT);
return IDENTIFIER_POINTER (get_identifier (newsym));
}
*************** i386_pe_encode_section_info (decl, first
*** 447,454 ****
i386_pe_mark_dllimport (decl);
/* It might be that DECL has already been marked as dllimport, but a
subsequent definition nullified that. The attribute is gone but
! DECL_RTL still has (DLL_IMPORT_EXPORT_PREFIX)i._imp__foo. We need
! to remove that. Ditto for the DECL_NON_ADDR_CONST_P flag. */
else if ((TREE_CODE (decl) == FUNCTION_DECL
|| TREE_CODE (decl) == VAR_DECL)
&& DECL_RTL (decl) != NULL_RTX
--- 459,466 ----
i386_pe_mark_dllimport (decl);
/* It might be that DECL has already been marked as dllimport, but a
subsequent definition nullified that. The attribute is gone but
! DECL_RTL still has (DLL_IMPORT_PREFIX) prefixed. We need to remove
! that. Ditto for the DECL_NON_ADDR_CONST_P flag. */
else if ((TREE_CODE (decl) == FUNCTION_DECL
|| TREE_CODE (decl) == VAR_DECL)
&& DECL_RTL (decl) != NULL_RTX
*************** i386_pe_encode_section_info (decl, first
*** 458,464 ****
&& i386_pe_dllimport_name_p (XSTR (XEXP (XEXP (DECL_RTL (decl), 0), 0),
0)))
{
const char *oldname = XSTR (XEXP (XEXP (DECL_RTL (decl), 0), 0), 0);
! tree idp = get_identifier (oldname + 9);
rtx newrtl = gen_rtx (SYMBOL_REF, Pmode, IDENTIFIER_POINTER (idp));
XEXP (DECL_RTL (decl), 0) = newrtl;
--- 470,477 ----
&& i386_pe_dllimport_name_p (XSTR (XEXP (XEXP (DECL_RTL (decl), 0), 0),
0)))
{
const char *oldname = XSTR (XEXP (XEXP (DECL_RTL (decl), 0), 0), 0);
! /* Remove DLL_IMPORT_PREFIX. */
! tree idp = get_identifier (oldname + strlen (DLL_IMPORT_PREFIX));
rtx newrtl = gen_rtx (SYMBOL_REF, Pmode, IDENTIFIER_POINTER (idp));
XEXP (DECL_RTL (decl), 0) = newrtl;
*************** const char *
*** 477,484 ****
i386_pe_strip_name_encoding (str)
const char *str;
{
! if (*str == DLL_IMPORT_EXPORT_PREFIX)
! str += 3;
if (*str == '*')
str += 1;
return str;
--- 490,501 ----
i386_pe_strip_name_encoding (str)
const char *str;
{
! if (strncmp (str, DLL_IMPORT_PREFIX, strlen (DLL_IMPORT_PREFIX))
! == 0)
! str += strlen (DLL_IMPORT_PREFIX);
! else if (strncmp (str, DLL_EXPORT_PREFIX, strlen (DLL_EXPORT_PREFIX))
! == 0)
! str += strlen (DLL_EXPORT_PREFIX);
if (*str == '*')
str += 1;
return str;
*************** void i386_pe_output_labelref (stream, na
*** 508,537 ****
FILE *stream;
const char *name;
{
! char prefix[4];
!
! sprintf (prefix, "%ci.", DLL_IMPORT_EXPORT_PREFIX);
! if (strncmp (name, prefix, strlen (prefix)) == 0)
! {
! if (name[3] == FASTCALL_PREFIX)
{
fprintf (stream, "__imp_%s",
i386_pe_strip_name_encoding (name));
}
else
{
fprintf (stream, "__imp__%s",
i386_pe_strip_name_encoding (name));
}
}
else if ((name[0] == FASTCALL_PREFIX)
! || ((name[0] == DLL_IMPORT_EXPORT_PREFIX)
! && (name[3] == FASTCALL_PREFIX)))
{
fprintf (stream, "%s",
i386_pe_strip_name_encoding (name));
}
else
{
fprintf (stream, "%s%s", USER_LABEL_PREFIX,
i386_pe_strip_name_encoding (name));
--- 525,559 ----
FILE *stream;
const char *name;
{
! if (strncmp (name, DLL_IMPORT_PREFIX, strlen (DLL_IMPORT_PREFIX))
! == 0)
! /* A dll import */
! {
! if (name[strlen (DLL_IMPORT_PREFIX)] == FASTCALL_PREFIX)
! /* A dllimport fastcall symbol. */
{
fprintf (stream, "__imp_%s",
i386_pe_strip_name_encoding (name));
}
else
+ /* A dllimport non-fastcall symbol. */
{
fprintf (stream, "__imp__%s",
i386_pe_strip_name_encoding (name));
}
}
else if ((name[0] == FASTCALL_PREFIX)
! || (strncmp (name, DLL_EXPORT_PREFIX,
! strlen (DLL_EXPORT_PREFIX)
! == 0
! && name[strlen (DLL_EXPORT_PREFIX)] == FASTCALL_PREFIX)))
! /* A fastcall symbol. */
{
fprintf (stream, "%s",
i386_pe_strip_name_encoding (name));
}
else
+ /* Everything else. */
{
fprintf (stream, "%s%s", USER_LABEL_PREFIX,
i386_pe_strip_name_encoding (name));
http://mobile.yahoo.com.au - Yahoo! Mobile
- Check & compose your email via SMS on your Telstra or Vodafone mobile.