[Bug ld/14915] New: --copy-dt-needed-entries not working

2012-12-04 Thread rguenth at gcc dot gnu.org
http://sourceware.org/bugzilla/show_bug.cgi?id=14915

 Bug #: 14915
   Summary: --copy-dt-needed-entries not working
   Product: binutils
   Version: 2.23
Status: NEW
  Severity: normal
  Priority: P2
 Component: ld
AssignedTo: unassig...@sourceware.org
ReportedBy: rgue...@gcc.gnu.org
Classification: Unclassified


 gcc -o libt1.so -shared -lm
 gcc -o libt2.so -shared -Wl,--copy-dt-needed-entries -L. -lt1

libt1.so is as expected:

 readelf -d libt1.so

Dynamic section at offset 0xe48 contains 22 entries:
  TagType Name/Value
 0x0001 (NEEDED) Shared library: [libm.so.6]
 0x0001 (NEEDED) Shared library: [libc.so.6]
 0x000c (INIT)   0x480
...

but libt2.so does not have a NEEDED entry for libm.so.6:

 readelf -d libt2.so 

Dynamic section at offset 0xe48 contains 22 entries:
  TagType Name/Value
 0x0001 (NEEDED) Shared library: [libt1.so]
 0x0001 (NEEDED) Shared library: [libc.so.6]
 0x000c (INIT)   0x480
...

(trying to come up with a testcase where --[no-]copy-dt-needed-entries matters)

Same behavior with ld 2.18 (and --[no-]add-needed) btw.  Same behavior
if libt2.so is not a shared object.

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
--- 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/14915] --copy-dt-needed-entries not working

2012-12-04 Thread matz at suse dot de
http://sourceware.org/bugzilla/show_bug.cgi?id=14915

Michael Matz matz at suse dot de changed:

   What|Removed |Added

 CC||matz at suse dot de

--- Comment #1 from Michael Matz matz at suse dot de 2012-12-04 14:06:26 UTC 
---
Behaviour also doesn't change if we include objects that refer to stuff from
libm or libt1 into libt2.  I tried to debug ld a bit to see where this is
supposed to be handled but got lost after two hours.  It seems that some
handling of dt_needed entries in elf32.xm:gld*_after_open is only done
for executables, but even creating an executable doesn't help.

In any case, I couldn't find any code that really tries to add DT_NEEDED
entries from referred libraries to the output file.  The code in
elflink.c:elf_link_add_object_symbols at least only adds to the htab-needed
list on those entries (and 'libm.so.6' is included there), but doesn't actually
call elf_add_dt_needed_tag on those entries (and nobody else does
either).

It certainly doesn't work as documented or expected (with my expectations).

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
--- 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/14915] --copy-dt-needed-entries not working

2012-12-04 Thread hjl.tools at gmail dot com
http://sourceware.org/bugzilla/show_bug.cgi?id=14915

--- Comment #2 from H.J. Lu hjl.tools at gmail dot com 2012-12-04 14:07:56 
UTC ---
Please show the output of

gcc -o libt2.so -shared -Wl,--copy-dt-needed-entries -L. -lt1 -v

We need to see all command-line options passed to
linker.

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
--- 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/14915] --copy-dt-needed-entries not working

2012-12-04 Thread hjl.tools at gmail dot com
http://sourceware.org/bugzilla/show_bug.cgi?id=14915

H.J. Lu hjl.tools at gmail dot com changed:

   What|Removed |Added

 Status|NEW |WAITING
 CC||hjl.tools at gmail dot com

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
--- 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/14915] --copy-dt-needed-entries not working

2012-12-04 Thread hjl.tools at gmail dot com
http://sourceware.org/bugzilla/show_bug.cgi?id=14915

H.J. Lu hjl.tools at gmail dot com changed:

   What|Removed |Added

 Status|WAITING |NEW

--- Comment #4 from H.J. Lu hjl.tools at gmail dot com 2012-12-04 14:30:28 
UTC ---
This option is renamed from --add-needed:

http://sourceware.org/ml/binutils/2004-07/msg00093.html

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
--- 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/14915] --copy-dt-needed-entries not working

2012-12-04 Thread matz at suse dot de
http://sourceware.org/bugzilla/show_bug.cgi?id=14915

--- Comment #5 from Michael Matz matz at suse dot de 2012-12-04 14:39:58 UTC 
---
(In reply to comment #4)
 This option is renamed from --add-needed:
 
 http://sourceware.org/ml/binutils/2004-07/msg00093.html

Yes, but why are you mentioning that?

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
--- 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/14915] --copy-dt-needed-entries not working

2012-12-04 Thread rguenth at gcc dot gnu.org
http://sourceware.org/bugzilla/show_bug.cgi?id=14915

