GNU Binutils with patches for OS216
Revision | b58f81aef6a84930bcb58db39f2bad0c45383a6d (tree) |
---|---|
Zeit | 2004-10-17 03:13:54 |
Autor | Daniel Jacobowitz <drow@fals...> |
Commiter | Daniel Jacobowitz |
bfd/
* bfd-in2.h: Regenerate.
* bfd.c (struct bfd): Add no_export.
* elflink.c (elf_link_add_object_symbols): Handle no_export.
ld/
* ldlang.c (struct excluded_lib, excluded_libs, add_excluded_libs)
(check_excluded_libs): New.
(load_symbols): Call check_excluded_libs.
* ldlang.h (add_excluded_libs): New prototype.
* emultempl/elf32.em (OPTION_EXCLUDED_LIBS): Define.
(gld${EMULATION_NAME}_add_options): Add --exclude-libs.
(gld${EMULATION_NAME}_handle_option): Handle --exclude-libs.
* ld.texinfo (Command Line Variables): Document --exclude-libs.
(Options Specific to i386 PE Targets): Remove --exclude-libs.
ld/testsuite/
* ld-elf/exclude1.s, ld-elf/exclude2.s, ld-elf/exclude.exp: New.
@@ -1,3 +1,9 @@ | ||
1 | +2004-10-16 Daniel Jacobowitz <dan@debian.org> | |
2 | + | |
3 | + * bfd-in2.h: Regenerate. | |
4 | + * bfd.c (struct bfd): Add no_export. | |
5 | + * elflink.c (elf_link_add_object_symbols): Handle no_export. | |
6 | + | |
1 | 7 | 2004-10-15 Alan Modra <amodra@bigpond.net.au> |
2 | 8 | |
3 | 9 | * config.bfd: Whitespace cleanup. |
@@ -3962,6 +3962,9 @@ struct bfd | ||
3962 | 3962 | /* Pointer to structure which contains architecture information. */ |
3963 | 3963 | const struct bfd_arch_info *arch_info; |
3964 | 3964 | |
3965 | + /* Flag set if symbols from this BFD should not be exported. */ | |
3966 | + bfd_boolean no_export; | |
3967 | + | |
3965 | 3968 | /* Stuff only useful for archives. */ |
3966 | 3969 | void *arelt_data; |
3967 | 3970 | struct bfd *my_archive; /* The containing archive BFD. */ |
@@ -133,6 +133,9 @@ CODE_FRAGMENT | ||
133 | 133 | . {* Pointer to structure which contains architecture information. *} |
134 | 134 | . const struct bfd_arch_info *arch_info; |
135 | 135 | . |
136 | +. {* Flag set if symbols from this BFD should not be exported. *} | |
137 | +. bfd_boolean no_export; | |
138 | +. | |
136 | 139 | . {* Stuff only useful for archives. *} |
137 | 140 | . void *arelt_data; |
138 | 141 | . struct bfd *my_archive; {* The containing archive BFD. *} |
@@ -3778,6 +3778,14 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info) | ||
3778 | 3778 | (*bed->elf_backend_merge_symbol_attribute) (h, isym, definition, |
3779 | 3779 | dynamic); |
3780 | 3780 | |
3781 | + /* If this symbol has default visibility and the user has requested | |
3782 | + we not re-export it, then mark it as hidden. */ | |
3783 | + if (definition && !dynamic | |
3784 | + && (abfd->no_export | |
3785 | + || (abfd->my_archive && abfd->my_archive->no_export)) | |
3786 | + && ELF_ST_VISIBILITY (isym->st_other) != STV_INTERNAL) | |
3787 | + isym->st_other = STV_HIDDEN | (isym->st_other & ~ ELF_ST_VISIBILITY (-1)); | |
3788 | + | |
3781 | 3789 | if (isym->st_other != 0 && !dynamic) |
3782 | 3790 | { |
3783 | 3791 | unsigned char hvis, symvis, other, nvis; |
@@ -1,3 +1,15 @@ | ||
1 | +2004-10-16 Daniel Jacobowitz <dan@debian.org> | |
2 | + | |
3 | + * ldlang.c (struct excluded_lib, excluded_libs, add_excluded_libs) | |
4 | + (check_excluded_libs): New. | |
5 | + (load_symbols): Call check_excluded_libs. | |
6 | + * ldlang.h (add_excluded_libs): New prototype. | |
7 | + * emultempl/elf32.em (OPTION_EXCLUDED_LIBS): Define. | |
8 | + (gld${EMULATION_NAME}_add_options): Add --exclude-libs. | |
9 | + (gld${EMULATION_NAME}_handle_option): Handle --exclude-libs. | |
10 | + * ld.texinfo (Command Line Variables): Document --exclude-libs. | |
11 | + (Options Specific to i386 PE Targets): Remove --exclude-libs. | |
12 | + | |
1 | 13 | 2004-10-15 Alan Modra <amodra@bigpond.net.au> |
2 | 14 | |
3 | 15 | * ldexp.c (exp_fold_tree): Don't immediately exit ld on a |
@@ -1571,7 +1571,8 @@ cat >>e${EMULATION_NAME}.c <<EOF | ||
1571 | 1571 | #define OPTION_ENABLE_NEW_DTAGS (OPTION_DISABLE_NEW_DTAGS + 1) |
1572 | 1572 | #define OPTION_GROUP (OPTION_ENABLE_NEW_DTAGS + 1) |
1573 | 1573 | #define OPTION_EH_FRAME_HDR (OPTION_GROUP + 1) |
1574 | - | |
1574 | +#define OPTION_EXCLUDE_LIBS (OPTION_EH_FRAME_HDR + 1) | |
1575 | + | |
1575 | 1576 | static void |
1576 | 1577 | gld${EMULATION_NAME}_add_options |
1577 | 1578 | (int ns, char **shortopts, int nl, struct option **longopts, |
@@ -1586,6 +1587,7 @@ cat >>e${EMULATION_NAME}.c <<EOF | ||
1586 | 1587 | {"disable-new-dtags", no_argument, NULL, OPTION_DISABLE_NEW_DTAGS}, |
1587 | 1588 | {"enable-new-dtags", no_argument, NULL, OPTION_ENABLE_NEW_DTAGS}, |
1588 | 1589 | {"eh-frame-hdr", no_argument, NULL, OPTION_EH_FRAME_HDR}, |
1590 | + {"exclude-libs", required_argument, NULL, OPTION_EXCLUDE_LIBS}, | |
1589 | 1591 | {"Bgroup", no_argument, NULL, OPTION_GROUP}, |
1590 | 1592 | EOF |
1591 | 1593 | fi |
@@ -1638,6 +1640,10 @@ cat >>e${EMULATION_NAME}.c <<EOF | ||
1638 | 1640 | link_info.unresolved_syms_in_shared_libs = RM_GENERATE_ERROR; |
1639 | 1641 | break; |
1640 | 1642 | |
1643 | + case OPTION_EXCLUDE_LIBS: | |
1644 | + add_excluded_libs (optarg); | |
1645 | + break; | |
1646 | + | |
1641 | 1647 | case 'z': |
1642 | 1648 | if (strcmp (optarg, "initfirst") == 0) |
1643 | 1649 | link_info.flags_1 |= (bfd_vma) DF_1_INITFIRST; |
@@ -449,6 +449,17 @@ base 10; you may use a leading @samp{0x} for base 16, or a leading | ||
449 | 449 | @samp{0} for base 8). @xref{Entry Point}, for a discussion of defaults |
450 | 450 | and other ways of specifying the entry point. |
451 | 451 | |
452 | +@kindex --exclude-libs | |
453 | +@item --exclude-libs @var{lib},@var{lib},... | |
454 | +Specifies a list of archive libraries from which symbols should not be automatically | |
455 | +exported. The library names may be delimited by commas or colons. Specifying | |
456 | +@code{--exclude-libs ALL} excludes symbols in all archive libraries from | |
457 | +automatic export. This option is available only for the i386 PE targeted | |
458 | +port of the linker and for ELF targeted ports. For i386 PE, symbols | |
459 | +explicitly listed in a .def file are still exported, regardless of this | |
460 | +option. For ELF targeted ports, symbols affected by this option will | |
461 | +be treated as hidden. | |
462 | + | |
452 | 463 | @cindex dynamic symbol table |
453 | 464 | @kindex -E |
454 | 465 | @kindex --export-dynamic |
@@ -1884,15 +1895,6 @@ Specifies a list of symbols which should not be automatically | ||
1884 | 1895 | exported. The symbol names may be delimited by commas or colons. |
1885 | 1896 | [This option is specific to the i386 PE targeted port of the linker] |
1886 | 1897 | |
1887 | -@kindex --exclude-libs | |
1888 | -@item --exclude-libs @var{lib},@var{lib},... | |
1889 | -Specifies a list of archive libraries from which symbols should not be automatically | |
1890 | -exported. The library names may be delimited by commas or colons. Specifying | |
1891 | -@code{--exclude-libs ALL} excludes symbols in all archive libraries from | |
1892 | -automatic export. Symbols explicitly listed in a .def file are still exported, | |
1893 | -regardless of this option. | |
1894 | -[This option is specific to the i386 PE targeted port of the linker] | |
1895 | - | |
1896 | 1898 | @kindex --file-alignment |
1897 | 1899 | @item --file-alignment |
1898 | 1900 | Specify the file alignment. Sections in the file will always begin at |
@@ -1692,6 +1692,67 @@ lookup_name (const char *name) | ||
1692 | 1692 | return search; |
1693 | 1693 | } |
1694 | 1694 | |
1695 | +/* Save LIST as a list of libraries whose symbols should not be exported. */ | |
1696 | + | |
1697 | +struct excluded_lib | |
1698 | +{ | |
1699 | + char *name; | |
1700 | + struct excluded_lib *next; | |
1701 | +}; | |
1702 | +static struct excluded_lib *excluded_libs; | |
1703 | + | |
1704 | +void | |
1705 | +add_excluded_libs (const char *list) | |
1706 | +{ | |
1707 | + const char *p = list, *end; | |
1708 | + | |
1709 | + while (*p != '\0') | |
1710 | + { | |
1711 | + struct excluded_lib *entry; | |
1712 | + end = strpbrk (p, ",:"); | |
1713 | + if (end == NULL) | |
1714 | + end = p + strlen (p); | |
1715 | + entry = xmalloc (sizeof (*entry)); | |
1716 | + entry->next = excluded_libs; | |
1717 | + entry->name = xmalloc (end - p + 1); | |
1718 | + memcpy (entry->name, p, end - p); | |
1719 | + entry->name[end - p] = '\0'; | |
1720 | + excluded_libs = entry; | |
1721 | + if (*end == '\0') | |
1722 | + break; | |
1723 | + p = end + 1; | |
1724 | + } | |
1725 | +} | |
1726 | + | |
1727 | +static void | |
1728 | +check_excluded_libs (bfd *abfd) | |
1729 | +{ | |
1730 | + struct excluded_lib *lib = excluded_libs; | |
1731 | + | |
1732 | + while (lib) | |
1733 | + { | |
1734 | + int len = strlen (lib->name); | |
1735 | + const char *filename = lbasename (abfd->filename); | |
1736 | + | |
1737 | + if (strcmp (lib->name, "ALL") == 0) | |
1738 | + { | |
1739 | + abfd->no_export = TRUE; | |
1740 | + return; | |
1741 | + } | |
1742 | + | |
1743 | + if (strncmp (lib->name, filename, len) == 0 | |
1744 | + && (filename[len] == '\0' | |
1745 | + || (filename[len] == '.' && filename[len + 1] == 'a' | |
1746 | + && filename[len + 2] == '\0'))) | |
1747 | + { | |
1748 | + abfd->no_export = TRUE; | |
1749 | + return; | |
1750 | + } | |
1751 | + | |
1752 | + lib = lib->next; | |
1753 | + } | |
1754 | +} | |
1755 | + | |
1695 | 1756 | /* Get the symbols for an input file. */ |
1696 | 1757 | |
1697 | 1758 | static bfd_boolean |
@@ -1776,6 +1837,8 @@ load_symbols (lang_input_statement_type *entry, | ||
1776 | 1837 | break; |
1777 | 1838 | |
1778 | 1839 | case bfd_archive: |
1840 | + check_excluded_libs (entry->the_bfd); | |
1841 | + | |
1779 | 1842 | if (entry->whole_archive) |
1780 | 1843 | { |
1781 | 1844 | bfd *member = NULL; |
@@ -589,4 +589,6 @@ extern int lang_symbol_definition_iteration (const char *); | ||
589 | 589 | extern void lang_update_definedness |
590 | 590 | (const char *, struct bfd_link_hash_entry *); |
591 | 591 | |
592 | +extern void add_excluded_libs (const char *); | |
593 | + | |
592 | 594 | #endif |
@@ -1,3 +1,7 @@ | ||
1 | +2004-10-16 Daniel Jacobowitz <dan@debian.org> | |
2 | + | |
3 | + * ld-elf/exclude1.s, ld-elf/exclude2.s, ld-elf/exclude.exp: New. | |
4 | + | |
1 | 5 | 2004-10-15 Alan Modra <amodra@bigpond.net.au> |
2 | 6 | |
3 | 7 | * ld-crx/reloc-num8.d: Adjust for changed orphan placement. |
@@ -0,0 +1,137 @@ | ||
1 | +# Expect script for --exclude-libs tests | |
2 | +# Copyright 2004 Free Software Foundation, Inc. | |
3 | +# | |
4 | +# This file is free software; you can redistribute it and/or modify | |
5 | +# it under the terms of the GNU General Public License as published by | |
6 | +# the Free Software Foundation; either version 2 of the License, or | |
7 | +# (at your option) any later version. | |
8 | +# | |
9 | +# This program is distributed in the hope that it will be useful, | |
10 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | +# GNU General Public License for more details. | |
13 | +# | |
14 | +# You should have received a copy of the GNU General Public License | |
15 | +# along with this program; if not, write to the Free Software | |
16 | +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
17 | + | |
18 | +# Make sure that ld can hide symbols from libraries when building a shared | |
19 | +# library. | |
20 | + | |
21 | +# This test can only be run on ELF platforms. | |
22 | +if ![is_elf_format] { | |
23 | + return | |
24 | +} | |
25 | + | |
26 | +# No shared lib support on this target. | |
27 | +if { [istarget "mcore-*-*"] } { | |
28 | + return | |
29 | +} | |
30 | + | |
31 | +global ar | |
32 | +global as | |
33 | +global ld | |
34 | +global nm | |
35 | +global nm_output | |
36 | + | |
37 | +set test1 "ld link shared library" | |
38 | +set test2 "ld export symbols from archive" | |
39 | +set test3 "ld link shared library with --exclude-libs" | |
40 | +set test4 "ld exclude symbols from archive - --exclude-libs libexclude" | |
41 | +set test5 "ld exclude symbols from archive - --exclude-libs libexclude.a" | |
42 | +set test6 "ld exclude symbols from archive - --exclude-libs ALL" | |
43 | +set test7 "ld exclude symbols from archive - --exclude-libs foo:libexclude.a" | |
44 | +set test8 "ld exclude symbols from archive - --exclude-libs foo,libexclude.a" | |
45 | +set test9 "ld don't exclude symbols from archive - --exclude-libs foo:bar" | |
46 | + | |
47 | +if { ![ld_assemble $as $srcdir/$subdir/exclude1.s tmpdir/exclude1.o ] | |
48 | + || ![ld_assemble $as $srcdir/$subdir/exclude2.s tmpdir/exclude2.o] } { | |
49 | + unresolved $test1 | |
50 | + return | |
51 | +} | |
52 | + | |
53 | +catch "exec rm -f tmpdir/libexclude.a" catch_output | |
54 | +catch "exec $ar cq tmpdir/libexclude.a tmpdir/exclude2.o" catch_output | |
55 | +if {![string match "" $catch_output]} { | |
56 | + unresolved $test1 | |
57 | + return | |
58 | +} | |
59 | + | |
60 | +# Test that the symbol is normally exported. | |
61 | + | |
62 | +if { [ld_simple_link $ld tmpdir/exclude.so "--shared tmpdir/exclude1.o -Ltmpdir -lexclude"] } { | |
63 | + pass $test1 | |
64 | +} else { | |
65 | + if [string match "*shared not supported*" $link_output] { | |
66 | + unsupported "$test1 - -shared is not supported by this target" | |
67 | + } else { | |
68 | + fail $test1 | |
69 | + } | |
70 | + return | |
71 | +} | |
72 | + | |
73 | +if ![ld_nm $nm "-D" tmpdir/exclude.so] { | |
74 | + unresolved $test2 | |
75 | +} elseif { [info exists nm_output(exclude_sym)] } { | |
76 | + pass $test2 | |
77 | +} else { | |
78 | + fail $test2 | |
79 | +} | |
80 | + | |
81 | +# Test --exclude-libs libexclude | |
82 | + | |
83 | +if { [ld_simple_link $ld tmpdir/exclude.so "--exclude-libs libexclude --shared tmpdir/exclude1.o -Ltmpdir -lexclude"] } { | |
84 | + pass $test3 | |
85 | +} else { | |
86 | + fail $test3 | |
87 | +} | |
88 | + | |
89 | +if ![ld_nm $nm "-D" tmpdir/exclude.so] { | |
90 | + unresolved $test4 | |
91 | +} elseif { ! [info exists nm_output(exclude_sym)] } { | |
92 | + pass $test4 | |
93 | +} else { | |
94 | + fail $test4 | |
95 | +} | |
96 | + | |
97 | +# Test alternate spellings of --exclude-libs | |
98 | + | |
99 | +if { [ld_simple_link $ld tmpdir/exclude.so "--exclude-libs libexclude.a --shared tmpdir/exclude1.o -Ltmpdir -lexclude"] | |
100 | + && [ld_nm $nm "-D" tmpdir/exclude.so] | |
101 | + && ! [info exists nm_output(exclude_sym)] } { | |
102 | + pass $test5 | |
103 | +} else { | |
104 | + fail $test5 | |
105 | +} | |
106 | + | |
107 | +if { [ld_simple_link $ld tmpdir/exclude.so "--exclude-libs ALL --shared tmpdir/exclude1.o -Ltmpdir -lexclude"] | |
108 | + && [ld_nm $nm "-D" tmpdir/exclude.so] | |
109 | + && ! [info exists nm_output(exclude_sym)] } { | |
110 | + pass $test6 | |
111 | +} else { | |
112 | + fail $test6 | |
113 | +} | |
114 | + | |
115 | +if { [ld_simple_link $ld tmpdir/exclude.so "--exclude-libs foo:libexclude.a --shared tmpdir/exclude1.o -Ltmpdir -lexclude"] | |
116 | + && [ld_nm $nm "-D" tmpdir/exclude.so] | |
117 | + && ! [info exists nm_output(exclude_sym)] } { | |
118 | + pass $test7 | |
119 | +} else { | |
120 | + fail $test7 | |
121 | +} | |
122 | + | |
123 | +if { [ld_simple_link $ld tmpdir/exclude.so "--exclude-libs foo,libexclude.a --shared tmpdir/exclude1.o -Ltmpdir -lexclude"] | |
124 | + && [ld_nm $nm "-D" tmpdir/exclude.so] | |
125 | + && ! [info exists nm_output(exclude_sym)] } { | |
126 | + pass $test8 | |
127 | +} else { | |
128 | + fail $test8 | |
129 | +} | |
130 | + | |
131 | +if { [ld_simple_link $ld tmpdir/exclude.so "--exclude-libs foo:bar --shared tmpdir/exclude1.o -Ltmpdir -lexclude"] | |
132 | + && [ld_nm $nm "-D" tmpdir/exclude.so] | |
133 | + && [info exists nm_output(exclude_sym)] } { | |
134 | + pass $test9 | |
135 | +} else { | |
136 | + fail $test9 | |
137 | +} |
@@ -0,0 +1,3 @@ | ||
1 | + .globl include_sym | |
2 | +include_sym: | |
3 | + .long exclude_sym - include_sym |
@@ -0,0 +1,3 @@ | ||
1 | + .globl exclude_sym | |
2 | +exclude_sym: | |
3 | + .long 0 |