GCC Wikia
Advertisement

このページを編集する際は,編集に関する方針に従ってください.[]

概要[]

1591 /* Assemble everything that is needed for a variable or function declaration.
1592    Not used for automatic variables, and not used for function definitions.
1593    Should not be called for variables of incomplete structure type.
1594 
1595    TOP_LEVEL is nonzero if this variable has file scope.
1596    AT_END is nonzero if this is the special handling, at end of compilation,
1597    to define things that have had only tentative definitions.
1598    DONT_OUTPUT_DATA if nonzero means don't actually output the
1599    initial value (that will be done by the caller).  */

引数[]

実装[]

1601 void
1602 assemble_variable (tree decl, int top_level ATTRIBUTE_UNUSED,
1603                    int at_end ATTRIBUTE_UNUSED, int dont_output_data)
1604 {
1605   const char *name;
1606   unsigned int align;
1607   int reloc = 0;
1608   rtx decl_rtl;
1609 
1610   if (lang_hooks.decls.prepare_assemble_variable)
1611     lang_hooks.decls.prepare_assemble_variable (decl);
1612 
1613   last_assemble_variable_decl = 0;
1614 
1615   /* Normally no need to say anything here for external references,
1616      since assemble_external is called by the language-specific code
1617      when a declaration is first seen.  */
1618 
1619   if (DECL_EXTERNAL (decl))
1620     return;
1621 
1622   /* Output no assembler code for a function declaration.
1623      Only definitions of functions output anything.  */
1624 
1625   if (TREE_CODE (decl) == FUNCTION_DECL)
1626     return;
1627 
1628   /* Do nothing for global register variables.  */
1629   if (DECL_RTL_SET_P (decl) && REG_P (DECL_RTL (decl)))
1630     {
1631       TREE_ASM_WRITTEN (decl) = 1;
1632       return;
1633     }
1634 
1635   /* If type was incomplete when the variable was declared,
1636      see if it is complete now.  */
1637 
1638   if (DECL_SIZE (decl) == 0)
1639     layout_decl (decl, 0);
1640 
1641   /* Still incomplete => don't allocate it; treat the tentative defn
1642      (which is what it must have been) as an `extern' reference.  */
1643 
1644   if (!dont_output_data && DECL_SIZE (decl) == 0)
1645     {
1646       error ("storage size of %q+D isn%'t known", decl);
1647       TREE_ASM_WRITTEN (decl) = 1;
1648       return;
1649     }
1650 
1651   /* The first declaration of a variable that comes through this function
1652      decides whether it is global (in C, has external linkage)
1653      or local (in C, has internal linkage).  So do nothing more
1654      if this function has already run.  */
1655 
1656   if (TREE_ASM_WRITTEN (decl))
1657     return;
1658 
1659   /* Make sure targetm.encode_section_info is invoked before we set
1660      ASM_WRITTEN.  */
1661   decl_rtl = DECL_RTL (decl);
1662 
1663   TREE_ASM_WRITTEN (decl) = 1;
1664 
1665   /* Do no output if -fsyntax-only.  */
1666   if (flag_syntax_only)
1667     return;
1668 
1669   app_disable ();
1670 
1671   if (! dont_output_data
1672       && ! host_integerp (DECL_SIZE_UNIT (decl), 1))
1673     {
1674       error ("size of variable %q+D is too large", decl);
1675       return;
1676     }
1677 
1678   name = XSTR (XEXP (decl_rtl, 0), 0);
1679   if (TREE_PUBLIC (decl) && DECL_NAME (decl))
1680     notice_global_symbol (decl);
1681 
1682   /* Compute the alignment of this data.  */
1683 
1684   align = DECL_ALIGN (decl);
1685 
1686   /* In the case for initialing an array whose length isn't specified,
1687      where we have not yet been able to do the layout,
1688      figure out the proper alignment now.  */
1689   if (dont_output_data && DECL_SIZE (decl) == 0
1690       && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
1691     align = MAX (align, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl))));
1692 
1693   /* Some object file formats have a maximum alignment which they support.
1694      In particular, a.out format supports a maximum alignment of 4.  */
1695   if (align > MAX_OFILE_ALIGNMENT)
1696     {
1697       warning (0, "alignment of %q+D is greater than maximum object "
1698                "file alignment.  Using %d", decl,
1699                MAX_OFILE_ALIGNMENT/BITS_PER_UNIT);
1700       align = MAX_OFILE_ALIGNMENT;
1701     }
1702 
1703   /* On some machines, it is good to increase alignment sometimes.  */
1704   if (! DECL_USER_ALIGN (decl))
1705     {
1706 #ifdef DATA_ALIGNMENT
1707       align = DATA_ALIGNMENT (TREE_TYPE (decl), align);
1708 #endif
1709 #ifdef CONSTANT_ALIGNMENT
1710       if (DECL_INITIAL (decl) != 0 && DECL_INITIAL (decl) != error_mark_node)
1711         align = CONSTANT_ALIGNMENT (DECL_INITIAL (decl), align);
1712 #endif
1713     }
1714 
1715   /* Reset the alignment in case we have made it tighter, so we can benefit
1716      from it in get_pointer_alignment.  */
1717   DECL_ALIGN (decl) = align;
1718   set_mem_align (decl_rtl, align);
1719 
1720   if (TREE_PUBLIC (decl))
1721     maybe_assemble_visibility (decl);
1722 
1723   if (DECL_PRESERVE_P (decl))
1724     targetm.asm_out.mark_decl_preserved (name);
1725 
1726   /* Handle uninitialized definitions.  */
1727 
1728   /* If the decl has been given an explicit section name, then it
1729      isn't common, and shouldn't be handled as such.  */
1730   if (DECL_SECTION_NAME (decl) || dont_output_data)
1731     ;
1732   /* We don't implement common thread-local data at present.  */
1733   else if (DECL_THREAD_LOCAL_P (decl))
1734     {
1735       if (DECL_COMMON (decl))
1736         sorry ("thread-local COMMON data not implemented");
1737     }
1738   else if (DECL_INITIAL (decl) == 0
1739            || DECL_INITIAL (decl) == error_mark_node
1740            || (flag_zero_initialized_in_bss
1741                /* Leave constant zeroes in .rodata so they can be shared.  */
1742                && !TREE_READONLY (decl)
1743                && initializer_zerop (DECL_INITIAL (decl))))
1744     {
1745       unsigned HOST_WIDE_INT size = tree_low_cst (DECL_SIZE_UNIT (decl), 1);
1746       unsigned HOST_WIDE_INT rounded = size;
1747 
1748       /* Don't allocate zero bytes of common,
1749          since that means "undefined external" in the linker.  */
1750       if (size == 0)
1751         rounded = 1;
1752 
1753       /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1754          so that each uninitialized object starts on such a boundary.  */
1755       rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1;
1756       rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1757                  * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1758 
1759 #if !defined(ASM_OUTPUT_ALIGNED_COMMON) && !defined(ASM_OUTPUT_ALIGNED_DECL_COMMON) && !defined(ASM_OUTPUT_ALIGNED_BSS)
1760       if ((unsigned HOST_WIDE_INT) DECL_ALIGN_UNIT (decl) > rounded)
1761         warning (0, "requested alignment for %q+D is greater than "
1762                  "implemented alignment of %wu", decl, rounded);
1763 #endif
1764 
1765       /* If the target cannot output uninitialized but not common global data
1766          in .bss, then we have to use .data, so fall through.  */
1767       if (asm_emit_uninitialised (decl, name, size, rounded))
1768         return;
1769     }
1770 
1771   /* Handle initialized definitions.
1772      Also handle uninitialized global definitions if -fno-common and the
1773      target doesn't support ASM_OUTPUT_BSS.  */
1774 
1775   /* First make the assembler name(s) global if appropriate.  */
1776   if (TREE_PUBLIC (decl) && DECL_NAME (decl))
1777     globalize_decl (decl);
1778 
1779   /* Output any data that we will need to use the address of.  */
1780   if (DECL_INITIAL (decl) == error_mark_node)
1781     reloc = contains_pointers_p (TREE_TYPE (decl)) ? 3 : 0;
1782   else if (DECL_INITIAL (decl))
1783     {
1784       reloc = compute_reloc_for_constant (DECL_INITIAL (decl));
1785       output_addressed_constants (DECL_INITIAL (decl));
1786     }
1787 
1788   /* Switch to the appropriate section.  */
1789   resolve_unique_section (decl, reloc, flag_data_sections);
1790   variable_section (decl, reloc);
1791 
1792   /* dbxout.c needs to know this.  */
1793   if (in_text_section () || in_unlikely_text_section ())
1794     DECL_IN_TEXT_SECTION (decl) = 1;
1795 
1796   /* Output the alignment of this data.  */
1797   if (align > BITS_PER_UNIT)
1798     ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (DECL_ALIGN_UNIT (decl)));
1799 
1800   /* Do any machine/system dependent processing of the object.  */
1801 #ifdef ASM_DECLARE_OBJECT_NAME
1802   last_assemble_variable_decl = decl;
1803   ASM_DECLARE_OBJECT_NAME (asm_out_file, name, decl);
1804 #else
1805   /* Standard thing is just output label for the object.  */
1806   ASM_OUTPUT_LABEL (asm_out_file, name);
1807 #endif /* ASM_DECLARE_OBJECT_NAME */
1808 
1809   if (!dont_output_data)
1810     {
1811       if (DECL_INITIAL (decl)
1812           && DECL_INITIAL (decl) != error_mark_node
1813           && !initializer_zerop (DECL_INITIAL (decl)))
1814         /* Output the actual data.  */
1815         output_constant (DECL_INITIAL (decl),
1816                          tree_low_cst (DECL_SIZE_UNIT (decl), 1),
1817                          align);
1818       else
1819         /* Leave space for it.  */
1820         assemble_zeros (tree_low_cst (DECL_SIZE_UNIT (decl), 1));
1821     }
1822 }


リンク元

Advertisement