Rev 5222 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 5222 | Rev 6324 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | /* write.c - emit .o file |
1 | /* write.c - emit .o file |
2 | Copyright 1986, 1987, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, |
- | |
3 | 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, |
- | |
4 | 2010, 2011, 2012 Free Software Foundation, Inc. |
2 | Copyright (C) 1986-2015 Free Software Foundation, Inc. |
Line 5... | Line 3... | ||
5 | 3 | ||
Line 6... | Line 4... | ||
6 | This file is part of GAS, the GNU Assembler. |
4 | This file is part of GAS, the GNU Assembler. |
7 | 5 | ||
Line 836... | Line 834... | ||
836 | 834 | ||
837 | symsec = S_GET_SEGMENT (sym); |
835 | symsec = S_GET_SEGMENT (sym); |
838 | if (symsec == NULL) |
836 | if (symsec == NULL) |
Line 839... | Line 837... | ||
839 | abort (); |
837 | abort (); |
- | 838 | ||
840 | 839 | if (bfd_is_abs_section (symsec) |
|
841 | if (bfd_is_abs_section (symsec)) |
840 | || symsec == reg_section) |
842 | { |
841 | { |
843 | /* The fixup_segment routine normally will not use this |
842 | /* The fixup_segment routine normally will not use this |
844 | symbol in a relocation. */ |
843 | symbol in a relocation. */ |
Line 1183... | Line 1182... | ||
1183 | for (f = seginfo->frchainP->frch_root; f != NULL; f = f->fr_next) |
1182 | for (f = seginfo->frchainP->frch_root; f != NULL; f = f->fr_next) |
1184 | if (f->fr_address <= r->u.b.r.address |
1183 | if (f->fr_address <= r->u.b.r.address |
1185 | && r->u.b.r.address < f->fr_address + f->fr_fix) |
1184 | && r->u.b.r.address < f->fr_address + f->fr_fix) |
1186 | return f; |
1185 | return f; |
Line -... | Line 1186... | ||
- | 1186 | ||
- | 1187 | for (f = seginfo->frchainP->frch_root; f != NULL; f = f->fr_next) |
|
- | 1188 | if (f->fr_address <= r->u.b.r.address |
|
- | 1189 | && r->u.b.r.address <= f->fr_address + f->fr_fix) |
|
- | 1190 | return f; |
|
1187 | 1191 | ||
1188 | as_bad_where (r->file, r->line, |
1192 | as_bad_where (r->file, r->line, |
1189 | _("reloc not within (fixed part of) section")); |
1193 | _("reloc not within (fixed part of) section")); |
1190 | return NULL; |
1194 | return NULL; |
Line 1407... | Line 1411... | ||
1407 | char *compressed_name; |
1411 | char *compressed_name; |
1408 | char *header; |
1412 | char *header; |
1409 | struct z_stream_s *strm; |
1413 | struct z_stream_s *strm; |
1410 | int x; |
1414 | int x; |
1411 | flagword flags = bfd_get_section_flags (abfd, sec); |
1415 | flagword flags = bfd_get_section_flags (abfd, sec); |
- | 1416 | unsigned int header_size, compression_header_size; |
|
Line 1412... | Line 1417... | ||
1412 | 1417 | ||
1413 | if (seginfo == NULL |
1418 | if (seginfo == NULL |
1414 | || sec->size < 32 |
1419 | || sec->size < 32 |
1415 | || (flags & (SEC_ALLOC | SEC_HAS_CONTENTS)) == SEC_ALLOC) |
1420 | || (flags & (SEC_ALLOC | SEC_HAS_CONTENTS)) == SEC_ALLOC) |
Line 1421... | Line 1426... | ||
1421 | 1426 | ||
1422 | strm = compress_init (); |
1427 | strm = compress_init (); |
1423 | if (strm == NULL) |
1428 | if (strm == NULL) |
Line -... | Line 1429... | ||
- | 1429 | return; |
|
- | 1430 | ||
- | 1431 | if (flag_compress_debug == COMPRESS_DEBUG_GABI_ZLIB) |
|
- | 1432 | { |
|
- | 1433 | stdoutput->flags |= BFD_COMPRESS | BFD_COMPRESS_GABI; |
|
- | 1434 | compression_header_size |
|
- | 1435 | = bfd_get_compression_header_size (stdoutput, NULL); |
|
- | 1436 | header_size = compression_header_size; |
|
- | 1437 | } |
|
- | 1438 | else |
|
- | 1439 | { |
|
- | 1440 | stdoutput->flags |= BFD_COMPRESS; |
|
- | 1441 | compression_header_size = 0; |
|
- | 1442 | header_size = 12; |
|
1424 | return; |
1443 | } |
1425 | 1444 | ||
1426 | /* Create a new frag to contain the "ZLIB" header. */ |
1445 | /* Create a new frag to contain the compression header. */ |
1427 | first_newf = frag_alloc (ob); |
1446 | first_newf = frag_alloc (ob); |
1428 | if (obstack_room (ob) < 12) |
1447 | if (obstack_room (ob) < header_size) |
1429 | first_newf = frag_alloc (ob); |
1448 | first_newf = frag_alloc (ob); |
1430 | if (obstack_room (ob) < 12) |
1449 | if (obstack_room (ob) < header_size) |
1431 | as_fatal (_("can't extend frag %u chars"), 12); |
1450 | as_fatal (_("can't extend frag %u chars"), header_size); |
1432 | last_newf = first_newf; |
1451 | last_newf = first_newf; |
1433 | obstack_blank_fast (ob, 12); |
1452 | obstack_blank_fast (ob, header_size); |
1434 | last_newf->fr_type = rs_fill; |
1453 | last_newf->fr_type = rs_fill; |
1435 | last_newf->fr_fix = 12; |
- | |
1436 | header = last_newf->fr_literal; |
- | |
1437 | memcpy (header, "ZLIB", 4); |
- | |
1438 | header[11] = uncompressed_size; uncompressed_size >>= 8; |
- | |
1439 | header[10] = uncompressed_size; uncompressed_size >>= 8; |
- | |
1440 | header[9] = uncompressed_size; uncompressed_size >>= 8; |
- | |
1441 | header[8] = uncompressed_size; uncompressed_size >>= 8; |
- | |
1442 | header[7] = uncompressed_size; uncompressed_size >>= 8; |
- | |
1443 | header[6] = uncompressed_size; uncompressed_size >>= 8; |
- | |
1444 | header[5] = uncompressed_size; uncompressed_size >>= 8; |
1454 | last_newf->fr_fix = header_size; |
Line 1445... | Line 1455... | ||
1445 | header[4] = uncompressed_size; |
1455 | header = last_newf->fr_literal; |
1446 | compressed_size = 12; |
1456 | compressed_size = header_size; |
1447 | 1457 | ||
1448 | /* Stream the frags through the compression engine, adding new frags |
1458 | /* Stream the frags through the compression engine, adding new frags |
Line 1520... | Line 1530... | ||
1520 | 1530 | ||
1521 | if (x == 0) |
1531 | if (x == 0) |
1522 | break; |
1532 | break; |
Line -... | Line 1533... | ||
- | 1533 | } |
|
- | 1534 | ||
- | 1535 | /* PR binutils/18087: If compression didn't make the section smaller, |
|
- | 1536 | just keep it uncompressed. */ |
|
- | 1537 | if (compressed_size >= uncompressed_size) |
|
1523 | } |
1538 | return; |
1524 | 1539 | ||
1525 | /* Replace the uncompressed frag list with the compressed frag list. */ |
1540 | /* Replace the uncompressed frag list with the compressed frag list. */ |
Line 1526... | Line 1541... | ||
1526 | seginfo->frchainP->frch_root = first_newf; |
1541 | seginfo->frchainP->frch_root = first_newf; |
- | 1542 | seginfo->frchainP->frch_last = last_newf; |
|
1527 | seginfo->frchainP->frch_last = last_newf; |
1543 | |
1528 | 1544 | /* Update the section size and its name. */ |
|
- | 1545 | bfd_update_compression_header (abfd, (bfd_byte *) header, sec); |
|
- | 1546 | x = bfd_set_section_size (abfd, sec, compressed_size); |
|
1529 | /* Update the section size and its name. */ |
1547 | gas_assert (x); |
1530 | x = bfd_set_section_size (abfd, sec, compressed_size); |
1548 | if (!compression_header_size) |
1531 | gas_assert (x); |
1549 | { |
1532 | compressed_name = (char *) xmalloc (strlen (section_name) + 2); |
1550 | compressed_name = (char *) xmalloc (strlen (section_name) + 2); |
1533 | compressed_name[0] = '.'; |
1551 | compressed_name[0] = '.'; |
1534 | compressed_name[1] = 'z'; |
1552 | compressed_name[1] = 'z'; |
- | 1553 | strcpy (compressed_name + 2, section_name + 1); |
|
Line 1535... | Line 1554... | ||
1535 | strcpy (compressed_name + 2, section_name + 1); |
1554 | bfd_section_name (stdoutput, sec) = compressed_name; |
1536 | bfd_section_name (stdoutput, sec) = compressed_name; |
1555 | } |
1537 | } |
1556 | } |
1538 | 1557 | ||
Line 1564... | Line 1583... | ||
1564 | { |
1583 | { |
1565 | x = bfd_set_section_contents (stdoutput, sec, |
1584 | x = bfd_set_section_contents (stdoutput, sec, |
1566 | f->fr_literal, (file_ptr) offset, |
1585 | f->fr_literal, (file_ptr) offset, |
1567 | (bfd_size_type) f->fr_fix); |
1586 | (bfd_size_type) f->fr_fix); |
1568 | if (!x) |
1587 | if (!x) |
1569 | as_fatal (_("can't write %s: %s"), stdoutput->filename, |
1588 | as_fatal (_("can't write %ld bytes to section %s of %s because: '%s'"), |
- | 1589 | (long) f->fr_fix, sec->name, |
|
- | 1590 | stdoutput->filename, |
|
1570 | bfd_errmsg (bfd_get_error ())); |
1591 | bfd_errmsg (bfd_get_error ())); |
1571 | offset += f->fr_fix; |
1592 | offset += f->fr_fix; |
1572 | } |
1593 | } |
1573 | fill_literal = f->fr_literal + f->fr_fix; |
1594 | fill_literal = f->fr_literal + f->fr_fix; |
1574 | fill_size = f->fr_var; |
1595 | fill_size = f->fr_var; |
Line 1585... | Line 1606... | ||
1585 | x = bfd_set_section_contents (stdoutput, sec, |
1606 | x = bfd_set_section_contents (stdoutput, sec, |
1586 | fill_literal, |
1607 | fill_literal, |
1587 | (file_ptr) offset, |
1608 | (file_ptr) offset, |
1588 | (bfd_size_type) fill_size); |
1609 | (bfd_size_type) fill_size); |
1589 | if (!x) |
1610 | if (!x) |
1590 | as_fatal (_("can't write %s: %s"), stdoutput->filename, |
1611 | as_fatal (_("can't fill %ld bytes in section %s of %s because '%s'"), |
- | 1612 | (long) fill_size, sec->name, |
|
- | 1613 | stdoutput->filename, |
|
1591 | bfd_errmsg (bfd_get_error ())); |
1614 | bfd_errmsg (bfd_get_error ())); |
1592 | offset += fill_size; |
1615 | offset += fill_size; |
1593 | } |
1616 | } |
1594 | } |
1617 | } |
1595 | else |
1618 | else |
Line 1615... | Line 1638... | ||
1615 | n_per_buf = n_per_buf > count ? count : n_per_buf; |
1638 | n_per_buf = n_per_buf > count ? count : n_per_buf; |
1616 | x = bfd_set_section_contents |
1639 | x = bfd_set_section_contents |
1617 | (stdoutput, sec, buf, (file_ptr) offset, |
1640 | (stdoutput, sec, buf, (file_ptr) offset, |
1618 | (bfd_size_type) n_per_buf * fill_size); |
1641 | (bfd_size_type) n_per_buf * fill_size); |
1619 | if (!x) |
1642 | if (!x) |
1620 | as_fatal (_("cannot write to output file '%s': %s"), |
1643 | as_fatal (_("cannot fill %ld bytes in section %s of %s because: '%s'"), |
- | 1644 | (long)(n_per_buf * fill_size), sec->name, |
|
1621 | stdoutput->filename, |
1645 | stdoutput->filename, |
1622 | bfd_errmsg (bfd_get_error ())); |
1646 | bfd_errmsg (bfd_get_error ())); |
1623 | offset += n_per_buf * fill_size; |
1647 | offset += n_per_buf * fill_size; |
1624 | } |
1648 | } |
1625 | } |
1649 | } |
Line 1686... | Line 1710... | ||
1686 | #ifdef HANDLE_ALIGN |
1710 | #ifdef HANDLE_ALIGN |
1687 | /* The last subsegment gets an alignment corresponding to the alignment |
1711 | /* The last subsegment gets an alignment corresponding to the alignment |
1688 | of the section. This allows proper nop-filling at the end of |
1712 | of the section. This allows proper nop-filling at the end of |
1689 | code-bearing sections. */ |
1713 | code-bearing sections. */ |
1690 | #define SUB_SEGMENT_ALIGN(SEG, FRCHAIN) \ |
1714 | #define SUB_SEGMENT_ALIGN(SEG, FRCHAIN) \ |
1691 | (!(FRCHAIN)->frch_next ? get_recorded_alignment (SEG) : 0) |
1715 | (!(FRCHAIN)->frch_next && subseg_text_p (SEG) \ |
- | 1716 | ? get_recorded_alignment (SEG) \ |
|
- | 1717 | : 0) |
|
1692 | #else |
1718 | #else |
1693 | #define SUB_SEGMENT_ALIGN(SEG, FRCHAIN) 0 |
1719 | #define SUB_SEGMENT_ALIGN(SEG, FRCHAIN) 0 |
1694 | #endif |
1720 | #endif |
1695 | #endif |
1721 | #endif |
Line 1696... | Line 1722... | ||
1696 | 1722 | ||
1697 | void |
1723 | static void |
1698 | subsegs_finish (void) |
1724 | subsegs_finish_section (asection *s) |
1699 | { |
1725 | { |
1700 | struct frchain *frchainP; |
- | |
1701 | asection *s; |
- | |
1702 | - | ||
1703 | for (s = stdoutput->sections; s; s = s->next) |
- | |
1704 | { |
1726 | struct frchain *frchainP; |
1705 | segment_info_type *seginfo = seg_info (s); |
1727 | segment_info_type *seginfo = seg_info (s); |
1706 | if (!seginfo) |
1728 | if (!seginfo) |
Line 1707... | Line 1729... | ||
1707 | continue; |
1729 | return; |
1708 | 1730 | ||
1709 | for (frchainP = seginfo->frchainP; |
1731 | for (frchainP = seginfo->frchainP; |
1710 | frchainP != NULL; |
1732 | frchainP != NULL; |
Line 1729... | Line 1751... | ||
1729 | while ((entsize & 1) == 0) |
1751 | while ((entsize & 1) == 0) |
1730 | { |
1752 | { |
1731 | ++entalign; |
1753 | ++entalign; |
1732 | entsize >>= 1; |
1754 | entsize >>= 1; |
1733 | } |
1755 | } |
- | 1756 | ||
1734 | if (entalign > alignment) |
1757 | if (entalign > alignment) |
1735 | alignment = entalign; |
1758 | alignment = entalign; |
1736 | } |
1759 | } |
1737 | } |
1760 | } |
Line 1749... | Line 1772... | ||
1749 | frag_wane (frag_now); |
1772 | frag_wane (frag_now); |
1750 | frag_now->fr_fix = 0; |
1773 | frag_now->fr_fix = 0; |
1751 | know (frag_now->fr_next == NULL); |
1774 | know (frag_now->fr_next == NULL); |
1752 | } |
1775 | } |
1753 | } |
1776 | } |
- | 1777 | ||
- | 1778 | static void |
|
- | 1779 | subsegs_finish (void) |
|
- | 1780 | { |
|
- | 1781 | asection *s; |
|
- | 1782 | ||
- | 1783 | for (s = stdoutput->sections; s; s = s->next) |
|
- | 1784 | subsegs_finish_section (s); |
|
- | 1785 | } |
|
- | 1786 | ||
- | 1787 | #ifdef OBJ_ELF |
|
- | 1788 | static void |
|
- | 1789 | create_obj_attrs_section (void) |
|
- | 1790 | { |
|
- | 1791 | segT s; |
|
- | 1792 | char *p; |
|
- | 1793 | offsetT size; |
|
- | 1794 | const char *name; |
|
- | 1795 | ||
- | 1796 | size = bfd_elf_obj_attr_size (stdoutput); |
|
- | 1797 | if (size) |
|
- | 1798 | { |
|
- | 1799 | name = get_elf_backend_data (stdoutput)->obj_attrs_section; |
|
- | 1800 | if (!name) |
|
- | 1801 | name = ".gnu.attributes"; |
|
- | 1802 | s = subseg_new (name, 0); |
|
- | 1803 | elf_section_type (s) |
|
- | 1804 | = get_elf_backend_data (stdoutput)->obj_attrs_section_type; |
|
- | 1805 | bfd_set_section_flags (stdoutput, s, SEC_READONLY | SEC_DATA); |
|
- | 1806 | frag_now_fix (); |
|
- | 1807 | p = frag_more (size); |
|
- | 1808 | bfd_elf_set_obj_attr_contents (stdoutput, (bfd_byte *)p, size); |
|
- | 1809 | ||
- | 1810 | subsegs_finish_section (s); |
|
- | 1811 | relax_segment (seg_info (s)->frchainP->frch_root, s, 0); |
|
- | 1812 | size_seg (stdoutput, s, NULL); |
|
- | 1813 | } |
|
1754 | } |
1814 | } |
- | 1815 | #endif |
|
Line 1755... | Line 1816... | ||
1755 | 1816 | ||
Line 1756... | Line 1817... | ||
1756 | /* Write the object file. */ |
1817 | /* Write the object file. */ |
1757 | 1818 | ||
Line 1761... | Line 1822... | ||
1761 | struct relax_seg_info rsi; |
1822 | struct relax_seg_info rsi; |
1762 | #ifndef WORKING_DOT_WORD |
1823 | #ifndef WORKING_DOT_WORD |
1763 | fragS *fragP; /* Track along all frags. */ |
1824 | fragS *fragP; /* Track along all frags. */ |
1764 | #endif |
1825 | #endif |
Line -... | Line 1826... | ||
- | 1826 | ||
- | 1827 | subsegs_finish (); |
|
1765 | 1828 | ||
1766 | #ifdef md_pre_output_hook |
1829 | #ifdef md_pre_output_hook |
1767 | md_pre_output_hook; |
1830 | md_pre_output_hook; |
Line 1768... | Line -... | ||
1768 | #endif |
- | |
1769 | - | ||
1770 | /* Do we really want to write it? */ |
- | |
1771 | { |
- | |
1772 | int n_warns, n_errs; |
- | |
1773 | n_warns = had_warnings (); |
- | |
1774 | n_errs = had_errors (); |
- | |
1775 | /* The -Z flag indicates that an object file should be generated, |
- | |
1776 | regardless of warnings and errors. */ |
- | |
1777 | if (flag_always_generate_output) |
- | |
1778 | { |
- | |
1779 | if (n_warns || n_errs) |
- | |
1780 | as_warn (_("%d error%s, %d warning%s, generating bad object file"), |
- | |
1781 | n_errs, n_errs == 1 ? "" : "s", |
- | |
1782 | n_warns, n_warns == 1 ? "" : "s"); |
- | |
1783 | } |
- | |
1784 | else |
- | |
1785 | { |
- | |
1786 | if (n_errs) |
- | |
1787 | as_fatal (_("%d error%s, %d warning%s, no object file generated"), |
- | |
1788 | n_errs, n_errs == 1 ? "" : "s", |
- | |
1789 | n_warns, n_warns == 1 ? "" : "s"); |
- | |
1790 | } |
- | |
1791 | } |
1831 | #endif |
1792 | 1832 | ||
1793 | #ifdef md_pre_relax_hook |
1833 | #ifdef md_pre_relax_hook |
Line 1794... | Line 1834... | ||
1794 | md_pre_relax_hook; |
1834 | md_pre_relax_hook; |
Line 1864... | Line 1904... | ||
1864 | 1904 | ||
1865 | #ifdef md_post_relax_hook |
1905 | #ifdef md_post_relax_hook |
1866 | md_post_relax_hook; |
1906 | md_post_relax_hook; |
Line -... | Line 1907... | ||
- | 1907 | #endif |
|
- | 1908 | ||
- | 1909 | #ifdef OBJ_ELF |
|
- | 1910 | if (IS_ELF) |
|
- | 1911 | create_obj_attrs_section (); |
|
1867 | #endif |
1912 | #endif |
1868 | 1913 | ||
1869 | #ifndef WORKING_DOT_WORD |
1914 | #ifndef WORKING_DOT_WORD |
1870 | { |
1915 | { |
Line 1883... | Line 1928... | ||
1883 | exp.X_op_symbol = lie->sub; |
1928 | exp.X_op_symbol = lie->sub; |
1884 | exp.X_add_number = lie->addnum; |
1929 | exp.X_add_number = lie->addnum; |
1885 | #ifdef TC_CONS_FIX_NEW |
1930 | #ifdef TC_CONS_FIX_NEW |
1886 | TC_CONS_FIX_NEW (lie->frag, |
1931 | TC_CONS_FIX_NEW (lie->frag, |
1887 | lie->word_goes_here - lie->frag->fr_literal, |
1932 | lie->word_goes_here - lie->frag->fr_literal, |
1888 | 2, &exp); |
1933 | 2, &exp, TC_PARSE_CONS_RETURN_NONE); |
1889 | #else |
1934 | #else |
1890 | fix_new_exp (lie->frag, |
1935 | fix_new_exp (lie->frag, |
1891 | lie->word_goes_here - lie->frag->fr_literal, |
1936 | lie->word_goes_here - lie->frag->fr_literal, |
1892 | 2, &exp, 0, BFD_RELOC_16); |
1937 | 2, &exp, 0, BFD_RELOC_16); |
1893 | #endif |
1938 | #endif |
Line 2284... | Line 2329... | ||
2284 | #endif /* defined (TC_GENERIC_RELAX_TABLE) */ |
2329 | #endif /* defined (TC_GENERIC_RELAX_TABLE) */ |
Line 2285... | Line 2330... | ||
2285 | 2330 | ||
2286 | /* Relax_align. Advance location counter to next address that has 'alignment' |
2331 | /* Relax_align. Advance location counter to next address that has 'alignment' |
2287 | lowest order bits all 0s, return size of adjustment made. */ |
2332 | lowest order bits all 0s, return size of adjustment made. */ |
2288 | static relax_addressT |
2333 | static relax_addressT |
2289 | relax_align (register relax_addressT address, /* Address now. */ |
2334 | relax_align (relax_addressT address, /* Address now. */ |
2290 | register int alignment /* Alignment (binary). */) |
2335 | int alignment /* Alignment (binary). */) |
2291 | { |
2336 | { |
2292 | relax_addressT mask; |
2337 | relax_addressT mask; |
Line 2293... | Line 2338... | ||
2293 | relax_addressT new_address; |
2338 | relax_addressT new_address; |
2294 | 2339 | ||
2295 | mask = ~((~0) << alignment); |
2340 | mask = ~((relax_addressT) ~0 << alignment); |
2296 | new_address = (address + mask) & (~mask); |
2341 | new_address = (address + mask) & (~mask); |
2297 | #ifdef LINKER_RELAXING_SHRINKS_ONLY |
2342 | #ifdef LINKER_RELAXING_SHRINKS_ONLY |
2298 | if (linkrelax) |
2343 | if (linkrelax) |