+#endif
+
+/* The default implementation of TARGET_USE_ANCHORS_FOR_SYMBOL_P. */
+
+bool
+default_use_anchors_for_symbol_p (const_rtx symbol)
+{
+ section *sect;
+ tree decl;
+
+ /* Don't use anchors for mergeable sections. The linker might move
+ the objects around. */
+ sect = SYMBOL_REF_BLOCK (symbol)->sect;
+ if (sect->common.flags & SECTION_MERGE)
+ return false;
+
+ /* Don't use anchors for small data sections. The small data register
+ acts as an anchor for such sections. */
+ if (sect->common.flags & SECTION_SMALL)
+ return false;
+
+ decl = SYMBOL_REF_DECL (symbol);
+ if (decl && DECL_P (decl))
+ {
+ /* Don't use section anchors for decls that might be defined by
+ other modules. */
+ if (!targetm.binds_local_p (decl))
+ return false;
+
+ /* Don't use section anchors for decls that will be placed in a
+ small data section. */
+ /* ??? Ideally, this check would be redundant with the SECTION_SMALL
+ one above. The problem is that we only use SECTION_SMALL for
+ sections that should be marked as small in the section directive. */
+ if (targetm.in_small_data_p (decl))
+ return false;
+ }
+ return true;
+}
+
+/* Assume ELF-ish defaults, since that's pretty much the most liberal
+ wrt cross-module name binding. */
+
+bool
+default_binds_local_p (const_tree exp)
+{
+ return default_binds_local_p_1 (exp, flag_shlib);
+}
+
+bool
+default_binds_local_p_1 (const_tree exp, int shlib)
+{
+ bool local_p;
+
+ /* A non-decl is an entry in the constant pool. */
+ if (!DECL_P (exp))
+ local_p = true;
+ /* Weakrefs may not bind locally, even though the weakref itself is
+ always static and therefore local. */
+ else if (lookup_attribute ("weakref", DECL_ATTRIBUTES (exp)))
+ local_p = false;
+ /* Static variables are always local. */
+ else if (! TREE_PUBLIC (exp))
+ local_p = true;
+ /* A variable is local if the user has said explicitly that it will
+ be. */
+ else if (DECL_VISIBILITY_SPECIFIED (exp)
+ && DECL_VISIBILITY (exp) != VISIBILITY_DEFAULT)
+ local_p = true;
+ /* Variables defined outside this object might not be local. */
+ else if (DECL_EXTERNAL (exp))
+ local_p = false;
+ /* If defined in this object and visibility is not default, must be
+ local. */
+ else if (DECL_VISIBILITY (exp) != VISIBILITY_DEFAULT)
+ local_p = true;
+ /* Default visibility weak data can be overridden by a strong symbol
+ in another module and so are not local. */
+ else if (DECL_WEAK (exp))
+ local_p = false;
+ /* If PIC, then assume that any global name can be overridden by
+ symbols resolved from other modules, unless we are compiling with
+ -fwhole-program, which assumes that names are local. */
+ else if (shlib)
+ local_p = flag_whole_program;
+ /* Uninitialized COMMON variable may be unified with symbols
+ resolved from other modules. */
+ else if (DECL_COMMON (exp)
+ && (DECL_INITIAL (exp) == NULL
+ || DECL_INITIAL (exp) == error_mark_node))
+ local_p = false;
+ /* Otherwise we're left with initialized (or non-common) global data
+ which is of necessity defined locally. */
+ else
+ local_p = true;
+
+ return local_p;
+}
+
+/* Determine whether or not a pointer mode is valid. Assume defaults
+ of ptr_mode or Pmode - can be overridden. */
+bool
+default_valid_pointer_mode (enum machine_mode mode)
+{
+ return (mode == ptr_mode || mode == Pmode);
+}
+
+/* Default function to output code that will globalize a label. A
+ target must define GLOBAL_ASM_OP or provide its own function to
+ globalize a label. */
+#ifdef GLOBAL_ASM_OP
+void
+default_globalize_label (FILE * stream, const char *name)
+{
+ fputs (GLOBAL_ASM_OP, stream);
+ assemble_name (stream, name);
+ putc ('\n', stream);
+}
+#endif /* GLOBAL_ASM_OP */
+
+/* Default function to output code that will globalize a declaration. */
+void
+default_globalize_decl_name (FILE * stream, tree decl)
+{
+ const char *name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
+ targetm.asm_out.globalize_label (stream, name);
+}
+
+/* Default function to output a label for unwind information. The
+ default is to do nothing. A target that needs nonlocal labels for
+ unwind information must provide its own function to do this. */
+void
+default_emit_unwind_label (FILE * stream ATTRIBUTE_UNUSED,
+ tree decl ATTRIBUTE_UNUSED,
+ int for_eh ATTRIBUTE_UNUSED,
+ int empty ATTRIBUTE_UNUSED)
+{
+}
+
+/* Default function to output a label to divide up the exception table.
+ The default is to do nothing. A target that needs/wants to divide
+ up the table must provide it's own function to do this. */
+void
+default_emit_except_table_label (FILE * stream ATTRIBUTE_UNUSED)
+{
+}
+
+/* This is how to output an internal numbered label where PREFIX is
+ the class of label and LABELNO is the number within the class. */
+
+void
+default_internal_label (FILE *stream, const char *prefix,
+ unsigned long labelno)
+{
+ char *const buf = (char *) alloca (40 + strlen (prefix));
+ ASM_GENERATE_INTERNAL_LABEL (buf, prefix, labelno);
+ ASM_OUTPUT_INTERNAL_LABEL (stream, buf);
+}
+
+/* This is the default behavior at the beginning of a file. It's
+ controlled by two other target-hook toggles. */
+void
+default_file_start (void)
+{
+ if (targetm.file_start_app_off
+ && !(flag_verbose_asm || flag_debug_asm || flag_dump_rtl_in_asm))
+ fputs (ASM_APP_OFF, asm_out_file);
+
+ if (targetm.file_start_file_directive)
+ output_file_directive (asm_out_file, main_input_filename);
+}
+
+/* This is a generic routine suitable for use as TARGET_ASM_FILE_END
+ which emits a special section directive used to indicate whether or
+ not this object file needs an executable stack. This is primarily
+ a GNU extension to ELF but could be used on other targets. */
+
+int trampolines_created;
+
+void
+file_end_indicate_exec_stack (void)
+{
+ unsigned int flags = SECTION_DEBUG;
+ if (trampolines_created)
+ flags |= SECTION_CODE;
+
+ switch_to_section (get_section (".note.GNU-stack", flags, NULL));
+}
+
+/* Output DIRECTIVE (a C string) followed by a newline. This is used as
+ a get_unnamed_section callback. */
+
+void
+output_section_asm_op (const void *directive)
+{
+ fprintf (asm_out_file, "%s\n", (const char *) directive);
+}
+
+/* Emit assembly code to switch to section NEW_SECTION. Do nothing if
+ the current section is NEW_SECTION. */
+
+void
+switch_to_section (section *new_section)
+{
+ if (in_section == new_section)
+ return;
+
+ if (new_section->common.flags & SECTION_FORGET)
+ in_section = NULL;
+ else
+ in_section = new_section;
+
+ switch (SECTION_STYLE (new_section))
+ {
+ case SECTION_NAMED:
+ if (cfun
+ && !crtl->subsections.unlikely_text_section_name
+ && strcmp (new_section->named.name,
+ UNLIKELY_EXECUTED_TEXT_SECTION_NAME) == 0)
+ crtl->subsections.unlikely_text_section_name = UNLIKELY_EXECUTED_TEXT_SECTION_NAME;
+
+ targetm.asm_out.named_section (new_section->named.name,
+ new_section->named.common.flags,
+ new_section->named.decl);
+ break;
+
+ case SECTION_UNNAMED:
+ new_section->unnamed.callback (new_section->unnamed.data);
+ break;
+
+ case SECTION_NOSWITCH:
+ gcc_unreachable ();
+ break;
+ }
+
+ new_section->common.flags |= SECTION_DECLARED;
+}
+
+/* If block symbol SYMBOL has not yet been assigned an offset, place
+ it at the end of its block. */
+
+void
+place_block_symbol (rtx symbol)
+{
+ unsigned HOST_WIDE_INT size, mask, offset;
+ struct constant_descriptor_rtx *desc;
+ unsigned int alignment;
+ struct object_block *block;
+ tree decl;
+
+ gcc_assert (SYMBOL_REF_BLOCK (symbol));
+ if (SYMBOL_REF_BLOCK_OFFSET (symbol) >= 0)
+ return;
+
+ /* Work out the symbol's size and alignment. */
+ if (CONSTANT_POOL_ADDRESS_P (symbol))
+ {
+ desc = SYMBOL_REF_CONSTANT (symbol);
+ alignment = desc->align;
+ size = GET_MODE_SIZE (desc->mode);
+ }
+ else if (TREE_CONSTANT_POOL_ADDRESS_P (symbol))
+ {
+ decl = SYMBOL_REF_DECL (symbol);
+ alignment = get_constant_alignment (decl);
+ size = get_constant_size (decl);
+ }
+ else
+ {
+ decl = SYMBOL_REF_DECL (symbol);
+ alignment = DECL_ALIGN (decl);
+ size = tree_low_cst (DECL_SIZE_UNIT (decl), 1);
+ }
+
+ /* Calculate the object's offset from the start of the block. */
+ block = SYMBOL_REF_BLOCK (symbol);
+ mask = alignment / BITS_PER_UNIT - 1;
+ offset = (block->size + mask) & ~mask;
+ SYMBOL_REF_BLOCK_OFFSET (symbol) = offset;
+
+ /* Record the block's new alignment and size. */
+ block->alignment = MAX (block->alignment, alignment);
+ block->size = offset + size;
+
+ VEC_safe_push (rtx, gc, block->objects, symbol);
+}
+
+/* Return the anchor that should be used to address byte offset OFFSET
+ from the first object in BLOCK. MODEL is the TLS model used
+ to access it. */
+
+rtx
+get_section_anchor (struct object_block *block, HOST_WIDE_INT offset,
+ enum tls_model model)
+{
+ char label[100];
+ unsigned int begin, middle, end;
+ unsigned HOST_WIDE_INT min_offset, max_offset, range, bias, delta;
+ rtx anchor;
+
+ /* Work out the anchor's offset. Use an offset of 0 for the first
+ anchor so that we don't pessimize the case where we take the address
+ of a variable at the beginning of the block. This is particularly
+ useful when a block has only one variable assigned to it.
+
+ We try to place anchors RANGE bytes apart, so there can then be
+ anchors at +/-RANGE, +/-2 * RANGE, and so on, up to the limits of
+ a ptr_mode offset. With some target settings, the lowest such
+ anchor might be out of range for the lowest ptr_mode offset;
+ likewise the highest anchor for the highest offset. Use anchors
+ at the extreme ends of the ptr_mode range in such cases.
+
+ All arithmetic uses unsigned integers in order to avoid
+ signed overflow. */
+ max_offset = (unsigned HOST_WIDE_INT) targetm.max_anchor_offset;
+ min_offset = (unsigned HOST_WIDE_INT) targetm.min_anchor_offset;
+ range = max_offset - min_offset + 1;
+ if (range == 0)
+ offset = 0;
+ else
+ {
+ bias = 1 << (GET_MODE_BITSIZE (ptr_mode) - 1);
+ if (offset < 0)
+ {
+ delta = -(unsigned HOST_WIDE_INT) offset + max_offset;
+ delta -= delta % range;
+ if (delta > bias)
+ delta = bias;
+ offset = (HOST_WIDE_INT) (-delta);
+ }
+ else
+ {
+ delta = (unsigned HOST_WIDE_INT) offset - min_offset;
+ delta -= delta % range;
+ if (delta > bias - 1)
+ delta = bias - 1;
+ offset = (HOST_WIDE_INT) delta;
+ }
+ }
+
+ /* Do a binary search to see if there's already an anchor we can use.
+ Set BEGIN to the new anchor's index if not. */
+ begin = 0;
+ end = VEC_length (rtx, block->anchors);
+ while (begin != end)
+ {
+ middle = (end + begin) / 2;
+ anchor = VEC_index (rtx, block->anchors, middle);
+ if (SYMBOL_REF_BLOCK_OFFSET (anchor) > offset)
+ end = middle;
+ else if (SYMBOL_REF_BLOCK_OFFSET (anchor) < offset)
+ begin = middle + 1;
+ else if (SYMBOL_REF_TLS_MODEL (anchor) > model)
+ end = middle;
+ else if (SYMBOL_REF_TLS_MODEL (anchor) < model)
+ begin = middle + 1;
+ else
+ return anchor;
+ }
+
+ /* Create a new anchor with a unique label. */
+ ASM_GENERATE_INTERNAL_LABEL (label, "LANCHOR", anchor_labelno++);
+ anchor = create_block_symbol (ggc_strdup (label), block, offset);
+ SYMBOL_REF_FLAGS (anchor) |= SYMBOL_FLAG_LOCAL | SYMBOL_FLAG_ANCHOR;
+ SYMBOL_REF_FLAGS (anchor) |= model << SYMBOL_FLAG_TLS_SHIFT;
+
+ /* Insert it at index BEGIN. */
+ VEC_safe_insert (rtx, gc, block->anchors, begin, anchor);
+ return anchor;
+}
+
+/* Output the objects in BLOCK. */
+
+static void
+output_object_block (struct object_block *block)
+{
+ struct constant_descriptor_rtx *desc;
+ unsigned int i;
+ HOST_WIDE_INT offset;
+ tree decl;
+ rtx symbol;
+
+ if (block->objects == NULL)
+ return;
+
+ /* Switch to the section and make sure that the first byte is
+ suitably aligned. */
+ switch_to_section (block->sect);
+ assemble_align (block->alignment);
+
+ /* Define the values of all anchors relative to the current section
+ position. */
+ for (i = 0; VEC_iterate (rtx, block->anchors, i, symbol); i++)
+ targetm.asm_out.output_anchor (symbol);
+
+ /* Output the objects themselves. */
+ offset = 0;
+ for (i = 0; VEC_iterate (rtx, block->objects, i, symbol); i++)
+ {
+ /* Move to the object's offset, padding with zeros if necessary. */
+ assemble_zeros (SYMBOL_REF_BLOCK_OFFSET (symbol) - offset);
+ offset = SYMBOL_REF_BLOCK_OFFSET (symbol);
+ if (CONSTANT_POOL_ADDRESS_P (symbol))
+ {
+ desc = SYMBOL_REF_CONSTANT (symbol);
+ output_constant_pool_1 (desc, 1);
+ offset += GET_MODE_SIZE (desc->mode);
+ }
+ else if (TREE_CONSTANT_POOL_ADDRESS_P (symbol))
+ {
+ decl = SYMBOL_REF_DECL (symbol);
+ assemble_constant_contents (decl, XSTR (symbol, 0),
+ get_constant_alignment (decl));
+ offset += get_constant_size (decl);
+ }
+ else
+ {
+ decl = SYMBOL_REF_DECL (symbol);
+ assemble_variable_contents (decl, XSTR (symbol, 0), false);
+ offset += tree_low_cst (DECL_SIZE_UNIT (decl), 1);
+ }
+ }
+}
+
+/* A htab_traverse callback used to call output_object_block for
+ each member of object_block_htab. */
+
+static int
+output_object_block_htab (void **slot, void *data ATTRIBUTE_UNUSED)
+{
+ output_object_block ((struct object_block *) (*slot));
+ return 1;
+}
+
+/* Output the definitions of all object_blocks. */
+
+void
+output_object_blocks (void)
+{
+ htab_traverse (object_block_htab, output_object_block_htab, NULL);
+}
+
+/* This function provides a possible implementation of the
+ TARGET_ASM_RECORD_GCC_SWITCHES target hook for ELF targets. When triggered
+ by -frecord-gcc-switches it creates a new mergeable, string section in the
+ assembler output file called TARGET_ASM_RECORD_GCC_SWITCHES_SECTION which
+ contains the switches in ASCII format.
+
+ FIXME: This code does not correctly handle double quote characters
+ that appear inside strings, (it strips them rather than preserving them).
+ FIXME: ASM_OUTPUT_ASCII, as defined in config/elfos.h will not emit NUL
+ characters - instead it treats them as sub-string separators. Since
+ we want to emit NUL strings terminators into the object file we have to use
+ ASM_OUTPUT_SKIP. */
+
+int
+elf_record_gcc_switches (print_switch_type type, const char * name)
+{
+ static char buffer[1024];
+
+ /* This variable is used as part of a simplistic heuristic to detect
+ command line switches which take an argument:
+
+ "If a command line option does not start with a dash then
+ it is an argument for the previous command line option."
+
+ This fails in the case of the command line option which is the name
+ of the file to compile, but otherwise it is pretty reasonable. */
+ static bool previous_name_held_back = FALSE;
+
+ switch (type)
+ {
+ case SWITCH_TYPE_PASSED:
+ if (* name != '-')
+ {
+ if (previous_name_held_back)
+ {
+ unsigned int len = strlen (buffer);
+
+ snprintf (buffer + len, sizeof buffer - len, " %s", name);
+ ASM_OUTPUT_ASCII (asm_out_file, buffer, strlen (buffer));
+ ASM_OUTPUT_SKIP (asm_out_file, (unsigned HOST_WIDE_INT) 1);
+ previous_name_held_back = FALSE;
+ }
+ else
+ {
+ strncpy (buffer, name, sizeof buffer);
+ ASM_OUTPUT_ASCII (asm_out_file, buffer, strlen (buffer));
+ ASM_OUTPUT_SKIP (asm_out_file, (unsigned HOST_WIDE_INT) 1);
+ }
+ }
+ else
+ {
+ if (previous_name_held_back)
+ {
+ ASM_OUTPUT_ASCII (asm_out_file, buffer, strlen (buffer));
+ ASM_OUTPUT_SKIP (asm_out_file, (unsigned HOST_WIDE_INT) 1);
+ }
+
+ strncpy (buffer, name, sizeof buffer);
+ previous_name_held_back = TRUE;
+ }
+ break;
+
+ case SWITCH_TYPE_DESCRIPTIVE:
+ if (name == NULL)
+ {
+ /* Distinguish between invocations where name is NULL. */
+ static bool started = false;
+
+ if (started)
+ {
+ if (previous_name_held_back)
+ {
+ ASM_OUTPUT_ASCII (asm_out_file, buffer, strlen (buffer));
+ ASM_OUTPUT_SKIP (asm_out_file, (unsigned HOST_WIDE_INT) 1);
+ }
+ }
+ else
+ {
+ section * sec;
+
+ sec = get_section (targetm.asm_out.record_gcc_switches_section,
+ SECTION_DEBUG
+ | SECTION_MERGE
+ | SECTION_STRINGS
+ | (SECTION_ENTSIZE & 1),
+ NULL);
+ switch_to_section (sec);
+ started = true;
+ }
+ }
+
+ default:
+ break;
+ }
+
+ /* The return value is currently ignored by the caller, but must be 0.
+ For -fverbose-asm the return value would be the number of characters
+ emitted into the assembler file. */
+ return 0;
+}
+
+/* Emit text to declare externally defined symbols. It is needed to
+ properly support non-default visibility. */
+void
+default_elf_asm_output_external (FILE *file ATTRIBUTE_UNUSED,
+ tree decl,
+ const char *name ATTRIBUTE_UNUSED)
+{
+ /* We output the name if and only if TREE_SYMBOL_REFERENCED is
+ set in order to avoid putting out names that are never really
+ used. */
+ if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))
+ && targetm.binds_local_p (decl))
+ maybe_assemble_visibility (decl);
+}
+
+#include "gt-varasm.h"