From patchwork Thu Sep 17 22:51:58 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joseph Myers X-Patchwork-Id: 8759 Received: (qmail 108915 invoked by alias); 17 Sep 2015 22:52:07 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 108898 invoked by uid 89); 17 Sep 2015 22:52:05 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.3 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: relay1.mentorg.com Date: Thu, 17 Sep 2015 22:51:58 +0000 From: Joseph Myers To: Roland McGrath CC: "H.J. Lu" , GNU C Library Subject: Re: [PATCH] [BZ #18970]: Reference of pthread_setcancelstate in libc.a In-Reply-To: <20150917220353.9BB252C3B3C@topped-with-meat.com> Message-ID: References: <20150917152135.GA25716@intel.com> <20150917195803.E05DF2C3B40@topped-with-meat.com> <20150917215151.6201A2C3B40@topped-with-meat.com> <20150917220353.9BB252C3B3C@topped-with-meat.com> User-Agent: Alpine 2.10 (DEB 1266 2009-07-14) MIME-Version: 1.0 On Thu, 17 Sep 2015, Roland McGrath wrote: > > I don't know what combination of false positives and real problems you'd > > find if linknamespace.pl stopped special-casing weak symbols. > > I think we should look into that. The name space issues are orthogoal to > weakness in all scenarios I can think of. If code reached by function foo > is affected at all by a symbol bar and bar is in the application name space > for some application that can use foo, then there is a problem. This patch effects such a change (weak undefined symbols are required to be in the standard namespace - but it's still the case that such symbols are not followed recursively to find other symbols to check the namespace of, because the linker wouldn't bring in a definition of a function referenced only weakly). It turns out that pthread_setcancelstate is the only such function showing up in linknamespace failures with this patch in testing on x86_64 and x86 (so once HJ's fix, minus testcase, is in, I can commit this patch). 2015-09-17 Joseph Myers * conform/linknamespace.pl: Require weak undefined symbols to be in the standard namespace. (%strong_syms): Rename to %seen_syms. (%strong_seen): Rename to %seen_where. diff --git a/conform/linknamespace.pl b/conform/linknamespace.pl index 15fa613..94ebfd4 100644 --- a/conform/linknamespace.pl +++ b/conform/linknamespace.pl @@ -97,8 +97,8 @@ sub list_syms { # Load information about GLOBAL and WEAK symbols defined or used in # the standard libraries. -# Strong symbols (defined or undefined) from a given object. -%strong_syms = (); +# Symbols from a given object, except for weak defined symbols. +%seen_syms = (); # Strong undefined symbols from a given object. %strong_undef_syms = (); # Objects defining a given symbol (strongly or weakly). @@ -112,17 +112,17 @@ foreach my $sym (@sym_data) { } push (@{$sym_objs{$name}}, $file); } - if ($bind eq "GLOBAL") { - if (!defined ($strong_syms{$file})) { - $strong_syms{$file} = []; + if ($bind eq "GLOBAL" || !$defined) { + if (!defined ($seen_syms{$file})) { + $seen_syms{$file} = []; } - push (@{$strong_syms{$file}}, $name); - if (!$defined) { - if (!defined ($strong_undef_syms{$file})) { - $strong_undef_syms{$file} = []; - } - push (@{$strong_undef_syms{$file}}, $name); + push (@{$seen_syms{$file}}, $name); + } + if ($bind eq "GLOBAL" && !$defined) { + if (!defined ($strong_undef_syms{$file})) { + $strong_undef_syms{$file} = []; } + push (@{$strong_undef_syms{$file}}, $name); } } @@ -132,12 +132,7 @@ foreach my $sym (@sym_data) { # The rules followed are heuristic and so may produce false positives # and false negatives. # -# * Weak undefined symbols are ignored; however, if a code path that -# references one (even just to check if its address is 0) is executed, -# that may conflict with a definition of that symbol in the user's -# program. -# -# * Strong undefined symbols are considered of signficance, but it is +# * All undefined symbols are considered of signficance, but it is # possible that (a) any standard library definition is weak, so can be # overridden by the user's definition, and (b) the symbol is only used # conditionally and not if the program is limited to standard @@ -192,14 +187,14 @@ unlink ($cincfile) || die ("unlink $cincfile: $!\n"); unlink ($cincfile_o) || die ("unlink $cincfile_o: $!\n"); unlink ($cincfile_sym) || die ("unlink $cincfile_sym: $!\n"); -%strong_seen = (); +%seen_where = (); %files_seen = (); %all_undef = (); %current_undef = (); foreach my $sym (@elf_syms) { my ($file, $name, $bind, $defined) = @$sym; if ($bind eq "GLOBAL" && !$defined) { - $strong_seen{$name} = "[initial] $name"; + $seen_where{$name} = "[initial] $name"; $all_undef{$name} = "[initial] $name"; $current_undef{$name} = "[initial] $name"; } @@ -213,9 +208,9 @@ while (%current_undef) { next; } $files_seen{$file} = 1; - foreach my $ssym (@{$strong_syms{$file}}) { - if (!defined ($strong_seen{$ssym})) { - $strong_seen{$ssym} = "$current_undef{$sym} -> [$file] $ssym"; + foreach my $ssym (@{$seen_syms{$file}}) { + if (!defined ($seen_where{$ssym})) { + $seen_where{$ssym} = "$current_undef{$sym} -> [$file] $ssym"; } } foreach my $usym (@{$strong_undef_syms{$file}}) { @@ -230,14 +225,14 @@ while (%current_undef) { } $ret = 0; -foreach my $sym (sort keys %strong_seen) { +foreach my $sym (sort keys %seen_where) { if ($sym =~ /^_/) { next; } if (defined ($stdsyms{$sym})) { next; } - print "$strong_seen{$sym}\n"; + print "$seen_where{$sym}\n"; $ret = 1; }