[Bug ld/21382] --as-needed cannot be combined with -flto

2017-09-27 Thread cvs-commit at gcc dot gnu.org
https://sourceware.org/bugzilla/show_bug.cgi?id=21382

--- Comment #7 from cvs-commit at gcc dot gnu.org  ---
The binutils-2_28-branch branch has been updated by Alan Modra
:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=b805037cf0061e86b1a71cba26fdaff52a46844d

commit b805037cf0061e86b1a71cba26fdaff52a46844d
Author: H.J. Lu 
Date:   Thu Apr 20 07:48:24 2017 -0700

Handle symbol defined in IR and referenced in DSO

We need to make an IR symbol visible if it is defined in an IR object
and referenced in a dynamic object.  When --as-needed is used, since
linker removes the IR symbol reference of the dynamic object if the
dynamic object isn't needed in the first pass, the IR definition isn't
visible to the dynamic object even if the dynamic object becomes needed
in the second pass.  Add dynamic_ref_after_ir_def to bfd_link_hash_entry
to track IR symbol which is defined in an IR object and later referenced
in a dynamic object.  dynamic_ref_after_ir_def is preserved when restoring
the symbol table for unneeded dynamic object.

bfd/

PR ld/21382
* elflink.c (elf_link_add_object_symbols): Preserve
dynamic_ref_after_ir_def when restoring the symbol table for
unneeded dynamic object.

include/

PR ld/21382
* bfdlink.h (bfd_link_hash_entry): Add dynamic_ref_after_ir_def.

ld/

PR ld/21382
* plugin.c (is_visible_from_outside): Symbol may be visible
from outside if dynamic_ref_after_ir_def is set.
(plugin_notice): Set dynamic_ref_after_ir_def if the symbol is
defined in an IR object and referenced in a dynamic object.
* testsuite/ld-plugin/lto.exp: Run PR ld/21382 tests.
* testsuite/ld-plugin/pr21382a.c: New file.
* testsuite/ld-plugin/pr21382b.c: Likewise.

(cherry picked from commit 59fa66c53823dc695f78669f40ec2eebab3aec42)

-- 
You are receiving this mail because:
You are on the CC list for the bug.
___
bug-binutils mailing list
bug-binutils@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-binutils


[Bug ld/21382] --as-needed cannot be combined with -flto

2017-04-20 Thread hjl.tools at gmail dot com
https://sourceware.org/bugzilla/show_bug.cgi?id=21382

H.J. Lu  changed:

   What|Removed |Added

 Status|NEW |RESOLVED
 Resolution|--- |FIXED
   Target Milestone|--- |2.29

--- Comment #6 from H.J. Lu  ---
Fixed for 2.29.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
___
bug-binutils mailing list
bug-binutils@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-binutils


[Bug ld/21382] --as-needed cannot be combined with -flto

2017-04-20 Thread cvs-commit at gcc dot gnu.org
https://sourceware.org/bugzilla/show_bug.cgi?id=21382

--- Comment #5 from cvs-commit at gcc dot gnu.org  ---
The master branch has been updated by H.J. Lu :

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=59fa66c53823dc695f78669f40ec2eebab3aec42

commit 59fa66c53823dc695f78669f40ec2eebab3aec42
Author: H.J. Lu 
Date:   Thu Apr 20 07:48:24 2017 -0700

Handle symbol defined in IR and referenced in DSO

We need to make an IR symbol visible if it is defined in an IR object
and referenced in a dynamic object.  When --as-needed is used, since
linker removes the IR symbol reference of the dynamic object if the
dynamic object isn't needed in the first pass, the IR definition isn't
visible to the dynamic object even if the dynamic object becomes needed
in the second pass.  Add dynamic_ref_after_ir_def to bfd_link_hash_entry
to track IR symbol which is defined in an IR object and later referenced
in a dynamic object.  dynamic_ref_after_ir_def is preserved when restoring
the symbol table for unneeded dynamic object.

bfd/

PR ld/21382
* elflink.c (elf_link_add_object_symbols): Preserve
dynamic_ref_after_ir_def when restoring the symbol table for
unneeded dynamic object.

include/

PR ld/21382
* bfdlink.h (bfd_link_hash_entry): Add dynamic_ref_after_ir_def.

ld/

PR ld/21382
* plugin.c (is_visible_from_outside): Symbol may be visible
from outside if dynamic_ref_after_ir_def is set.
(plugin_notice): Set dynamic_ref_after_ir_def if the symbol is
defined in an IR object and referenced in a dynamic object.
* testsuite/ld-plugin/lto.exp: Run PR ld/21382 tests.
* testsuite/ld-plugin/pr21382a.c: New file.
* testsuite/ld-plugin/pr21382b.c: Likewise.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
___
bug-binutils mailing list
bug-binutils@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-binutils


