1 /* Routines for GCC for ARM/pe.
2 Copyright (C) 1995, 1996, 2000, 2001, 2002 Free Software Foundation, Inc.
3 Contributed by Doug Evans (dje@cygnus.com).
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
32 extern int current_function_anonymous_args
;
35 /* Return non-zero if DECL is a dllexport'd object. */
37 tree current_class_type
; /* FIXME */
40 arm_dllexport_p (decl
)
45 if (TREE_CODE (decl
) != VAR_DECL
46 && TREE_CODE (decl
) != FUNCTION_DECL
)
48 exp
= lookup_attribute ("dllexport", DECL_ATTRIBUTES (decl
));
55 /* Return non-zero if DECL is a dllimport'd object. */
58 arm_dllimport_p (decl
)
63 if (TREE_CODE (decl
) == FUNCTION_DECL
64 && TARGET_NOP_FUN_DLLIMPORT
)
67 if (TREE_CODE (decl
) != VAR_DECL
68 && TREE_CODE (decl
) != FUNCTION_DECL
)
70 imp
= lookup_attribute ("dllimport", DECL_ATTRIBUTES (decl
));
77 /* Return non-zero if SYMBOL is marked as being dllexport'd. */
80 arm_dllexport_name_p (symbol
)
83 return symbol
[0] == ARM_PE_FLAG_CHAR
&& symbol
[1] == 'e' && symbol
[2] == '.';
86 /* Return non-zero if SYMBOL is marked as being dllimport'd. */
89 arm_dllimport_name_p (symbol
)
92 return symbol
[0] == ARM_PE_FLAG_CHAR
&& symbol
[1] == 'i' && symbol
[2] == '.';
95 /* Mark a DECL as being dllexport'd.
96 Note that we override the previous setting (eg: dllimport). */
99 arm_mark_dllexport (decl
)
102 const char * oldname
;
107 rtlname
= XEXP (DECL_RTL (decl
), 0);
108 if (GET_CODE (rtlname
) == SYMBOL_REF
)
109 oldname
= XSTR (rtlname
, 0);
110 else if (GET_CODE (rtlname
) == MEM
111 && GET_CODE (XEXP (rtlname
, 0)) == SYMBOL_REF
)
112 oldname
= XSTR (XEXP (rtlname
, 0), 0);
115 if (arm_dllimport_name_p (oldname
))
117 else if (arm_dllexport_name_p (oldname
))
118 return; /* already done */
120 newname
= alloca (strlen (oldname
) + 4);
121 sprintf (newname
, "%ce.%s", ARM_PE_FLAG_CHAR
, oldname
);
123 /* We pass newname through get_identifier to ensure it has a unique
124 address. RTL processing can sometimes peek inside the symbol ref
125 and compare the string's addresses to see if two symbols are
127 /* ??? At least I think that's why we do this. */
128 idp
= get_identifier (newname
);
130 XEXP (DECL_RTL (decl
), 0) =
131 gen_rtx (SYMBOL_REF
, Pmode
, IDENTIFIER_POINTER (idp
));
134 /* Mark a DECL as being dllimport'd. */
137 arm_mark_dllimport (decl
)
140 const char * oldname
;
145 rtlname
= XEXP (DECL_RTL (decl
), 0);
147 if (GET_CODE (rtlname
) == SYMBOL_REF
)
148 oldname
= XSTR (rtlname
, 0);
149 else if (GET_CODE (rtlname
) == MEM
150 && GET_CODE (XEXP (rtlname
, 0)) == SYMBOL_REF
)
151 oldname
= XSTR (XEXP (rtlname
, 0), 0);
155 if (arm_dllexport_name_p (oldname
))
156 abort (); /* this shouldn't happen */
157 else if (arm_dllimport_name_p (oldname
))
158 return; /* already done */
160 /* ??? One can well ask why we're making these checks here,
161 and that would be a good question. */
163 /* Imported variables can't be initialized. */
164 if (TREE_CODE (decl
) == VAR_DECL
165 && !DECL_VIRTUAL_P (decl
)
166 && DECL_INITIAL (decl
))
168 error_with_decl (decl
, "initialized variable `%s' is marked dllimport");
171 /* Nor can they be static. */
172 if (TREE_CODE (decl
) == VAR_DECL
173 /* ??? Is this test for vtables needed? */
174 && !DECL_VIRTUAL_P (decl
)
177 error_with_decl (decl
, "static variable `%s' is marked dllimport");
181 /* `extern' needn't be specified with dllimport.
182 Specify `extern' now and hope for the best. Sigh. */
183 if (TREE_CODE (decl
) == VAR_DECL
184 /* ??? Is this test for vtables needed? */
185 && !DECL_VIRTUAL_P (decl
))
187 DECL_EXTERNAL (decl
) = 1;
188 TREE_PUBLIC (decl
) = 1;
191 newname
= alloca (strlen (oldname
) + 11);
192 sprintf (newname
, "%ci.__imp_%s", ARM_PE_FLAG_CHAR
, oldname
);
194 /* We pass newname through get_identifier to ensure it has a unique
195 address. RTL processing can sometimes peek inside the symbol ref
196 and compare the string's addresses to see if two symbols are
198 /* ??? At least I think that's why we do this. */
199 idp
= get_identifier (newname
);
201 newrtl
= gen_rtx (MEM
, Pmode
,
202 gen_rtx (SYMBOL_REF
, Pmode
,
203 IDENTIFIER_POINTER (idp
)));
204 XEXP (DECL_RTL (decl
), 0) = newrtl
;
208 arm_pe_encode_section_info (decl
, first
)
210 int first ATTRIBUTE_UNUSED
;
212 /* This bit is copied from arm_encode_section_info. */
213 if (optimize
> 0 && TREE_CONSTANT (decl
)
214 && (!flag_writable_strings
|| TREE_CODE (decl
) != STRING_CST
))
216 rtx rtl
= (TREE_CODE_CLASS (TREE_CODE (decl
)) != 'd'
217 ? TREE_CST_RTL (decl
) : DECL_RTL (decl
));
218 SYMBOL_REF_FLAG (XEXP (rtl
, 0)) = 1;
221 /* Mark the decl so we can tell from the rtl whether the object is
222 dllexport'd or dllimport'd. */
223 if (arm_dllexport_p (decl
))
224 arm_mark_dllexport (decl
);
225 else if (arm_dllimport_p (decl
))
226 arm_mark_dllimport (decl
);
227 /* It might be that DECL has already been marked as dllimport, but a
228 subsequent definition nullified that. The attribute is gone but
229 DECL_RTL still has @i.__imp_foo. We need to remove that. */
230 else if ((TREE_CODE (decl
) == FUNCTION_DECL
231 || TREE_CODE (decl
) == VAR_DECL
)
232 && DECL_RTL (decl
) != NULL_RTX
233 && GET_CODE (DECL_RTL (decl
)) == MEM
234 && GET_CODE (XEXP (DECL_RTL (decl
), 0)) == MEM
235 && GET_CODE (XEXP (XEXP (DECL_RTL (decl
), 0), 0)) == SYMBOL_REF
236 && arm_dllimport_name_p (XSTR (XEXP (XEXP (DECL_RTL (decl
), 0), 0), 0)))
238 const char *oldname
= XSTR (XEXP (XEXP (DECL_RTL (decl
), 0), 0), 0);
239 tree idp
= get_identifier (oldname
+ 9);
240 rtx newrtl
= gen_rtx (SYMBOL_REF
, Pmode
, IDENTIFIER_POINTER (idp
));
242 XEXP (DECL_RTL (decl
), 0) = newrtl
;
244 /* We previously set TREE_PUBLIC and DECL_EXTERNAL.
245 ??? We leave these alone for now. */
250 arm_pe_unique_section (decl
, reloc
)
259 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
260 /* Strip off any encoding in fnname. */
261 STRIP_NAME_ENCODING (name
, name
);
263 /* The object is put in, for example, section .text$foo.
264 The linker will then ultimately place them in .text
265 (everything from the $ on is stripped). */
266 if (TREE_CODE (decl
) == FUNCTION_DECL
)
268 else if (DECL_READONLY_SECTION (decl
, reloc
))
272 len
= strlen (name
) + strlen (prefix
);
273 string
= alloca (len
+ 1);
274 sprintf (string
, "%s%s", prefix
, name
);
276 DECL_SECTION_NAME (decl
) = build_string (len
, string
);