OSDN Git Service

* pa/elf.h, pa/som.h (ASM_OUTPUT_EXTERNAL): Use assemble_name_raw
[pf3gnuchains/gcc-fork.git] / gcc / config / pa / som.h
1 /* Definitions for SOM assembler support.
2    Copyright (C) 1999, 2001, 2002, 2003, 2004, 2005 Free Software Foundation,
3    Inc.
4
5 This file is part of GCC.
6
7 GCC 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)
10 any later version.
11
12 GCC 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.
16
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING.  If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA.  */
21
22 /* So we can conditionalize small amounts of code in pa.c or pa.md.  */
23 #undef TARGET_SOM
24 #define TARGET_SOM 1
25
26 /* We do not use BINCL stabs in SOM.
27    ??? If it does not hurt, we probably should to avoid useless divergence
28    from other embedded stabs implementations.  */
29 #undef DBX_USE_BINCL
30
31 #define DBX_LINES_FUNCTION_RELATIVE 1
32
33 /* gdb needs a null N_SO at the end of each file for scattered loading.  */
34
35 #define DBX_OUTPUT_NULL_N_SO_AT_MAIN_SOURCE_FILE_END
36
37 /* Select a format to encode pointers in exception handling data.  CODE
38    is 0 for data, 1 for code labels, 2 for function pointers.  GLOBAL is
39    true if the symbol may be affected by dynamic relocations.  Because
40    the HP assembler does auto alignment, it is necessary to use
41    DW_EH_PE_aligned instead of the default DW_EH_PE_absptr.  */
42
43 #define ASM_PREFERRED_EH_DATA_FORMAT(CODE, GLOBAL) \
44   (TARGET_GAS ? DW_EH_PE_absptr : DW_EH_PE_aligned)
45
46 /* HPUX has a program 'chatr' to list the dependencies of dynamically
47    linked executables and shared libraries.  */
48 #define LDD_SUFFIX "chatr"
49 /* Look for lines like "dynamic   /usr/lib/X11R5/libX11.sl"
50    or "static    /usr/lib/X11R5/libX11.sl". 
51
52    HPUX 10.20 also has lines like "static branch prediction ..."
53    so we filter that out explicitly.
54
55    We also try to bound our search for libraries with marker
56    lines.  What a pain.  */
57 #define PARSE_LDD_OUTPUT(PTR)                                   \
58 do {                                                            \
59   static int in_shlib_list = 0;                                 \
60   while (*PTR == ' ') PTR++;                                    \
61   if (strncmp (PTR, "shared library list:",                     \
62                sizeof ("shared library list:") - 1) == 0)       \
63     {                                                           \
64       PTR = 0;                                                  \
65       in_shlib_list = 1;                                        \
66     }                                                           \
67   else if (strncmp (PTR, "shared library binding:",             \
68                     sizeof ("shared library binding:") - 1) == 0)\
69     {                                                           \
70       PTR = 0;                                                  \
71       in_shlib_list = 0;                                        \
72     }                                                           \
73   else if (strncmp (PTR, "static branch prediction disabled",   \
74                     sizeof ("static branch prediction disabled") - 1) == 0)\
75     {                                                           \
76       PTR = 0;                                                  \
77       in_shlib_list = 0;                                        \
78     }                                                           \
79   else if (in_shlib_list                                        \
80            &&  strncmp (PTR, "dynamic", sizeof ("dynamic") - 1) == 0) \
81     {                                                           \
82       PTR += sizeof ("dynamic") - 1;                            \
83       while (*p == ' ') PTR++;                                  \
84     }                                                           \
85   else if (in_shlib_list                                        \
86            && strncmp (PTR, "static", sizeof ("static") - 1) == 0) \
87     {                                                           \
88       PTR += sizeof ("static") - 1;                             \
89       while (*p == ' ') PTR++;                                  \
90     }                                                           \
91   else                                                          \
92     PTR = 0;                                                    \
93 } while (0)
94
95 /* Output the label for a function definition.  */
96 #ifndef HP_FP_ARG_DESCRIPTOR_REVERSED
97 #define ASM_DOUBLE_ARG_DESCRIPTORS(FILE, ARG0, ARG1)    \
98   do { fprintf (FILE, ",ARGW%d=FR", (ARG0));            \
99        fprintf (FILE, ",ARGW%d=FU", (ARG1));} while (0)
100 #define DFMODE_RETURN_STRING ",RTNVAL=FU"
101 #define SFMODE_RETURN_STRING ",RTNVAL=FR"
102 #else
103 #define ASM_DOUBLE_ARG_DESCRIPTORS(FILE, ARG0, ARG1)    \
104   do { fprintf (FILE, ",ARGW%d=FU", (ARG0));            \
105        fprintf (FILE, ",ARGW%d=FR", (ARG1));} while (0)
106 #define DFMODE_RETURN_STRING ",RTNVAL=FR"
107 #define SFMODE_RETURN_STRING ",RTNVAL=FU"
108 #endif
109
110 \f
111 #define ASM_DECLARE_FUNCTION_NAME(FILE, NAME, DECL) \
112     do { tree fntype = TREE_TYPE (TREE_TYPE (DECL));                    \
113          tree tree_type = TREE_TYPE (DECL);                             \
114          tree parm;                                                     \
115          int i;                                                         \
116          if (TREE_PUBLIC (DECL) || TARGET_GAS)                          \
117            {                                                            \
118              if (TREE_PUBLIC (DECL))                                    \
119                {                                                        \
120                  fputs ("\t.EXPORT ", FILE);                            \
121                  assemble_name (FILE, NAME);                            \
122                  fputs (",ENTRY,PRIV_LEV=3", FILE);                     \
123                }                                                        \
124              else                                                       \
125                {                                                        \
126                  fputs ("\t.PARAM ", FILE);                             \
127                  assemble_name (FILE, NAME);                            \
128                  fputs (",PRIV_LEV=3", FILE);                           \
129                }                                                        \
130              for (parm = DECL_ARGUMENTS (DECL), i = 0; parm && i < 4;   \
131                   parm = TREE_CHAIN (parm))                             \
132                {                                                        \
133                  if (TYPE_MODE (DECL_ARG_TYPE (parm)) == SFmode         \
134                      && ! TARGET_SOFT_FLOAT)                            \
135                    fprintf (FILE, ",ARGW%d=FR", i++);                   \
136                  else if (TYPE_MODE (DECL_ARG_TYPE (parm)) == DFmode    \
137                           && ! TARGET_SOFT_FLOAT)                       \
138                    {                                                    \
139                      if (i <= 2)                                        \
140                        {                                                \
141                          if (i == 1) i++;                               \
142                          ASM_DOUBLE_ARG_DESCRIPTORS (FILE, i++, i++);   \
143                        }                                                \
144                      else                                               \
145                        break;                                           \
146                    }                                                    \
147                  else                                                   \
148                    {                                                    \
149                      int arg_size =                                     \
150                        FUNCTION_ARG_SIZE (TYPE_MODE (DECL_ARG_TYPE (parm)),\
151                                           DECL_ARG_TYPE (parm));        \
152                      /* Passing structs by invisible reference uses     \
153                         one general register.  */                       \
154                      if (arg_size > 2                                   \
155                          || TREE_ADDRESSABLE (DECL_ARG_TYPE (parm)))    \
156                        arg_size = 1;                                    \
157                      if (arg_size == 2 && i <= 2)                       \
158                        {                                                \
159                          if (i == 1) i++;                               \
160                          fprintf (FILE, ",ARGW%d=GR", i++);             \
161                          fprintf (FILE, ",ARGW%d=GR", i++);             \
162                        }                                                \
163                      else if (arg_size == 1)                            \
164                        fprintf (FILE, ",ARGW%d=GR", i++);               \
165                      else                                               \
166                        i += arg_size;                                   \
167                    }                                                    \
168                }                                                        \
169              /* anonymous args */                                       \
170              if (TYPE_ARG_TYPES (tree_type) != 0                        \
171                  && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (tree_type)))\
172                      != void_type_node))                                \
173                {                                                        \
174                  for (; i < 4; i++)                                     \
175                    fprintf (FILE, ",ARGW%d=GR", i);                     \
176                }                                                        \
177              if (TYPE_MODE (fntype) == DFmode && ! TARGET_SOFT_FLOAT)   \
178                fputs (DFMODE_RETURN_STRING, FILE);                      \
179              else if (TYPE_MODE (fntype) == SFmode && ! TARGET_SOFT_FLOAT) \
180                fputs (SFMODE_RETURN_STRING, FILE);                      \
181              else if (fntype != void_type_node)                         \
182                fputs (",RTNVAL=GR", FILE);                              \
183              fputs ("\n", FILE);                                        \
184            }} while (0)
185
186 #define TARGET_ASM_FILE_START pa_som_file_start
187
188 /* String to output before text.  */
189 #define TEXT_SECTION_ASM_OP som_text_section_asm_op ()
190
191 /* String to output before writable data.  */
192 #define DATA_SECTION_ASM_OP "\t.SPACE $PRIVATE$\n\t.SUBSPA $DATA$\n"
193
194 /* String to output before uninitialized data.  */
195 #define BSS_SECTION_ASM_OP "\t.SPACE $PRIVATE$\n\t.SUBSPA $BSS$\n"
196
197 /* FIXME: HPUX ld generates incorrect GOT entries for "T" fixups
198    which reference data within the $TEXT$ space (for example constant
199    strings in the $LIT$ subspace).
200
201    The assemblers (GAS and HP as) both have problems with handling
202    the difference of two symbols which is the other correct way to
203    reference constant data during PIC code generation.
204
205    So, there's no way to reference constant data which is in the
206    $TEXT$ space during PIC generation.  Instead place all constant
207    data into the $PRIVATE$ subspace (this reduces sharing, but it
208    works correctly).  */
209 #define READONLY_DATA_SECTION \
210   (flag_pic ? data_section : som_readonly_data_section)
211
212 /* We must not have a reference to an external symbol defined in a
213    shared library in a readonly section, else the SOM linker will
214    complain.
215
216    So, we force exception information into the data section.  */
217 #define TARGET_ASM_EXCEPTION_SECTION data_section
218
219 /* This is how to output a command to make the user-level label
220    named NAME defined for reference from other files.  We use
221    assemble_name_raw instead of assemble_name since a symbol in
222    a .IMPORT directive that isn't otherwise referenced is not
223    placed in the symbol table of the assembled object.
224
225    Failure to import a function reference can cause the HP linker
226    to segmentation fault!
227
228    Note that the SOM based tools need the symbol imported as a
229    CODE symbol, while the ELF based tools require the symbol to
230    be imported as an ENTRY symbol.  */
231
232 #define ASM_OUTPUT_EXTERNAL(FILE, DECL, NAME) \
233   do { fputs ("\t.IMPORT ", FILE);                                      \
234        assemble_name_raw (FILE, NAME);                                  \
235        if (FUNCTION_NAME_P (NAME))                                      \
236          fputs (",CODE\n", FILE);                                       \
237        else                                                             \
238          fputs (",DATA\n", FILE);                                       \
239      } while (0)
240
241 /* The bogus HP assembler requires ALL external references to be
242    "imported", even library calls. They look a bit different, so
243    here's this macro.
244
245    Also note not all libcall names are passed to pa_encode_section_info
246    (__main for example).  To make sure all libcall names have section
247    info recorded in them, we do it here.  We must also ensure that
248    we don't import a libcall that has been previously exported since
249    the HP assembler may change an ENTRY symbol to a CODE symbol.  */
250
251 #define ASM_OUTPUT_EXTERNAL_LIBCALL(FILE, RTL) \
252   do { const char *name;                                                \
253        tree id;                                                         \
254                                                                         \
255        if (!function_label_operand (RTL, VOIDmode))                     \
256          hppa_encode_label (RTL);                                       \
257                                                                         \
258        name = targetm.strip_name_encoding (XSTR ((RTL), 0));            \
259        id = maybe_get_identifier (name);                                \
260        if (!id || !TREE_SYMBOL_REFERENCED (id))                         \
261          {                                                              \
262            fputs ("\t.IMPORT ", FILE);                                  \
263            assemble_name (FILE, XSTR ((RTL), 0));                       \
264            fputs (",CODE\n", FILE);                                     \
265          }                                                              \
266      } while (0)
267
268 /* We want __gcc_plt_call to appear in every program built by
269    gcc, so we make a reference to it out of __main.
270    We use the asm statement to fool the optimizer into not
271    removing the dead (but important) initialization of
272    REFERENCE.  */
273
274 #define DO_GLOBAL_DTORS_BODY                    \
275 do {                                            \
276   extern void __gcc_plt_call (void);            \
277   void (*reference)(void) = &__gcc_plt_call;    \
278   func_ptr *p;                                  \
279   __asm__ ("" : : "r" (reference));             \
280   for (p = __DTOR_LIST__ + 1; *p; )             \
281     (*p++) ();                                  \
282 } while (0)
283
284 /* This macro specifies the biggest alignment supported by the object
285    file format of this machine.
286
287    The .align directive in the HP assembler allows alignments up to 4096
288    bytes.  However, the maximum alignment of a global common symbol is 8
289    bytes for objects smaller than the page size (4096 bytes).  For larger
290    objects, the linker provides an alignment of 32 bytes.  Unfortunately,
291    this macro doesn't provide a mechanism to test for common symbols.  */
292 #define MAX_OFILE_ALIGNMENT 32768
293
294 /* The SOM linker hardcodes paths into binaries.  As a result, dotdots
295    must be removed from library prefixes to prevent binaries from depending
296    on the location of the GCC tool directory.  The downside is GCC
297    cannot be moved after installation using a symlink.  */
298 #define ALWAYS_STRIP_DOTDOT 1
299
300 /* Aggregates with a single float or double field should be passed and
301    returned in the general registers.  */
302 #define MEMBER_TYPE_FORCES_BLK(FIELD, MODE) (MODE==SFmode || MODE==DFmode)
303
304 /* If GAS supports weak, we can support weak when we have working linker
305    support for secondary definitions and are generating code for GAS.  */
306 #ifdef HAVE_GAS_WEAK
307 #define SUPPORTS_WEAK (TARGET_SOM_SDEF && TARGET_GAS)
308 #else
309 #define SUPPORTS_WEAK 0
310 #endif
311
312 /* CVS GAS as of 4/28/04 supports a comdat parameter for the .nsubspa
313    directive.  This provides one-only linkage semantics even though we
314    don't have weak support.  */
315 #ifdef HAVE_GAS_NSUBSPA_COMDAT
316 #define SUPPORTS_SOM_COMDAT (TARGET_GAS)
317 #else
318 #define SUPPORTS_SOM_COMDAT 0
319 #endif
320
321 /* We can support one only if we support weak or comdat.  */
322 #define SUPPORTS_ONE_ONLY (SUPPORTS_WEAK || SUPPORTS_SOM_COMDAT)
323
324 /* We use DECL_COMMON for uninitialized one-only variables as we don't
325    have linkonce .bss.  We use SOM secondary definitions or comdat for
326    initialized variables and functions.  */
327 #define MAKE_DECL_ONE_ONLY(DECL) \
328   do {                                                                  \
329     if (TREE_CODE (DECL) == VAR_DECL                                    \
330         && (DECL_INITIAL (DECL) == 0                                    \
331             || DECL_INITIAL (DECL) == error_mark_node))                 \
332       DECL_COMMON (DECL) = 1;                                           \
333     else if (SUPPORTS_WEAK)                                             \
334       DECL_WEAK (DECL) = 1;                                             \
335   } while (0)
336
337 /* This is how we tell the assembler that a symbol is weak.  The SOM
338    weak implementation uses the secondary definition (sdef) flag.
339
340    The behavior of sdef symbols is similar to ELF weak symbols in that
341    multiple definitions can occur without incurring a link error.
342    However, they differ in the following ways:
343      1) Undefined sdef symbols are not allowed.
344      2) The linker searches for undefined sdef symbols and will load an
345         archive library member to resolve an undefined sdef symbol.
346      3) The exported symbol from a shared library is a primary symbol
347         rather than a sdef symbol.  Thus, more care is needed in the
348         ordering of libraries.
349
350    It appears that the linker discards extra copies of "weak" functions
351    when linking shared libraries, independent of whether or not they
352    are in their own section.  In linking final executables, -Wl,-O can
353    be used to remove dead procedures.  Thus, support for named sections
354    is not needed and in previous testing caused problems with various
355    HP tools.  */
356 #define ASM_WEAKEN_LABEL(FILE,NAME) \
357   do { fputs ("\t.weak\t", FILE);                               \
358        assemble_name (FILE, NAME);                              \
359        fputc ('\n', FILE);                                      \
360        if (! FUNCTION_NAME_P (NAME))                            \
361          {                                                      \
362            fputs ("\t.EXPORT ", FILE);                          \
363            assemble_name (FILE, NAME);                          \
364            fputs (",DATA\n", FILE);                             \
365          }                                                      \
366   } while (0)
367
368 /* We can't handle weak aliases, and therefore can't support pragma weak.
369    Suppress the use of pragma weak in gthr-dce.h and gthr-posix.h.  */
370 #define GTHREAD_USE_WEAK 0