[Bug ld/21382] --as-needed cannot be combined with -flto

2017-04-18 Thread hjl.tools at gmail dot com
https://sourceware.org/bugzilla/show_bug.cgi?id=21382

--- Comment #4 from H.J. Lu  ---
A patch is posted at

https://sourceware.org/ml/binutils/2017-04/msg00144.html

-- 
You are receiving this mail because:
You are on the CC list for the bug.
___
bug-binutils mailing list
bug-binutils@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-binutils


[Bug ld/21382] --as-needed cannot be combined with -flto

2017-04-13 Thread hjl.tools at gmail dot com
https://sourceware.org/bugzilla/show_bug.cgi?id=21382

H.J. Lu  changed:

   What|Removed |Added

   Attachment #9992|0   |1
is obsolete||
 CC||hjl.tools at gmail dot com

--- Comment #3 from H.J. Lu  ---
Created attachment 9993
  --> https://sourceware.org/bugzilla/attachment.cgi?id=9993=edit
An updated patch

-- 
You are receiving this mail because:
You are on the CC list for the bug.
___
bug-binutils mailing list
bug-binutils@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-binutils


[Bug ld/21382] --as-needed cannot be combined with -flto

2017-04-13 Thread hjl.tools at gmail dot com
https://sourceware.org/bugzilla/show_bug.cgi?id=21382

--- Comment #2 from H.J. Lu  ---
Created attachment 9992
  --> https://sourceware.org/bugzilla/attachment.cgi?id=9992=edit
A patch

This will introduce false reference from a shared library which isn't used
otherwise.

Before the change:

[hjl@gnu-6 pr15146a]$ cat foo.c 
extern int xxx;

int
bar (void)
{
  return xxx;
}

int
main ()
{ 
  return 0;
}
[hjl@gnu-6 pr15146a]$ cat yyy.c 
extern void bar (void);

void
zzz ()
{
  bar ();
}
[hjl@gnu-6 pr15146a]$ cat xxx.c 
int xxx  = 3;
[hjl@gnu-6 pr15146a]$ make
gcc -flto -O2   -c -o foo.o foo.c
gcc -shared -fPIC -o libxxx.so xxx.c
gcc -shared -fPIC -o libyyy.so yyy.c libxxx.so
gcc -flto -O2 -Wl,--as-needed  -o x foo.o libyyy.so -Wl,-rpath-link,.
[hjl@gnu-6 pr15146a]$ 

after:

[hjl@gnu-6 pr15146a]$ gcc -flto -O2 -Wl,--as-needed  -o x foo.o libyyy.so
-Wl,-rpath-link,. -B./
/tmp/ccQlE2wY.ltrans0.ltrans.o: In function `bar':
:(.text+0x2): undefined reference to `xxx'
collect2: error: ld returned 1 exit status
[hjl@gnu-6 pr15146a]$ 

Gold also failed:

[hjl@gnu-6 pr15146a]$ gcc -flto -O2 -Wl,--as-needed  -o x foo.o libyyy.so
-Wl,-rpath-link,. -fuse-ld=gold
/tmp/ccLftUeD.ltrans0.ltrans.o::function bar: error: undefined
reference to 'xxx'
collect2: error: ld returned 1 exit status
[hjl@gnu-6 pr15146a]$

-- 
You are receiving this mail because:
You are on the CC list for the bug.
___
bug-binutils mailing list
bug-binutils@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-binutils


[Bug ld/21382] --as-needed cannot be combined with -flto

2017-04-13 Thread rguenth at gcc dot gnu.org
https://sourceware.org/bugzilla/show_bug.cgi?id=21382

Richard Biener  changed:

   What|Removed |Added

 Status|UNCONFIRMED |NEW
   Last reconfirmed||2017-04-13
 CC||rguenth at gcc dot gnu.org
 Ever confirmed|0   |1

--- Comment #1 from Richard Biener  ---
To clarify the linker resolution is bougs:

1
m.o 3
165 e2668d19ae58a8ab PREVAILING_DEF_IRONLY x
180 e2668d19ae58a8ab PREVAILING_DEF main
185 e2668d19ae58a8ab UNDEF y

but x should be PREVAILING_DEF_IRONLY_EXP as gold correctly says.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
___
bug-binutils mailing list
bug-binutils@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-binutils