From patchwork Tue Nov 22 21:43:41 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 83510 Delivered-To: patch@linaro.org Received: by 10.182.1.168 with SMTP id 8csp2392616obn; Tue, 22 Nov 2016 13:44:09 -0800 (PST) X-Received: by 10.99.101.65 with SMTP id z62mr47845621pgb.74.1479851049698; Tue, 22 Nov 2016 13:44:09 -0800 (PST) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id r62si25829706pgr.192.2016.11.22.13.44.09 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 22 Nov 2016 13:44:09 -0800 (PST) Received-SPF: pass (google.com: domain of binutils-return-94556-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org; spf=pass (google.com: domain of binutils-return-94556-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=binutils-return-94556-patch=linaro.org@sourceware.org; dmarc=fail (p=NONE dis=NONE) header.from=gmail.com DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-type; q=dns; s=default; b=r3O0 rB8n1RpJJ7EXgbyR946ZthrdoiawUWyU/oGQH49ilDF18U+01HHe0DtGQfzYqnJ+ W8j9Dburak9r9p4NG4SGnLEbMVOaa80yocxLVnWr2QvI0yftazMBIjDxkRf1iE8E Lj/JVsnMoL2p4/rmwL0m8YXOWgwXzxURraz5ncc= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-type; s=default; bh=KSjlr96fWJ X3yT/RjbNCwaa8cAI=; b=skvFj+/Gq3zo8VpxSdyFSuGXwKFs5deLG/7kmPcEB1 JkJKGU5+QJI1HkbjOo5jSiQCktRSvHl6AwwbpCZTIt8iYIKOgMQoE84LuQ8qV0gG 78FkHD7MbKJUyBtgnzsf+JwGzt+roz8wIeYjoZf2GL/cgwq5RwNZolbeX6GkfJnU U= Received: (qmail 119887 invoked by alias); 22 Nov 2016 21:43:46 -0000 Mailing-List: contact binutils-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: binutils-owner@sourceware.org Delivered-To: mailing list binutils@sourceware.org Received: (qmail 119871 invoked by uid 89); 22 Nov 2016 21:43:45 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.1 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy=274, Decide, risk, late X-HELO: mail-qk0-f196.google.com Received: from mail-qk0-f196.google.com (HELO mail-qk0-f196.google.com) (209.85.220.196) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 22 Nov 2016 21:43:43 +0000 Received: by mail-qk0-f196.google.com with SMTP id x190so7130001qkb.0 for ; Tue, 22 Nov 2016 13:43:43 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=6MaeZLoUyPfvIsbo6xkG1bsiaonzxfEolmTjcKEHBwg=; b=IqsMhfzEcBPkZXfEFwReZukWkPY4gElovE1xpz50/P5wgblqxUO0eyiCuk9lGyBOxm ArShpOf8cNiV1iIuRUjwzsUxdXL+DQWR3AQFVZmqjgbOffIB6eweGfQyoohfWhkWGszz T5NrySSRmL/UN4NJSrFT3bzBQvGgrAB9jcEy6P2rU7je+2EDljRlx9G0ZZVmPG5xGpFr v9eHzXmpJ4ynOxsjoMyUk0yM+0BnfItjNRGv0ipBqjw4erDD3l3UxsqClJQQQxl8MBqI X/VTKydxJ6mIYG8zUsW3QC5aYx/ecf9Hv+sjMsOEPOEi9dQtZq1HRRam+c0qD884YJ15 6njA== X-Gm-Message-State: AKaTC01Cs6sy72tk3Hz8AXR0SecIDt8Zhmy28eXdfKQ3kIQ3yr1T/o+lBWEJfpPSSqOTBQO+G5gvRukF6xDQhQ== X-Received: by 10.55.91.1 with SMTP id p1mr26681783qkb.275.1479851021983; Tue, 22 Nov 2016 13:43:41 -0800 (PST) MIME-Version: 1.0 Received: by 10.55.115.70 with HTTP; Tue, 22 Nov 2016 13:43:41 -0800 (PST) In-Reply-To: <20161122001415.GH11815@bubble.grove.modra.org> References: <20150726221550.GA16472@gmail.com> <20150801140704.GA23091@gmail.com> <20161121030919.GD11815@bubble.grove.modra.org> <20161122001415.GH11815@bubble.grove.modra.org> From: "H.J. Lu" Date: Tue, 22 Nov 2016 13:43:41 -0800 Message-ID: Subject: Re: [PATCH] PR ld/18720: Properly merge hidden versioned symbol To: Alan Modra Cc: Binutils X-IsSubscribed: yes On Mon, Nov 21, 2016 at 4:14 PM, Alan Modra wrote: > On Mon, Nov 21, 2016 at 01:09:20PM -0800, H.J. Lu wrote: >> On Sun, Nov 20, 2016 at 7:09 PM, Alan Modra wrote: >> > On Wed, Aug 05, 2015 at 07:43:21PM -0700, H.J. Lu wrote: >> >> I will check it in this Friday unless there is an objection. >> > >> > HJ, git 6e33951edc change to elf_link_output_extsym where you >> > introduce local_bind, is broken. You can't change global syms to >> > STB_LOCAL that late, after _bfd_elf_link_renumber_dynsyms, as otherwise >> > you run the risk of ordering STB_LOCAL symbols after global symbols. >> > The ELF gABI is clear that "all symbols with STB_LOCAL binding precede >> > the weak and global symbols". (It's also wrong to test flags on a >> > bfd_link_hash_warning symbol.) >> > >> > I don't have a testcase for you. I noticed the bug when looking at >> > PR20828. Please revert the elf_link_output_extsym change and >> > implement by setting forced_local before the last run of >> > _bfd_elf_link_renumber_dynsyms. >> > >> >> How about this patch? > > OK thanks, it looks almost the same as the one I threw together. > > You could also move the code hiding weak undefined non-default > visibility symbols. > > /* If a weak undefined symbol has non-default visibility, we also > hide it from the dynamic linker. */ > if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT > && h->root.type == bfd_link_hash_undefweak) > (*bed->elf_backend_hide_symbol) (eif->info, h, TRUE); > > /* A hidden versioned symbol in executable should be forced local if > it is is locally defined, not referenced by shared library and not > exported. */ > else if (bfd_link_executable (eif->info) > etc. > This is what I checked in. Thanks. -- H.J. >From 5fcacf7f68b34b275af586e2e72f29aef5522b05 Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Mon, 21 Nov 2016 13:05:44 -0800 Subject: [PATCH] Properly hide hidden versioned symbol in executable A hidden versioned symbol in executable should be forced local if it is locally defined, not referenced by shared library and not exported. We must do it before _bfd_elf_link_renumber_dynsyms. bfd/ * elflink.c (_bfd_elf_fix_symbol_flags): Hide hidden versioned symbol in executable. (elf_link_output_extsym): Don't change bind from global to local when linking executable. ld/ * testsuite/ld-elf/indirect.exp: Add a test for PR 18720. * testsuite/ld-elf/pr18720.rd: New file. --- bfd/elflink.c | 55 ++++++++++++++++++++-------------------- ld/testsuite/ld-elf/indirect.exp | 3 +++ ld/testsuite/ld-elf/pr18720.rd | 4 +++ 3 files changed, 34 insertions(+), 28 deletions(-) create mode 100644 ld/testsuite/ld-elf/pr18720.rd diff --git a/bfd/elflink.c b/bfd/elflink.c index 76f91e9..5abac8d 100644 --- a/bfd/elflink.c +++ b/bfd/elflink.c @@ -2655,18 +2655,35 @@ _bfd_elf_fix_symbol_flags (struct elf_link_hash_entry *h, && (h->root.u.def.section->owner->flags & (DYNAMIC | BFD_PLUGIN)) == 0) h->def_regular = 1; + /* If a weak undefined symbol has non-default visibility, we also + hide it from the dynamic linker. */ + if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT + && h->root.type == bfd_link_hash_undefweak) + (*bed->elf_backend_hide_symbol) (eif->info, h, TRUE); + + /* A hidden versioned symbol in executable should be forced local if + it is is locally defined, not referenced by shared library and not + exported. */ + else if (bfd_link_executable (eif->info) + && h->versioned == versioned_hidden + && !eif->info->export_dynamic + && !h->dynamic + && !h->ref_dynamic + && h->def_regular) + (*bed->elf_backend_hide_symbol) (eif->info, h, TRUE); + /* If -Bsymbolic was used (which means to bind references to global symbols to the definition within the shared object), and this symbol was defined in a regular object, then it actually doesn't need a PLT entry. Likewise, if the symbol has non-default visibility. If the symbol has hidden or internal visibility, we will force it local. */ - if (h->needs_plt - && bfd_link_pic (eif->info) - && is_elf_hash_table (eif->info->hash) - && (SYMBOLIC_BIND (eif->info, h) - || ELF_ST_VISIBILITY (h->other) != STV_DEFAULT) - && h->def_regular) + else if (h->needs_plt + && bfd_link_pic (eif->info) + && is_elf_hash_table (eif->info->hash) + && (SYMBOLIC_BIND (eif->info, h) + || ELF_ST_VISIBILITY (h->other) != STV_DEFAULT) + && h->def_regular) { bfd_boolean force_local; @@ -2675,12 +2692,6 @@ _bfd_elf_fix_symbol_flags (struct elf_link_hash_entry *h, (*bed->elf_backend_hide_symbol) (eif->info, h, force_local); } - /* If a weak undefined symbol has non-default visibility, we also - hide it from the dynamic linker. */ - if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT - && h->root.type == bfd_link_hash_undefweak) - (*bed->elf_backend_hide_symbol) (eif->info, h, TRUE); - /* If this is a weak defined symbol in a dynamic object, and we know the real definition in the dynamic object, copy interesting flags over to the real definition. */ @@ -9250,16 +9261,6 @@ elf_link_output_extsym (struct bfd_hash_entry *bh, void *data) long indx; int ret; unsigned int type; - /* A symbol is bound locally if it is forced local or it is locally - defined, hidden versioned, not referenced by shared library and - not exported when linking executable. */ - bfd_boolean local_bind = (h->forced_local - || (bfd_link_executable (flinfo->info) - && !flinfo->info->export_dynamic - && !h->dynamic - && !h->ref_dynamic - && h->def_regular - && h->versioned == versioned_hidden)); if (h->root.type == bfd_link_hash_warning) { @@ -9271,12 +9272,12 @@ elf_link_output_extsym (struct bfd_hash_entry *bh, void *data) /* Decide whether to output this symbol in this pass. */ if (eoinfo->localsyms) { - if (!local_bind) + if (!h->forced_local) return TRUE; } else { - if (local_bind) + if (h->forced_local) return TRUE; } @@ -9493,7 +9494,7 @@ elf_link_output_extsym (struct bfd_hash_entry *bh, void *data) abort (); } - if (local_bind) + if (h->forced_local) { sym.st_info = ELF_ST_INFO (STB_LOCAL, type); /* Turn off visibility on local symbol. */ @@ -9604,10 +9605,8 @@ elf_link_output_extsym (struct bfd_hash_entry *bh, void *data) /* Since there is no version information in the dynamic string, if there is no version info in symbol version section, we will have a run-time problem if not linking executable, referenced - by shared library, not locally defined, or not bound locally. - */ + by shared library, or not bound locally. */ if (h->verinfo.verdef == NULL - && !local_bind && (!bfd_link_executable (flinfo->info) || h->ref_dynamic || !h->def_regular)) diff --git a/ld/testsuite/ld-elf/indirect.exp b/ld/testsuite/ld-elf/indirect.exp index b4766fd..3176210 100644 --- a/ld/testsuite/ld-elf/indirect.exp +++ b/ld/testsuite/ld-elf/indirect.exp @@ -91,6 +91,9 @@ set build_tests { {"Build pr18720b1.o" "-r -nostdlib tmpdir/pr18720b.o" "" {dummy.c} {} "pr18720b1.o"} + {"Build pr18720a" + "tmpdir/pr18720a.o tmpdir/pr18720b.o tmpdir/libpr18720c.so" "" + {check-ptr-eq.c} {{readelf {--dyn-syms} pr18720.rd}} "pr18720a"} {"Build libpr19553b.so" "-shared -Wl,--version-script=pr19553.map" "-fPIC" {pr19553b.c} {} "libpr19553b.so"} diff --git a/ld/testsuite/ld-elf/pr18720.rd b/ld/testsuite/ld-elf/pr18720.rd new file mode 100644 index 0000000..b5e848f --- /dev/null +++ b/ld/testsuite/ld-elf/pr18720.rd @@ -0,0 +1,4 @@ +#failif +#... +.* found at index >= .dynsym's sh_info value .* +#... -- 2.7.4