This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: PATCH: PR ld/14272: Mark the plugin symbol undefined
- From: "H.J. Lu" <hjl dot tools at gmail dot com>
- To: Binutils <binutils at sourceware dot org>
- Date: Fri, 6 Feb 2015 04:23:21 -0800
- Subject: Re: PATCH: PR ld/14272: Mark the plugin symbol undefined
- Authentication-results: sourceware.org; auth=none
- References: <20120628221026 dot GA5008 at intel dot com> <CAMe9rOqVkDWQ3gzojEQzRLmcj=DC+a9GS5HWX2Zy9S7HD9QkBA at mail dot gmail dot com> <20150204110841 dot GN14796 at bubble dot grove dot modra dot org> <CAMe9rOoh3dVaRUSWFb5=V=CEtsL24+s=7DeZiDQ+a7LtEU4q_w at mail dot gmail dot com> <20150206005938 dot GY14796 at bubble dot grove dot modra dot org> <CAMe9rOqd1RzU9hfqYkg+Tbyd0hSLgoWi3ECVBWaX8YAr5iNQ7Q at mail dot gmail dot com> <20150206015245 dot GZ14796 at bubble dot grove dot modra dot org> <CAMe9rOowvONfJkrP2cNA8TvPQWyGAWM72MegATaq6cNcP6MbYQ at mail dot gmail dot com> <CAMe9rOo1Y_imS06Mf1c=BPX4iMi2Ox171J-5dXMOkUgx8vFGow at mail dot gmail dot com>
On Thu, Feb 05, 2015 at 09:10:32PM -0800, H.J. Lu wrote:
> On Thu, Feb 5, 2015 at 8:06 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
> > On Thu, Feb 5, 2015 at 5:52 PM, Alan Modra <amodra@gmail.com> wrote:
> >> On Thu, Feb 05, 2015 at 05:06:38PM -0800, H.J. Lu wrote:
> >>> On Thu, Feb 5, 2015 at 4:59 PM, Alan Modra <amodra@gmail.com> wrote:
> >>> > On Wed, Feb 04, 2015 at 04:36:16AM -0800, H.J. Lu wrote:
> >>> >> On Wed, Feb 4, 2015 at 3:08 AM, Alan Modra <amodra@gmail.com> wrote:
> >>> >> > On Tue, Feb 03, 2015 at 09:06:47AM -0800, H.J. Lu wrote:
> >>> >> >> PR ld/12365
> >>> >> >> * ld-plugin/pr12365a.c: New file.
> >>> >> >> * ld-plugin/pr12365b.c: Likewise.
> >>> >> >> * ld-plugin/pr12365c.c: Likewise.
> >>> >> >
> >>> >> > The testcase fails when using gcc-5. Also, gcc-5 objects don't seem
> >>> >> > exercise your _bfd_elf_fix_symbol_flags code. I presume you need an
> >>> >> > older version of gcc, with lto bugs, to need those hacks. Is that
> >>> >> > true? Can you write a testcase that does exercise your
> >>> >> > _bfd_elf_fix_symbol_flags code?
> >>> >>
> >>> >> The -flto-partition default was changed. I checked in this patch
> >>> >> to pass -flto-partition=none to the PR ld/12365 test.
> >>> >
> >>> > The test fails when using gcc-4.7.2 on powerpc64-linux. Please fix it.
> >>>
> >>> Does it fail with gcc 4.8? What is the error message?
> >>
> >> No error message. The link succeeds. Similarly with gcc-4.9 and
> >
> > The test is very sensitive to LTO partition. Also
>
> The test is also sensitive to LTO IR order. I am testing this patch.
>
> > #define ASMNAME(cname) ASMNAME2 (__USER_LABEL_PREFIX__, cname)
> > #define ASMNAME2(prefix, cname) STRING (prefix) cname
> > #define STRING(x) #x
> >
> > typedef __SIZE_TYPE__ size_t;
> > extern void abort (void);
> > extern void *memcpy (void *, const void *, size_t)
> > __asm (ASMNAME ("my_memcpy"));
> >
> > doesn't work for all platforms. I will keep digging.
> >
>
> I will also limit this test to x86 for now until we find a way to make it
> work for other platforms.
>
It turns out that existing tests show PR ld/12365. The "plugin claimfile
resolve symbol" and "plugin claimfile replace symbol" tests expect
`func' referenced in section `.text.startup' of tmpdir/main.o: defined
in discarded section `.text' of tmpdir/func.o (symbol from plugin)
Since plugin never provides func, the error message should be
tmpdir/main.o: In function `main':
main.c:(.text.startup+0x15): undefined reference to `func'
I am checking in this patch to move the plugin symbol marking from
_bfd_elf_fix_symbol_flags to elf_link_input_bfd. I kept the PR ld/12365
test and limited to x86 targets.
H.J.
---
diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index f12a610..1220455 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,11 @@
+2015-02-06 H.J. Lu <hongjiu.lu@intel.com>
+
+ PR ld/12365
+ PR ld/14272
+ * elflink.c (_bfd_elf_fix_symbol_flags): Revert the last change.
+ (elf_link_input_bfd): Mark the plugin symbol undefined if it is
+ referenced from a non-IR file.
+
2015-02-06 Nick Clifton <nickc@redhat.com>
PR binutils/17512
diff --git a/bfd/elflink.c b/bfd/elflink.c
index 604cfb6..e8c4ad4 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -2423,20 +2423,6 @@ _bfd_elf_fix_symbol_flags (struct elf_link_hash_entry *h,
}
else
{
- /* If a plugin symbol is referenced from a non-IR file, mark
- the symbol as undefined, except for symbol for linker
- created section. */
- if (h->root.non_ir_ref
- && (h->root.type == bfd_link_hash_defined
- || h->root.type == bfd_link_hash_defweak)
- && (h->root.u.def.section->flags & SEC_LINKER_CREATED) == 0
- && h->root.u.def.section->owner != NULL
- && (h->root.u.def.section->owner->flags & BFD_PLUGIN) != 0)
- {
- h->root.type = bfd_link_hash_undefined;
- h->root.u.undef.abfd = h->root.u.def.section->owner;
- }
-
/* Unfortunately, NON_ELF is only correct if the symbol
was first seen in a non-ELF file. Fortunately, if the symbol
was first seen in an ELF file, we're probably OK unless the
@@ -9807,6 +9793,22 @@ elf_link_input_bfd (struct elf_final_link_info *flinfo, bfd *input_bfd)
s_type = h->type;
+ /* If a plugin symbol is referenced from a non-IR file,
+ mark the symbol as undefined, except for symbol for
+ linker created section. */
+ if (h->root.non_ir_ref
+ && (h->root.type == bfd_link_hash_defined
+ || h->root.type == bfd_link_hash_defweak)
+ && (h->root.u.def.section->flags
+ & SEC_LINKER_CREATED) == 0
+ && h->root.u.def.section->owner != NULL
+ && (h->root.u.def.section->owner->flags
+ & BFD_PLUGIN) != 0)
+ {
+ h->root.type = bfd_link_hash_undefined;
+ h->root.u.undef.abfd = h->root.u.def.section->owner;
+ }
+
ps = NULL;
if (h->root.type == bfd_link_hash_defined
|| h->root.type == bfd_link_hash_defweak)
diff --git a/ld/testsuite/ChangeLog b/ld/testsuite/ChangeLog
index 1041bd1..075016b 100644
--- a/ld/testsuite/ChangeLog
+++ b/ld/testsuite/ChangeLog
@@ -1,3 +1,11 @@
+2015-02-06 H.J. Lu <hongjiu.lu@intel.com>
+
+ PR ld/12365
+ PR ld/14272
+ * ld-plugin/lto.exp: Run the PR ld/12365 test only for x86 targets.
+ * ld-plugin/plugin-7.d: Updated.
+ * ld-plugin/plugin-8.d: Likewise.
+
2015-02-04 H.J. Lu <hongjiu.lu@intel.com>
* ld-plugin/lto.exp: Pass -flto-partition=none to the PR
diff --git a/ld/testsuite/ld-plugin/lto.exp b/ld/testsuite/ld-plugin/lto.exp
index 065e1bb..6d9500b 100644
--- a/ld/testsuite/ld-plugin/lto.exp
+++ b/ld/testsuite/ld-plugin/lto.exp
@@ -383,12 +383,23 @@ if {![string match "" $catch_output]} {
if { [at_least_gcc_version 4 7] } {
# Check expected LTO linker errors.
- set testname "PR ld/12365"
- set exec_output [run_host_cmd "$CC" "-O2 -flto -flto-partition=none -fuse-linker-plugin tmpdir/pr12365a.o tmpdir/pr12365b.o tmpdir/pr12365c.o"]
- if { [ regexp "undefined reference to `my_bcopy'" $exec_output ] } {
- pass $testname
- } {
- fail $testname
+ # Since the asm symbol name hack in pr12365b.c doesn't work on all
+ # targets, run PR ld/12365 tests only for known targets.
+ if { ([istarget "i?86-*-elf*"]
+ || (([istarget "i?86-*-linux*"] || [istarget "i?86-*-gnu*"])
+ && ![istarget "*-*-*aout*"]
+ && ![istarget "*-*-*oldld*"])
+ || [istarget "i?86-*-nacl*"]
+ || [istarget "x86_64-*-nacl*"]
+ || [istarget "x86_64-*-linux*"]
+ || [istarget "amd64-*-linux*"]) } {
+ set testname "PR ld/12365"
+ set exec_output [run_host_cmd "$CC" "-O2 -flto -flto-partition=none -fuse-linker-plugin tmpdir/pr12365a.o tmpdir/pr12365b.o tmpdir/pr12365c.o"]
+ if { [ regexp "undefined reference to `my_bcopy'" $exec_output ] } {
+ pass $testname
+ } {
+ fail $testname
+ }
}
set testname "PR ld/12942 (3)"
set exec_output [run_host_cmd "$CXX" "-O2 -flto -fuse-linker-plugin tmpdir/pr12942b.o tmpdir/pr12942a.o"]
diff --git a/ld/testsuite/ld-plugin/plugin-7.d b/ld/testsuite/ld-plugin/plugin-7.d
index 28a7036..d1c159c 100644
--- a/ld/testsuite/ld-plugin/plugin-7.d
+++ b/ld/testsuite/ld-plugin/plugin-7.d
@@ -28,6 +28,7 @@ hook called: claim_file tmpdir/func.o \[@0/.* CLAIMED
hook called: claim_file tmpdir/text.o \[@0/.* not claimed
#...
hook called: all symbols read.
-`_?func' referenced in section `\.text.*' of tmpdir/main.o: defined in discarded section .*
+tmpdir/main.o: In function `main':
+.*main.c.*: undefined reference to `func'
hook called: cleanup.
#...
diff --git a/ld/testsuite/ld-plugin/plugin-8.d b/ld/testsuite/ld-plugin/plugin-8.d
index 8170b54..2c7a15b 100644
--- a/ld/testsuite/ld-plugin/plugin-8.d
+++ b/ld/testsuite/ld-plugin/plugin-8.d
@@ -32,6 +32,7 @@ hook called: claim_file tmpdir/text.o \[@0/.* not claimed
hook called: all symbols read.
Sym: '_?func' Resolution: LDPR_PREVAILING_DEF
Sym: '_?func2' Resolution: LDPR_PREVAILING_DEF_IRONLY
-`_?func' referenced in section `\.text.*' of tmpdir/main.o: defined in discarded section .*
+tmpdir/main.o: In function `main':
+.*main.c.*: undefined reference to `func'
hook called: cleanup.
#...