OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [gcc-4.2.2/] [gcc/] [config/] [arm/] [pe.c] - Blame information for rev 816

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 38 julius
/* Routines for GCC for ARM/pe.
2
   Copyright (C) 1995, 1996, 2000, 2001, 2002, 2004, 2005, 2007
3
   Free Software Foundation, Inc.
4
   Contributed by Doug Evans (dje@cygnus.com).
5
 
6
   This file is part of GCC.
7
 
8
   GCC is free software; you can redistribute it and/or modify it
9
   under the terms of the GNU General Public License as published
10
   by the Free Software Foundation; either version 3, or (at your
11
   option) any later version.
12
 
13
   GCC is distributed in the hope that it will be useful, but WITHOUT
14
   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15
   or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
16
   License for more details.
17
 
18
   You should have received a copy of the GNU General Public License
19
   along with GCC; see the file COPYING3.  If not see
20
   <http://www.gnu.org/licenses/>.  */
21
 
22
#include "config.h"
23
#include "system.h"
24
#include "coretypes.h"
25
#include "tm.h"
26
#include "rtl.h"
27
#include "output.h"
28
#include "flags.h"
29
#include "tree.h"
30
#include "expr.h"
31
#include "toplev.h"
32
#include "tm_p.h"
33
 
34
extern int current_function_anonymous_args;
35
 
36
 
37
/* Return nonzero if DECL is a dllexport'd object.  */
38
 
39
tree current_class_type; /* FIXME */
40
 
41
int
42
arm_dllexport_p (decl)
43
     tree decl;
44
{
45
  tree exp;
46
 
47
  if (TREE_CODE (decl) != VAR_DECL
48
      && TREE_CODE (decl) != FUNCTION_DECL)
49
    return 0;
50
  exp = lookup_attribute ("dllexport", DECL_ATTRIBUTES (decl));
51
  if (exp)
52
    return 1;
53
 
54
  return 0;
55
}
56
 
57
/* Return nonzero if DECL is a dllimport'd object.  */
58
 
59
int
60
arm_dllimport_p (decl)
61
     tree decl;
62
{
63
  tree imp;
64
 
65
  if (TREE_CODE (decl) == FUNCTION_DECL
66
      && TARGET_NOP_FUN_DLLIMPORT)
67
    return 0;
68
 
69
  if (TREE_CODE (decl) != VAR_DECL
70
      && TREE_CODE (decl) != FUNCTION_DECL)
71
    return 0;
72
  imp = lookup_attribute ("dllimport", DECL_ATTRIBUTES (decl));
73
  if (imp)
74
    return 1;
75
 
76
  return 0;
77
}
78
 
79
/* Return nonzero if SYMBOL is marked as being dllexport'd.  */
80
 
81
int
82
arm_dllexport_name_p (symbol)
83
     const char * symbol;
84
{
85
  return symbol[0] == ARM_PE_FLAG_CHAR && symbol[1] == 'e' && symbol[2] == '.';
86
}
87
 
88
/* Return nonzero if SYMBOL is marked as being dllimport'd.  */
89
 
90
int
91
arm_dllimport_name_p (symbol)
92
     const char * symbol;
93
{
94
  return symbol[0] == ARM_PE_FLAG_CHAR && symbol[1] == 'i' && symbol[2] == '.';
95
}
96
 
97
/* Mark a DECL as being dllexport'd.
98
   Note that we override the previous setting (e.g.: dllimport).  */
99
 
100
void
101
arm_mark_dllexport (decl)
102
     tree decl;
103
{
104
  const char * oldname;
105
  char * newname;
106
  rtx rtlname;
107
  tree idp;
108
 
109
  rtlname = XEXP (DECL_RTL (decl), 0);
110
  if (GET_CODE (rtlname) == MEM)
111
    rtlname = XEXP (rtlname, 0);
112
  gcc_assert (GET_CODE (rtlname) == SYMBOL_REF);
113
  oldname = XSTR (rtlname, 0);
114
 
115
  if (arm_dllimport_name_p (oldname))
116
    oldname += 9;
117
  else if (arm_dllexport_name_p (oldname))
118
    return; /* already done */
119
 
120
  newname = alloca (strlen (oldname) + 4);
121
  sprintf (newname, "%ce.%s", ARM_PE_FLAG_CHAR, oldname);
122
 
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
126
     identical.  */
127
  /* ??? At least I think that's why we do this.  */
128
  idp = get_identifier (newname);
129
 
130
  XEXP (DECL_RTL (decl), 0) =
131
    gen_rtx_SYMBOL_REF (Pmode, IDENTIFIER_POINTER (idp));
132
}
133
 
134
/* Mark a DECL as being dllimport'd.  */
135
 
136
void
137
arm_mark_dllimport (decl)
138
     tree decl;