--- Comment #6 from Richard Guenther rguenth at gcc dot gnu.org 2012-12-04 
14:41:12 UTC ---
(In reply to comment #5)
 (In reply to comment #4)
  This option is renamed from --add-needed:
  
  http://sourceware.org/ml/binutils/2004-07/msg00093.html
 
 Yes, but why are you mentioning that?

Btw, I explicitely stated that even before the rename, with ld 2.18,
it did not work as expected (using --[no-]add-needed).

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
--- 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/14915] --copy-dt-needed-entries not working

2012-12-04 Thread matz at suse dot de
http://sourceware.org/bugzilla/show_bug.cgi?id=14915

--- Comment #7 from Michael Matz matz at suse dot de 2012-12-04 14:44:50 UTC 
---
(In reply to comment #5)
 (In reply to comment #4)
  This option is renamed from --add-needed:
  
  http://sourceware.org/ml/binutils/2004-07/msg00093.html
 
 Yes, but why are you mentioning that?

In particular, from that thread is referred the GCC problem that you wanted
to fix with adding --no-add-needed:
http://gcc.gnu.org/ml/gcc/2004-04/msg01130.html

The problem specifically was that libunwind was added to DT_NEEDED because
it was itself DT_NEEDED by libgcc_s, and it was said that this was how the
linker is supposed to work.  Now, meanwhile the default got switched, i.e.
--no-copy-dt-needed-entries is the default, but we're supposed to be able
to switch back with --copy-dt-needed-entries.  And this bug report is about
the fact, that this doesn't work.

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
--- 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/14915] --copy-dt-needed-entries not working

2012-12-04 Thread matz at suse dot de
http://sourceware.org/bugzilla/show_bug.cgi?id=14915

--- Comment #8 from Michael Matz matz at suse dot de 2012-12-04 14:56:09 UTC 
---
Let's create a different testcase showing also similar symptoms of not
correctly adding DT_NEEDED entries as documented, this time to search scopes:

% cat bla.c
extern double sin (double);
double f (double i) { return sin (i); }
% gcc -c -fPIC bla.c
% ./ld/ld-new -shared -o libt1.so bla.o -lm -zdefs
% readelf -d libt1.so | grep NEEDED
 0x0001 (NEEDED) Shared library: [libm.so.6]

Everything fine so far.  Now we want to generate libt2 also referring
to a libm function, want to link it only with libt1 and expect that
there's some way to include libm into the search scopes with some option to ld.
 The documented option is --copy-dt-needed-entries, so:

% cat bla2.c
extern double f (double);
extern double sin (double);
double g (double i) { return f(i) + sin (i); }
% gcc -c -fPIC bla2.c

So, bla2 refers to functions of libt1 and to libm, but still:

% ./ld/ld-new -shared -o libt2.so bla.o --copy-dt-needed-entries -L. -lt1 -z
defs
bla2.o: In function `g':
bla2.c:(.text+0x22): undefined reference to `sin'

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
--- 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/14915] --copy-dt-needed-entries not working

2012-12-04 Thread hjl.tools at gmail dot com
http://sourceware.org/bugzilla/show_bug.cgi?id=14915

--- Comment #9 from H.J. Lu hjl.tools at gmail dot com 2012-12-04 18:21:46 
UTC ---
--copy-dt-needed-entries doesn't work when -shared is used.

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
--- 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/14915] --copy-dt-needed-entries not working when creating DSO

2012-12-04 Thread hjl.tools at gmail dot com
http://sourceware.org/bugzilla/show_bug.cgi?id=14915

H.J. Lu hjl.tools at gmail dot com changed:

   What|Removed |Added

Summary|--copy-dt-needed-entries|--copy-dt-needed-entries
   |not working |not working when creating
   ||DSO

--- Comment #10 from H.J. Lu hjl.tools at gmail dot com 2012-12-04 18:28:14 
UTC ---
[hjl@gnu-6 pr14915]$ cat bla.c
extern void bar (void);
void f (void)
{ 
  bar ();
}
[hjl@gnu-6 pr14915]$ cat bla2.c
extern void f (void);
extern void bar (void);
int
main (void)
{
  f ();
  bar ();
  return 0;
}
[hjl@gnu-6 pr14915]$ cat bar.c
void
bar (void)
{
}
[hjl@gnu-6 pr14915]$ make
gcc -B./ -fPIC   -c -o bla2.o bla2.c
gcc -B./ -fPIC   -c -o bla.o bla.c
gcc -B./ -fPIC   -c -o bar.o bar.c
gcc -B./ -shared -o libbar.so bar.o -Wl,-z,defs
gcc -B./ -shared -o libt1.so bla.o libbar.so -Wl,-z,defs
gcc -B./ -o x bla2.o -Wl,--add-needed -L. -lt1 -Wl,-rpath-link=. -Wl,-z,defs
gcc -B./ -shared -o libt2.so bla2.o -Wl,--add-needed -Wl,-rpath-link=. -L. -lt1
-Wl,-z,defs
bla2.o: In function `main':
bla2.c:(.text+0xa): undefined reference to `bar'
collect2: error: ld returned 1 exit status
make: *** [libt2.so] Error 1
[hjl@gnu-6 pr14915]$

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
--- 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/14915] --copy-dt-needed-entries not working when creating DSO

