• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Keine Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

GNU Binutils with patches for OS216


Commit MetaInfo

Revisionb58f81aef6a84930bcb58db39f2bad0c45383a6d (tree)
Zeit2004-10-17 03:13:54
AutorDaniel Jacobowitz <drow@fals...>
CommiterDaniel Jacobowitz

Log Message

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.

Ändern Zusammenfassung

Diff

--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -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+
17 2004-10-15 Alan Modra <amodra@bigpond.net.au>
28
39 * config.bfd: Whitespace cleanup.
--- a/bfd/bfd-in2.h
+++ b/bfd/bfd-in2.h
@@ -3962,6 +3962,9 @@ struct bfd
39623962 /* Pointer to structure which contains architecture information. */
39633963 const struct bfd_arch_info *arch_info;
39643964
3965+ /* Flag set if symbols from this BFD should not be exported. */
3966+ bfd_boolean no_export;
3967+
39653968 /* Stuff only useful for archives. */
39663969 void *arelt_data;
39673970 struct bfd *my_archive; /* The containing archive BFD. */
--- a/bfd/bfd.c
+++ b/bfd/bfd.c
@@ -133,6 +133,9 @@ CODE_FRAGMENT
133133 . {* Pointer to structure which contains architecture information. *}
134134 . const struct bfd_arch_info *arch_info;
135135 .
136+. {* Flag set if symbols from this BFD should not be exported. *}
137+. bfd_boolean no_export;
138+.
136139 . {* Stuff only useful for archives. *}
137140 . void *arelt_data;
138141 . struct bfd *my_archive; {* The containing archive BFD. *}
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -3778,6 +3778,14 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
37783778 (*bed->elf_backend_merge_symbol_attribute) (h, isym, definition,
37793779 dynamic);
37803780
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+
37813789 if (isym->st_other != 0 && !dynamic)
37823790 {
37833791 unsigned char hvis, symvis, other, nvis;
--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -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+
113 2004-10-15 Alan Modra <amodra@bigpond.net.au>
214
315 * ldexp.c (exp_fold_tree): Don't immediately exit ld on a
--- a/ld/emultempl/elf32.em
+++ b/ld/emultempl/elf32.em
@@ -1571,7 +1571,8 @@ cat >>e${EMULATION_NAME}.c <<EOF
15711571 #define OPTION_ENABLE_NEW_DTAGS (OPTION_DISABLE_NEW_DTAGS + 1)
15721572 #define OPTION_GROUP (OPTION_ENABLE_NEW_DTAGS + 1)
15731573 #define OPTION_EH_FRAME_HDR (OPTION_GROUP + 1)
1574-
1574+#define OPTION_EXCLUDE_LIBS (OPTION_EH_FRAME_HDR + 1)
1575+
15751576 static void
15761577 gld${EMULATION_NAME}_add_options
15771578 (int ns, char **shortopts, int nl, struct option **longopts,
@@ -1586,6 +1587,7 @@ cat >>e${EMULATION_NAME}.c <<EOF
15861587 {"disable-new-dtags", no_argument, NULL, OPTION_DISABLE_NEW_DTAGS},
15871588 {"enable-new-dtags", no_argument, NULL, OPTION_ENABLE_NEW_DTAGS},
15881589 {"eh-frame-hdr", no_argument, NULL, OPTION_EH_FRAME_HDR},
1590+ {"exclude-libs", required_argument, NULL, OPTION_EXCLUDE_LIBS},
15891591 {"Bgroup", no_argument, NULL, OPTION_GROUP},
15901592 EOF
15911593 fi
@@ -1638,6 +1640,10 @@ cat >>e${EMULATION_NAME}.c <<EOF
16381640 link_info.unresolved_syms_in_shared_libs = RM_GENERATE_ERROR;
16391641 break;
16401642
1643+ case OPTION_EXCLUDE_LIBS:
1644+ add_excluded_libs (optarg);
1645+ break;
1646+
16411647 case 'z':
16421648 if (strcmp (optarg, "initfirst") == 0)
16431649 link_info.flags_1 |= (bfd_vma) DF_1_INITFIRST;
--- a/ld/ld.texinfo
+++ b/ld/ld.texinfo
@@ -449,6 +449,17 @@ base 10; you may use a leading @samp{0x} for base 16, or a leading
449449 @samp{0} for base 8). @xref{Entry Point}, for a discussion of defaults
450450 and other ways of specifying the entry point.
451451
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+
452463 @cindex dynamic symbol table
453464 @kindex -E
454465 @kindex --export-dynamic
@@ -1884,15 +1895,6 @@ Specifies a list of symbols which should not be automatically
18841895 exported. The symbol names may be delimited by commas or colons.
18851896 [This option is specific to the i386 PE targeted port of the linker]
18861897
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-
18961898 @kindex --file-alignment
18971899 @item --file-alignment
18981900 Specify the file alignment. Sections in the file will always begin at
--- a/ld/ldlang.c
+++ b/ld/ldlang.c
@@ -1692,6 +1692,67 @@ lookup_name (const char *name)
16921692 return search;
16931693 }
16941694
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+
16951756 /* Get the symbols for an input file. */
16961757
16971758 static bfd_boolean
@@ -1776,6 +1837,8 @@ load_symbols (lang_input_statement_type *entry,
17761837 break;
17771838
17781839 case bfd_archive:
1840+ check_excluded_libs (entry->the_bfd);
1841+
17791842 if (entry->whole_archive)
17801843 {
17811844 bfd *member = NULL;
--- a/ld/ldlang.h
+++ b/ld/ldlang.h
@@ -589,4 +589,6 @@ extern int lang_symbol_definition_iteration (const char *);
589589 extern void lang_update_definedness
590590 (const char *, struct bfd_link_hash_entry *);
591591
592+extern void add_excluded_libs (const char *);
593+
592594 #endif
--- a/ld/testsuite/ChangeLog
+++ b/ld/testsuite/ChangeLog
@@ -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+
15 2004-10-15 Alan Modra <amodra@bigpond.net.au>
26
37 * ld-crx/reloc-num8.d: Adjust for changed orphan placement.
--- /dev/null
+++ b/ld/testsuite/ld-elf/exclude.exp
@@ -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+}
--- /dev/null
+++ b/ld/testsuite/ld-elf/exclude1.s
@@ -0,0 +1,3 @@
1+ .globl include_sym
2+include_sym:
3+ .long exclude_sym - include_sym
--- /dev/null
+++ b/ld/testsuite/ld-elf/exclude2.s
@@ -0,0 +1,3 @@
1+ .globl exclude_sym
2+exclude_sym:
3+ .long 0