139
{
140
  const char * oldname;
141
  char * newname;
142
  tree idp;
143
  rtx rtlname, newrtl;
144
 
145
  rtlname = XEXP (DECL_RTL (decl), 0);
146
 
147
  if (GET_CODE (rtlname) == MEM)
148
    rtlname = XEXP (rtlname, 0);
149
  gcc_assert (GET_CODE (rtlname) == SYMBOL_REF);
150
  oldname = XSTR (rtlname, 0);
151
 
152
  gcc_assert (!arm_dllexport_name_p (oldname));
153
  if (arm_dllimport_name_p (oldname))
154
    return; /* already done */
155
 
156
  /* ??? One can well ask why we're making these checks here,
157
     and that would be a good question.  */
158
 
159
  /* Imported variables can't be initialized.  */
160
  if (TREE_CODE (decl) == VAR_DECL
161
      && !DECL_VIRTUAL_P (decl)
162
      && DECL_INITIAL (decl))
163
    {
164
      error ("initialized variable %q+D is marked dllimport", decl);
165
      return;
166
    }
167
  /* Nor can they be static.  */
168
  if (TREE_CODE (decl) == VAR_DECL
169
      /* ??? Is this test for vtables needed?  */
170
      && !DECL_VIRTUAL_P (decl)
171
      && 0 /*???*/)
172
    {
173
      error ("static variable %q+D is marked dllimport", decl);
174
      return;
175
    }
176
 
177
  /* `extern' needn't be specified with dllimport.
178
     Specify `extern' now and hope for the best.  Sigh.  */
179
  if (TREE_CODE (decl) == VAR_DECL
180
      /* ??? Is this test for vtables needed?  */
181
      && !DECL_VIRTUAL_P (decl))
182
    {
183
      DECL_EXTERNAL (decl) = 1;
184
      TREE_PUBLIC (decl) = 1;
185
    }
186
 
187
  newname = alloca (strlen (oldname) + 11);
188
  sprintf (newname, "%ci.__imp_%s", ARM_PE_FLAG_CHAR, oldname);
189
 
190
  /* We pass newname through get_identifier to ensure it has a unique
191
     address.  RTL processing can sometimes peek inside the symbol ref
192
     and compare the string's addresses to see if two symbols are
193
     identical.  */
194
  /* ??? At least I think that's why we do this.  */
195
  idp = get_identifier (newname);
196
 
197
  newrtl = gen_rtx_MEM (Pmode,
198
                        gen_rtx_SYMBOL_REF (Pmode,
199
                                            IDENTIFIER_POINTER (idp)));
200
  XEXP (DECL_RTL (decl), 0) = newrtl;
201
}
202
 
203
void
204
arm_pe_encode_section_info (decl, rtl, first)
205
     tree decl;
206
     rtx rtl;
207
     int first ATTRIBUTE_UNUSED;
208
{
209
  /* This bit is copied from arm_encode_section_info.  */
210
  if (optimize > 0 && TREE_CONSTANT (decl))
211
    SYMBOL_REF_FLAG (XEXP (rtl, 0)) = 1;
212
 
213
  /* Mark the decl so we can tell from the rtl whether the object is
214
     dllexport'd or dllimport'd.  */
215
  if (arm_dllexport_p (decl))
216
    arm_mark_dllexport (decl);
217
  else if (arm_dllimport_p (decl))
218
    arm_mark_dllimport (decl);
219
  /* It might be that DECL has already been marked as dllimport, but a
220
     subsequent definition nullified that.  The attribute is gone but
221
     DECL_RTL still has @i.__imp_foo.  We need to remove that.  */
222
  else if ((TREE_CODE (decl) == FUNCTION_DECL
223
            || TREE_CODE (decl) == VAR_DECL)
224
           && DECL_RTL (decl) != NULL_RTX
225
           && GET_CODE (DECL_RTL (decl)) == MEM
226
           && GET_CODE (XEXP (DECL_RTL (decl), 0)) == MEM
227
           && GET_CODE (XEXP (XEXP (DECL_RTL (decl), 0), 0)) == SYMBOL_REF
228
           && arm_dllimport_name_p (XSTR (XEXP (XEXP (DECL_RTL (decl), 0), 0), 0)))
229
    {
230
      const char *oldname = XSTR (XEXP (XEXP (DECL_RTL (decl), 0), 0), 0);
231
      tree idp = get_identifier (oldname + 9);
232
      rtx newrtl = gen_rtx_SYMBOL_REF (Pmode, IDENTIFIER_POINTER (idp));
233
 
234
      XEXP (DECL_RTL (decl), 0) = newrtl;
235
 
236
      /* We previously set TREE_PUBLIC and DECL_EXTERNAL.
237
         ??? We leave these alone for now.  */
238
    }
239
}
240
 
241
void
242
arm_pe_unique_section (decl, reloc)
243
     tree decl;
244
     int reloc;
245
{
246
  int len;
247
  const char * name;
248
  char * string;
249
  const char * prefix;
250
 
251
  name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
252
  name = arm_strip_name_encoding (name);
253
 
254
  /* The object is put in, for example, section .text$foo.
255
     The linker will then ultimately place them in .text
256
     (everything from the $ on is stripped).  */
257
  if (TREE_CODE (decl) == FUNCTION_DECL)
258
    prefix = ".text$";
259
  else if (decl_readonly_section (decl, reloc))
260
    prefix = ".rdata$";
261
  else
262
    prefix = ".data$";
263
  len = strlen (name) + strlen (prefix);
264
  string = alloca (len + 1);
265
  sprintf (string, "%s%s", prefix, name);
266
 
267
  DECL_SECTION_NAME (decl) = build_string (len, string);
268
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.