2012-12-04 Thread hjl.tools at gmail dot com
http://sourceware.org/bugzilla/show_bug.cgi?id=14915

--- Comment #11 from H.J. Lu hjl.tools at gmail dot com 2012-12-04 18:54:53 
UTC ---
This:

diff --git a/ld/emultempl/elf32.em b/ld/emultempl/elf32.em
index 6c84b82..875ac2c 100644
--- a/ld/emultempl/elf32.em
+++ b/ld/emultempl/elf32.em
@@ -1181,8 +1181,6 @@ gld${EMULATION_NAME}_after_open (void)
  special action by the person doing the link.  Note that the
  needed list can actually grow while we are stepping through this
  loop.  */
-  if (!link_info.executable)
-return;
   needed = bfd_elf_get_needed_list (link_info.output_bfd, link_info);
   for (l = needed; l != NULL; l = l-next)
 {

works for me.

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
--- 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/14915] --copy-dt-needed-entries not working when creating DSO

2012-12-04 Thread hjl.tools at gmail dot com
http://sourceware.org/bugzilla/show_bug.cgi?id=14915

H.J. Lu hjl.tools at gmail dot com changed:

   What|Removed |Added

URL||http://sourceware.org/ml/bi
   ||nutils/2012-12/msg00058.htm
   ||l

--- Comment #12 from H.J. Lu hjl.tools at gmail dot com 2012-12-04 19:13:15 
UTC ---
A patch is posted at

http://sourceware.org/ml/binutils/2012-12/msg00058.html

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
--- 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/14915] --copy-dt-needed-entries not working

2012-12-04 Thread matz at suse dot de
http://sourceware.org/bugzilla/show_bug.cgi?id=14915

--- Comment #3 from Michael Matz matz at suse dot de 2012-12-04 14:12:29 UTC 
---
(In reply to comment #2)
 
 gcc -o libt2.so -shared -Wl,--copy-dt-needed-entries -L. -lt1 -v

/usr/lib64/gcc/x86_64-suse-linux/4.5/collect2 --build-id --eh-frame-hdr -m
elf_x86_64 -shared -o libt2.so
/usr/lib64/gcc/x86_64-suse-linux/4.5/../../../../lib64/crti.o
/usr/lib64/gcc/x86_64-suse-linux/4.5/crtbeginS.o -L.
-L/usr/lib64/gcc/x86_64-suse-linux/4.5
-L/usr/lib64/gcc/x86_64-suse-linux/4.5/../../../../lib64 -L/lib/../lib64
-L/usr/lib/../lib64
-L/usr/lib64/gcc/x86_64-suse-linux/4.5/../../../../x86_64-suse-linux/lib
-L/usr/lib64/gcc/x86_64-suse-linux/4.5/../../.. --copy-dt-needed-entries -lt1
-lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s
--no-as-needed /usr/lib64/gcc/x86_64-suse-linux/4.5/crtendS.o
/usr/lib64/gcc/x86_64-suse-linux/4.5/../../../../lib64/crtn.o

So, the --copy-dt-needed-entries argument is at the right place, right before
-lt1.  During my debugging I of course used this cmdline (well, substed
collect2 with the right ld).  Changing various options like removing libs
or the --as-needed doesn't make a difference for the behaviour we expect.

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
--- 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/14918] New: linking with -flto always links in libgcc:s.so

2012-12-04 Thread doko at debian dot org
http://sourceware.org/bugzilla/show_bug.cgi?id=14918

 Bug #: 14918
   Summary: linking with -flto always links in libgcc:s.so
   Product: binutils
   Version: 2.23
Status: NEW
  Severity: normal
  Priority: P2
 Component: ld
AssignedTo: unassig...@sourceware.org
ReportedBy: d...@debian.org
Classification: Unclassified


checked with the 2.23 branch (and gcc-4.7), original report at
http://gcc.gnu.org/PR55592

$ cat foo.c 
int main() { }
$ gcc foo.c  ldd a.out |grep libgcc_s
$ gcc -flto foo.c  ldd a.out |grep libgcc_s
libgcc_s.so.1 = /lib/libgcc_s.so.1 (0x7fb214381000)

works with gold:
$ gcc -B /usr/lib/gold-ld -flto foo.c  ldd a.out |grep libgcc_s
$ 

libgcc is linked as:
-lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s
--no-as-needed

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
--- 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