OSDN Git Service

d8082d82b9eb83e7b46d73853f65043fb5532220
[pf3gnuchains/gcc-fork.git] / gcc / config / pa / som.h
1 /* Definitions for SOM assembler support.
2    Copyright (C) 1999, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
3
4 This file is part of GCC.
5
6 GCC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10
11 GCC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING.  If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA.  */
20
21 /* So we can conditionalize small amounts of code in pa.c or pa.md.  */
22 #undef TARGET_SOM
23 #define TARGET_SOM 1
24
25 /* We do not use BINCL stabs in SOM.
26    ??? If it does not hurt, we probably should to avoid useless divergence
27    from other embedded stabs implementations.  */
28 #undef DBX_USE_BINCL
29
30 /* We make the first line stab special to avoid adding several
31    gross hacks to GAS.  */
32 #undef  ASM_OUTPUT_SOURCE_LINE
33 #define ASM_OUTPUT_SOURCE_LINE(file, line, counter)             \
34   { static tree last_function_decl = NULL;                      \
35     if (current_function_decl == last_function_decl)            \
36       {                                                         \
37         rtx func = DECL_RTL (current_function_decl);            \
38         const char *name = XSTR (XEXP (func, 0), 0);            \
39         fprintf (file, "\t.stabn 68,0,%d,L$M%d-%s\nL$M%d:\n",   \
40                  line, counter,                                 \
41                  (* targetm.strip_name_encoding) (name),        \
42                  counter);                                      \
43       }                                                         \
44     else                                                        \
45       fprintf (file, "\t.stabn 68,0,%d,0\n", line);             \
46     last_function_decl = current_function_decl;                 \
47   }
48
49 /* gdb needs a null N_SO at the end of each file for scattered loading.  */
50
51 #undef  DBX_OUTPUT_MAIN_SOURCE_FILE_END
52 #define DBX_OUTPUT_MAIN_SOURCE_FILE_END(FILE, FILENAME) \
53   text_section (); \
54   fputs ("\t.SPACE $TEXT$\n\t.NSUBSPA $CODE$,QUAD=0,ALIGN=8,ACCESS=44,CODE_ONLY\n", FILE); \
55   fprintf (FILE,                                                        \
56            "\t.stabs \"\",%d,0,0,L$text_end0000\nL$text_end0000:\n", N_SO)
57
58 /* Select a format to encode pointers in exception handling data.  CODE
59    is 0 for data, 1 for code labels, 2 for function pointers.  GLOBAL is
60    true if the symbol may be affected by dynamic relocations.  Because
61    the HP assembler does auto alignment, it is necessary to use
62    DW_EH_PE_aligned instead of the default DW_EH_PE_absptr.  */
63
64 #define ASM_PREFERRED_EH_DATA_FORMAT(CODE, GLOBAL) \
65   (TARGET_GAS ? DW_EH_PE_absptr : DW_EH_PE_aligned)
66
67 /* HPUX has a program 'chatr' to list the dependencies of dynamically
68    linked executables and shared libraries.  */
69 #define LDD_SUFFIX "chatr"
70 /* Look for lines like "dynamic   /usr/lib/X11R5/libX11.sl"
71    or "static    /usr/lib/X11R5/libX11.sl". 
72
73    HPUX 10.20 also has lines like "static branch prediction ..."
74    so we filter that out explicitly.
75
76    We also try to bound our search for libraries with marker
77    lines.  What a pain.  */
78 #define PARSE_LDD_OUTPUT(PTR)                                   \
79 do {                                                            \
80   static int in_shlib_list = 0;                                 \
81   while (*PTR == ' ') PTR++;                                    \
82   if (strncmp (PTR, "shared library list:",                     \
83                sizeof ("shared library list:") - 1) == 0)       \
84     {                                                           \
85       PTR = 0;                                                  \
86       in_shlib_list = 1;                                        \
87     }                                                           \
88   else if (strncmp (PTR, "shared library binding:",             \
89                     sizeof ("shared library binding:") - 1) == 0)\
90     {                                                           \
91       PTR = 0;                                                  \
92       in_shlib_list = 0;                                        \
93     }                                                           \
94   else if (strncmp (PTR, "static branch prediction disabled",   \
95                     sizeof ("static branch prediction disabled") - 1) == 0)\
96     {                                                           \
97       PTR = 0;                                                  \
98       in_shlib_list = 0;                                        \
99     }                                                           \
100   else if (in_shlib_list                                        \
101            &&  strncmp (PTR, "dynamic", sizeof ("dynamic") - 1) == 0) \
102     {                                                           \
103       PTR += sizeof ("dynamic") - 1;                            \
104       while (*p == ' ') PTR++;                                  \
105     }                                                           \
106   else if (in_shlib_list                                        \
107            && strncmp (PTR, "static", sizeof ("static") - 1) == 0) \
108     {                                                           \
109       PTR += sizeof ("static") - 1;                             \
110       while (*p == ' ') PTR++;                                  \
111     }                                                           \
112   else                                                          \
113     PTR = 0;                                                    \
114 } while (0)
115
116 /* Output the label for a function definition.  */
117 #ifndef HP_FP_ARG_DESCRIPTOR_REVERSED
118 #define ASM_DOUBLE_ARG_DESCRIPTORS(FILE, ARG0, ARG1)    \
119   do { fprintf (FILE, ",ARGW%d=FR", (ARG0));            \
120        fprintf (FILE, ",ARGW%d=FU", (ARG1));} while (0)
121 #define DFMODE_RETURN_STRING ",RTNVAL=FU"
122 #define SFMODE_RETURN_STRING ",RTNVAL=FR"
123 #else
124 #define ASM_DOUBLE_ARG_DESCRIPTORS(FILE, ARG0, ARG1)    \
125   do { fprintf (FILE, ",ARGW%d=FU", (ARG0));            \
126        fprintf (FILE, ",ARGW%d=FR", (ARG1));} while (0)
127 #define DFMODE_RETURN_STRING ",RTNVAL=FR"
128 #define SFMODE_RETURN_STRING ",RTNVAL=FU"
129 #endif
130
131 \f
132 #define ASM_DECLARE_FUNCTION_NAME(FILE, NAME, DECL) \
133     do { tree fntype = TREE_TYPE (TREE_TYPE (DECL));                    \
134          tree tree_type = TREE_TYPE (DECL);                             \
135          tree parm;                                                     \
136          int i;                                                         \
137          if (TREE_PUBLIC (DECL) || TARGET_GAS)                          \
138            {                                                            \
139              if (TREE_PUBLIC (DECL))                                    \
140                {                                                        \
141                  fputs ("\t.EXPORT ", FILE);                            \
142                  assemble_name (FILE, NAME);                            \
143                  fputs (",ENTRY,PRIV_LEV=3", FILE);                     \
144                }                                                        \
145              else                                                       \
146                {                                                        \
147                  fputs ("\t.PARAM ", FILE);                             \
148                  assemble_name (FILE, NAME);                            \
149                  fputs (",PRIV_LEV=3", FILE);                           \
150                }                                                        \
151              for (parm = DECL_ARGUMENTS (DECL), i = 0; parm && i < 4;   \
152                   parm = TREE_CHAIN (parm))                             \
153                {                                                        \
154                  if (TYPE_MODE (DECL_ARG_TYPE (parm)) == SFmode         \
155                      && ! TARGET_SOFT_FLOAT)                            \
156                    fprintf (FILE, ",ARGW%d=FR", i++);                   \
157                  else if (TYPE_MODE (DECL_ARG_TYPE (parm)) == DFmode    \
158                           && ! TARGET_SOFT_FLOAT)                       \
159                    {                                                    \
160                      if (i <= 2)                                        \
161                        {                                                \
162                          if (i == 1) i++;                               \
163                          ASM_DOUBLE_ARG_DESCRIPTORS (FILE, i++, i++);   \
164                        }                                                \
165                      else                                               \
166                        break;                                           \
167                    }                                                    \
168                  else                                                   \
169                    {                                                    \
170                      int arg_size =                                     \
171                        FUNCTION_ARG_SIZE (TYPE_MODE (DECL_ARG_TYPE (parm)),\
172                                           DECL_ARG_TYPE (parm));        \
173                      /* Passing structs by invisible reference uses     \
174                         one general register.  */                       \
175                      if (arg_size > 2                                   \
176                          || TREE_ADDRESSABLE (DECL_ARG_TYPE (parm)))    \
177                        arg_size = 1;                                    \
178                      if (arg_size == 2 && i <= 2)                       \
179                        {                                                \
180                          if (i == 1) i++;                               \
181                          fprintf (FILE, ",ARGW%d=GR", i++);             \
182                          fprintf (FILE, ",ARGW%d=GR", i++);             \
183                        }                                                \
184                      else if (arg_size == 1)                            \
185                        fprintf (FILE, ",ARGW%d=GR", i++);               \
186                      else                                               \
187                        i += arg_size;                                   \
188                    }                                                    \
189                }                                                        \
190              /* anonymous args */                                       \
191              if (TYPE_ARG_TYPES (tree_type) != 0                        \
192                  && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (tree_type)))\
193                      != void_type_node))                                \
194                {                                                        \
195                  for (; i < 4; i++)                                     \
196                    fprintf (FILE, ",ARGW%d=GR", i);                     \
197                }                                                        \
198              if (TYPE_MODE (fntype) == DFmode && ! TARGET_SOFT_FLOAT)   \
199                fputs (DFMODE_RETURN_STRING, FILE);                      \
200              else if (TYPE_MODE (fntype) == SFmode && ! TARGET_SOFT_FLOAT) \
201                fputs (SFMODE_RETURN_STRING, FILE);                      \
202              else if (fntype != void_type_node)                         \
203                fputs (",RTNVAL=GR", FILE);                              \
204              fputs ("\n", FILE);                                        \
205            }} while (0)
206
207 #define TARGET_ASM_FILE_START pa_som_file_start
208
209 /* Select and return a TEXT_SECTION_ASM_OP string.  */
210 #define TEXT_SECTION_ASM_OP som_text_section_asm_op ()
211
212 /* Output before code in the default text section.  */
213 #define DEFAULT_TEXT_SECTION_ASM_OP "\t.SPACE $TEXT$\n\t.SUBSPA $CODE$"
214
215 /* Output before text in a new subspace.  This allows the linker to
216    place stubs between functions.  */
217 #define NEW_TEXT_SECTION_ASM_OP "\t.SPACE $TEXT$\n\t.NSUBSPA $CODE$"
218     
219 /* Output before text in a new one-only subspace.  */
220 #define ONE_ONLY_TEXT_SECTION_ASM_OP "\t.SPACE $TEXT$\n\
221 \t.NSUBSPA $CODE$,QUAD=0,ALIGN=8,ACCESS=44,SORT=24,COMDAT"
222
223 /* Output before read-only data.  */
224 #define READONLY_DATA_ASM_OP "\t.SPACE $TEXT$\n\t.SUBSPA $LIT$\n"
225
226 /* Output before one-only readonly data.  We make readonly data one only
227    by creating a new $LIT$ subspace in $TEXT$ with the comdat flag.  */
228 #define ONE_ONLY_READONLY_DATA_SECTION_ASM_OP "\t.SPACE $TEXT$\n\
229 \t.NSUBSPA $LIT$,QUAD=0,ALIGN=8,ACCESS=0x2c,SORT=16,COMDAT\n"
230
231 /* Output before writable data.  */
232 #define DATA_SECTION_ASM_OP "\t.SPACE $PRIVATE$\n\t.SUBSPA $DATA$\n"
233
234 /* Output before one-only data.  We make data one only by creating
235    a new $DATA$ subspace in $PRIVATE$ with the comdat flag.  */
236 #define ONE_ONLY_DATA_SECTION_ASM_OP "\t.SPACE $PRIVATE$\n\
237 \t.NSUBSPA $DATA$,QUAD=1,ALIGN=8,ACCESS=31,SORT=24,COMDAT\n"
238
239 /* Output before uninitialized data.  */
240 #define BSS_SECTION_ASM_OP "\t.SPACE $PRIVATE$\n\t.SUBSPA $BSS$\n"
241
242 #define EXTRA_SECTIONS                                                  \
243   in_readonly_data,                                                     \
244   in_one_only_readonly_data,                                            \
245   in_one_only_data
246
247 #define EXTRA_SECTION_FUNCTIONS                                         \
248   READONLY_DATA_FUNCTION                                                \
249   ONE_ONLY_READONLY_DATA_SECTION_FUNCTION                               \
250   ONE_ONLY_DATA_SECTION_FUNCTION                                        \
251   FORGET_SECTION_FUNCTION
252
253 #define READONLY_DATA_FUNCTION                                          \
254 void                                                                    \
255 readonly_data (void)                                                    \
256 {                                                                       \
257   if (in_section != in_readonly_data)                                   \
258     {                                                                   \
259       in_section = in_readonly_data;                                    \
260       fputs (READONLY_DATA_ASM_OP, asm_out_file);                       \
261     }                                                                   \
262 }                                                                       \
263
264 #define ONE_ONLY_READONLY_DATA_SECTION_FUNCTION                         \
265 void                                                                    \
266 one_only_readonly_data_section (void)                                   \
267 {                                                                       \
268   in_section = in_one_only_readonly_data;                               \
269   fputs (ONE_ONLY_READONLY_DATA_SECTION_ASM_OP, asm_out_file);          \
270 }                                                                       \
271
272 #define ONE_ONLY_DATA_SECTION_FUNCTION                                  \
273 void                                                                    \
274 one_only_data_section (void)                                            \
275 {                                                                       \
276   in_section = in_one_only_data;                                        \
277   fputs (ONE_ONLY_DATA_SECTION_ASM_OP, asm_out_file);                   \
278 }
279
280 #define FORGET_SECTION_FUNCTION                                         \
281 void                                                                    \
282 forget_section (void)                                                   \
283 {                                                                       \
284   in_section = no_section;                                              \
285 }                                                                       \
286
287 /* FIXME: HPUX ld generates incorrect GOT entries for "T" fixups
288    which reference data within the $TEXT$ space (for example constant
289    strings in the $LIT$ subspace).
290
291    The assemblers (GAS and HP as) both have problems with handling
292    the difference of two symbols which is the other correct way to
293    reference constant data during PIC code generation.
294
295    So, there's no way to reference constant data which is in the
296    $TEXT$ space during PIC generation.  Instead place all constant
297    data into the $PRIVATE$ subspace (this reduces sharing, but it
298    works correctly).  */
299 #define READONLY_DATA_SECTION (flag_pic ? data_section : readonly_data)
300
301 /* We must not have a reference to an external symbol defined in a
302    shared library in a readonly section, else the SOM linker will
303    complain.
304
305    So, we force exception information into the data section.  */
306 #define TARGET_ASM_EXCEPTION_SECTION data_section
307
308 /* This is how to output a command to make the user-level label named NAME
309    defined for reference from other files.
310
311    We call assemble_name, which in turn sets TREE_SYMBOL_REFERENCED.  This
312    macro will restore the original value of TREE_SYMBOL_REFERENCED to avoid
313    placing useless function definitions in the output file.
314
315    Also note that the SOM based tools need the symbol imported as a CODE
316    symbol, while the ELF based tools require the symbol to be imported as
317    an ENTRY symbol.  What a crock.  */
318
319 #define ASM_OUTPUT_EXTERNAL(FILE, DECL, NAME)   \
320   do { int save_referenced;                                     \
321        save_referenced = TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (DECL)); \
322        fputs ("\t.IMPORT ", FILE);                              \
323        assemble_name (FILE, NAME);                              \
324        if (FUNCTION_NAME_P (NAME))                              \
325          fputs (",CODE\n", FILE);                               \
326        else                                                     \
327          fputs (",DATA\n", FILE);                               \
328        TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (DECL)) = save_referenced; \
329      } while (0)
330
331 /* The bogus HP assembler requires ALL external references to be
332    "imported", even library calls. They look a bit different, so
333    here's this macro.
334
335    Also note not all libcall names are passed to pa_encode_section_info
336    (__main for example).  To make sure all libcall names have section
337    info recorded in them, we do it here.  We must also ensure that
338    we don't import a libcall that has been previously exported since
339    the HP assembler may change an ENTRY symbol to a CODE symbol.  */
340
341 #define ASM_OUTPUT_EXTERNAL_LIBCALL(FILE, RTL) \
342   do { const char *name;                                                \
343        tree id;                                                         \
344                                                                         \
345        if (!function_label_operand (RTL, VOIDmode))                     \
346          hppa_encode_label (RTL);                                       \
347                                                                         \
348        name = (*targetm.strip_name_encoding) (XSTR ((RTL), 0));         \
349        id = maybe_get_identifier (name);                                \
350        if (! id || ! TREE_SYMBOL_REFERENCED (id))                       \
351          {                                                              \
352            fputs ("\t.IMPORT ", FILE);                                  \
353            assemble_name (FILE, XSTR ((RTL), 0));                       \
354            fputs (",CODE\n", FILE);                                     \
355          }                                                              \
356      } while (0)
357
358 /* We want __gcc_plt_call to appear in every program built by
359    gcc, so we make a reference to it out of __main.
360    We use the asm statement to fool the optimizer into not
361    removing the dead (but important) initialization of
362    REFERENCE.  */
363
364 #define DO_GLOBAL_DTORS_BODY                    \
365 do {                                            \
366   extern void __gcc_plt_call (void);            \
367   void (*reference)(void) = &__gcc_plt_call;    \
368   func_ptr *p;                                  \
369   __asm__ ("" : : "r" (reference));             \
370   for (p = __DTOR_LIST__ + 1; *p; )             \
371     (*p++) ();                                  \
372 } while (0)
373
374 /* The .align directive in the HP assembler allows up to a 32 alignment.  */
375 #define MAX_OFILE_ALIGNMENT 32768
376
377 /* The SOM linker hardcodes paths into binaries.  As a result, dotdots
378    must be removed from library prefixes to prevent binaries from depending
379    on the location of the GCC tool directory.  The downside is GCC
380    cannot be moved after installation using a symlink.  */
381 #define ALWAYS_STRIP_DOTDOT 1
382
383 /* Aggregates with a single float or double field should be passed and
384    returned in the general registers.  */
385 #define MEMBER_TYPE_FORCES_BLK(FIELD, MODE) (MODE==SFmode || MODE==DFmode)
386
387 /* If GAS supports weak, we can support weak when we have working linker
388    support for secondary definitions and are generating code for GAS.  */
389 #ifdef HAVE_GAS_WEAK
390 #define SUPPORTS_WEAK (TARGET_SOM_SDEF && TARGET_GAS)
391 #else
392 #define SUPPORTS_WEAK 0
393 #endif
394
395 /* We can support one only if we support weak.  */
396 #define SUPPORTS_ONE_ONLY SUPPORTS_WEAK
397
398 /* Use weak (secondary definitions) to make one only declarations.  */
399 #define MAKE_DECL_ONE_ONLY(DECL) (DECL_WEAK (DECL) = 1)
400
401 /* This is how we tell the assembler that a symbol is weak.  The SOM
402    weak implementation uses the secondary definition (sdef) flag.
403
404    The behavior of sdef symbols is similar to ELF weak symbols in that
405    multiple definitions can occur without incurring a link error.
406    However, they differ in the following ways:
407      1) Undefined sdef symbols are not allowed.
408      2) The linker searches for undefined sdef symbols and will load an
409         archive library member to resolve an undefined sdef symbol.
410      3) The exported symbol from a shared library is a primary symbol
411         rather than a sdef symbol.  Thus, more care is needed in the
412         ordering of libraries.
413
414    It appears that the linker discards extra copies of "weak" functions
415    when linking shared libraries, independent of whether or not they
416    are in their own section.  In linking final executables, -Wl,-O can
417    be used to remove dead procedures.  Thus, support for named sections
418    is not needed and in previous testing caused problems with various
419    HP tools.  */
420 #define ASM_WEAKEN_LABEL(FILE,NAME) \
421   do { fputs ("\t.weak\t", FILE);                               \
422        assemble_name (FILE, NAME);                              \
423        fputc ('\n', FILE);                                      \
424        if (! FUNCTION_NAME_P (NAME))                            \
425          {                                                      \
426            fputs ("\t.EXPORT ", FILE);                          \
427            assemble_name (FILE, NAME);                          \
428            fputs (",DATA\n", FILE);                             \
429          }                                                      \
430   } while (0)
431
432 /* We can't handle weak aliases, and therefore can't support pragma weak.
433    Suppress the use of pragma weak in gthr-dce.h and gthr-posix.h.  */
434 #define GTHREAD_USE_WEAK 0