Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | From e9c1bdad269c0c3352eebcc9481ed65144001b0b Mon Sep 17 00:00:00 2001 |
| 2 | From: Cary Coutant <ccoutant@google.com> |
| 3 | Date: Mon, 16 Feb 2015 22:15:12 -0800 |
| 4 | Subject: [PATCH] Fix --dynamic-list so that symbols not in the list are still |
| 5 | exported. |
| 6 | |
| 7 | In PR 13577, the complaint was that -Bsymbolic was overriding the binding |
| 8 | behavior for symbols listed in the --dynamic-list by setting the DT_SYMBOLIC |
| 9 | tag in the dynamic table. In reading the Gnu ld manual, I decided that |
| 10 | --dynamic-list should be mutually exclusive of -Bsymbolic, and modified |
| 11 | gold so that --dynamic-list would treat symbols listed as preemptible, |
| 12 | and all other symbols as internally bound. I was wrong. |
| 13 | |
| 14 | PR 16992 shows that with --dynamic-list (and not -Bsymbolic), a symbol |
| 15 | not listed in the dynamic list is being internally bound within the |
| 16 | shared library, but because it's still in the dynamic symbol table, we |
| 17 | expose it to a COPY relocation, and things go really bad from there. |
| 18 | |
| 19 | (I can reproduce the same failure, simply by turning on -Bsymbolic-functions |
| 20 | with the Gnu linker. Even though the symbol is bound internally, it's |
| 21 | still exported to the dynamic symbol table, and is exposed to a COPY |
| 22 | relocation.) |
| 23 | |
| 24 | I've backed out part of the fix for PR 13577, and -Bsymbolic (or |
| 25 | -Bsymbolic-functions) can now be used with --dynamic-list, but if the |
| 26 | two are used together, we do not set DT_SYMBOLIC or DF_SYMBOLIC |
| 27 | (this matches Gnu ld behavior). We now treat symbols listed in the |
| 28 | dynamic list as premptible, but we do not automatically treat symbols |
| 29 | not listed there as non-premptible. |
| 30 | |
| 31 | gold/ |
| 32 | PR gold/13577 |
| 33 | PR gold/16992 |
| 34 | * layout.cc (Layout::finish_dynamic_section): Don't set DT_SYMBOLIC or |
| 35 | DF_SYMBOLIC if --dynamic-list option is used. |
| 36 | * options.cc (General_options::finalize): --dynamic-list is not |
| 37 | mutually exclusive with -Bsymbolic. |
| 38 | * symtab.h (Symbol::is_preemptible): Don't exclude dynamic symbols not |
| 39 | listed in --dynamic-list. |
| 40 | * testsuite/Makefile.am (dynamic_list_lib2.so): Add |
| 41 | -Bsymbolic-functions. |
| 42 | * testsuite/Makefile.in: Regenerate. |
| 43 | --- |
| 44 | Upstream-Status: Backport |
| 45 | |
| 46 | gold/ChangeLog | 14 ++++++++++++++ |
| 47 | gold/layout.cc | 3 ++- |
| 48 | gold/options.cc | 7 ------- |
| 49 | gold/symtab.h | 6 ++---- |
| 50 | gold/testsuite/Makefile.am | 2 +- |
| 51 | gold/testsuite/Makefile.in | 2 +- |
| 52 | 6 files changed, 20 insertions(+), 14 deletions(-) |
| 53 | |
| 54 | diff --git a/gold/layout.cc b/gold/layout.cc |
| 55 | index bcdaac8..7836640 100644 |
| 56 | --- a/gold/layout.cc |
| 57 | +++ b/gold/layout.cc |
| 58 | @@ -4873,7 +4873,8 @@ Layout::finish_dynamic_section(const Input_objects* input_objects, |
| 59 | flags |= elfcpp::DF_STATIC_TLS; |
| 60 | if (parameters->options().origin()) |
| 61 | flags |= elfcpp::DF_ORIGIN; |
| 62 | - if (parameters->options().Bsymbolic()) |
| 63 | + if (parameters->options().Bsymbolic() |
| 64 | + && !parameters->options().have_dynamic_list()) |
| 65 | { |
| 66 | flags |= elfcpp::DF_SYMBOLIC; |
| 67 | // Add DT_SYMBOLIC for compatibility with older loaders. |
| 68 | diff --git a/gold/options.cc b/gold/options.cc |
| 69 | index 7eb8f27..7f1f69e 100644 |
| 70 | --- a/gold/options.cc |
| 71 | +++ b/gold/options.cc |
| 72 | @@ -1200,13 +1200,6 @@ General_options::finalize() |
| 73 | // in the path, as appropriate. |
| 74 | this->add_sysroot(); |
| 75 | |
| 76 | - // --dynamic-list overrides -Bsymbolic and -Bsymbolic-functions. |
| 77 | - if (this->have_dynamic_list()) |
| 78 | - { |
| 79 | - this->set_Bsymbolic(false); |
| 80 | - this->set_Bsymbolic_functions(false); |
| 81 | - } |
| 82 | - |
| 83 | // Now that we've normalized the options, check for contradictory ones. |
| 84 | if (this->shared() && this->is_static()) |
| 85 | gold_fatal(_("-shared and -static are incompatible")); |
| 86 | diff --git a/gold/symtab.h b/gold/symtab.h |
| 87 | index aa0cb68..9413360 100644 |
| 88 | --- a/gold/symtab.h |
| 89 | +++ b/gold/symtab.h |
| 90 | @@ -604,10 +604,8 @@ class Symbol |
| 91 | if (parameters->options().in_dynamic_list(this->name())) |
| 92 | return true; |
| 93 | |
| 94 | - // If the user used -Bsymbolic or provided a --dynamic-list script, |
| 95 | - // then nothing (else) is preemptible. |
| 96 | - if (parameters->options().Bsymbolic() |
| 97 | - || parameters->options().have_dynamic_list()) |
| 98 | + // If the user used -Bsymbolic, then nothing (else) is preemptible. |
| 99 | + if (parameters->options().Bsymbolic()) |
| 100 | return false; |
| 101 | |
| 102 | // If the user used -Bsymbolic-functions, then functions are not |
| 103 | diff --git a/gold/testsuite/Makefile.am b/gold/testsuite/Makefile.am |
| 104 | index f767c21..7b73f9d 100644 |
| 105 | --- a/gold/testsuite/Makefile.am |
| 106 | +++ b/gold/testsuite/Makefile.am |
| 107 | @@ -1518,7 +1518,7 @@ dynamic_list_lib1.o: dynamic_list_lib1.cc |
| 108 | $(CXXCOMPILE) -c -fpic -o $@ $< |
| 109 | |
| 110 | dynamic_list_lib2.so: gcctestdir/ld dynamic_list_lib2.o $(srcdir)/dynamic_list_2.t |
| 111 | - $(CXXLINK) -Bgcctestdir/ -shared -Wl,--dynamic-list,$(srcdir)/dynamic_list_2.t dynamic_list_lib2.o |
| 112 | + $(CXXLINK) -Bgcctestdir/ -shared -Wl,-Bsymbolic-functions -Wl,--dynamic-list,$(srcdir)/dynamic_list_2.t dynamic_list_lib2.o |
| 113 | dynamic_list_lib2.o: dynamic_list_lib2.cc |
| 114 | $(CXXCOMPILE) -c -fpic -o $@ $< |
| 115 | |
| 116 | diff --git a/gold/testsuite/Makefile.in b/gold/testsuite/Makefile.in |
| 117 | index 217e472..b4ae3fd 100644 |
| 118 | --- a/gold/testsuite/Makefile.in |
| 119 | +++ b/gold/testsuite/Makefile.in |
| 120 | @@ -5319,7 +5319,7 @@ uninstall-am: |
| 121 | @GCC_TRUE@@NATIVE_LINKER_TRUE@ $(CXXCOMPILE) -c -fpic -o $@ $< |
| 122 | |
| 123 | @GCC_TRUE@@NATIVE_LINKER_TRUE@dynamic_list_lib2.so: gcctestdir/ld dynamic_list_lib2.o $(srcdir)/dynamic_list_2.t |
| 124 | -@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(CXXLINK) -Bgcctestdir/ -shared -Wl,--dynamic-list,$(srcdir)/dynamic_list_2.t dynamic_list_lib2.o |
| 125 | +@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(CXXLINK) -Bgcctestdir/ -shared -Wl,-Bsymbolic-functions -Wl,--dynamic-list,$(srcdir)/dynamic_list_2.t dynamic_list_lib2.o |
| 126 | @GCC_TRUE@@NATIVE_LINKER_TRUE@dynamic_list_lib2.o: dynamic_list_lib2.cc |
| 127 | @GCC_TRUE@@NATIVE_LINKER_TRUE@ $(CXXCOMPILE) -c -fpic -o $@ $< |
| 128 | |
| 129 | -- |
| 130 | 1.9.1 |
| 131 | |