Bug 2462 - -Wl,-s always output unused bytes at the end
Summary: -Wl,-s always output unused bytes at the end
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: binutils (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-03-14 21:00 UTC by Frédéric L. W. Meunier
Modified: 2006-03-17 23:30 UTC (History)
3 users (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Last reconfirmed:


Attachments
Small binaries showing the difference (37.86 KB, application/octet-stream)
2006-03-14 21:07 UTC, Frédéric L. W. Meunier
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Frédéric L. W. Meunier 2006-03-14 21:00:52 UTC
As H. J. Lu told me, I'm opening a bug report.

I'm using Slackware -current and some time ago decided to upgrade to 2.16.91.0.6
because it ships with 2.15.92.0.2.

What happens is that, whenever I compile something with -Wl,-s added in LDFLAGS
or another place in the Makefile, so that it strips the binaries/libraries and I
don't have to use strip(1), the final sizes are different. With the old version,
there's nothing left to strip if I use -Wl,-s. With the new version, if I use
strip(1), it strips something, and the final sizes are then the same and
md5sum(1) matches. This is with GCC 3.4.6 (also was with 3.4.5) on x86.

I have some small binaries from udev 0.87 if someone wants to take a look. I'm
very clueless about it and what may be causing it.
Comment 1 Frédéric L. W. Meunier 2006-03-14 21:07:36 UTC
Created attachment 919 [details]
Small binaries showing the difference

I don't know if this is of any help.

These are udevstart binaries from udev 087. udevstart.old is compiled with the
old binutils and udevstart.new with the new. Both used the same udev sources
and Makefile, which had

#STRIP = $(CROSS_COMPILE)strip
#STRIPCMD = $(STRIP) -s

commented

and -Wl,-s added to LDFLAGS = -Wl,-warn-common
Comment 2 Frédéric L. W. Meunier 2006-03-14 21:21:44 UTC
BTW, I'm not sure about what I should put in Host, Target, and Build. GCC is
from Slackware, so is i486-slackware-linux. I compiled binutils for my host, so
it picked i686-pc-linux-gnu.
Comment 3 H.J. Lu 2006-03-16 19:51:51 UTC
We need a testcase to look into it. An executable doesn't help here.
Comment 4 Frédéric L. W. Meunier 2006-03-16 23:08:03 UTC
As I wrote, I'm very clueless about it, so I don't know how to write a testcase. 

Would that help if I upload my binutils somewhere ? I could also give ssh access
to whoever wants to take a look.
Comment 5 H.J. Lu 2006-03-16 23:16:23 UTC
Please provide a simple source code with instructions to reproduce the problem
you have described.
Comment 6 Frédéric L. W. Meunier 2006-03-16 23:43:34 UTC
I can reproduce it with anything, even a single

#include <stdio.h>
void main(void) {
printf("Hello world \n");
}

New binutils:

$ gcc -o foo -Wl,-s foo.c
foo.c: In function `main':
foo.c:2: warning: return type of 'main' is not `int'
$ ls -l foo
-rwxr-xr-x 1 root root 3313 2006-03-16 20:38 foo
$ strip foo
$ ls -l foo
-rwxr-xr-x 1 root root 2896 2006-03-16 20:39 foo

Old binutils:

$ gcc -o foo -Wl,-s foo.c
foo.c: In function `main':
foo.c:2: warning: return type of 'main' is not `int'
$ ls -l foo
-rwxr-xr-x 1 root root 2896 2006-03-16 23:40 foo
$ strip foo
-rwxr-xr-x 1 root root 2896 2006-03-16 23:40 foo
Comment 7 H.J. Lu 2006-03-17 06:33:54 UTC
Paul, it looks like your patch:

http://sourceware.org/ml/binutils/2005-05/msg00170.html

puts a some random bytes at the end of output. Can you look into it? Thanks.
Comment 8 H.J. Lu 2006-03-17 06:44:39 UTC
I also saw this on Linux/x86-64.
Comment 9 H.J. Lu 2006-03-17 06:48:08 UTC
The problem is

diff -x 'config*' -x CVS -upr ../binutils-last/src/bfd/elfxx-target.h src/bfd/el
fxx-target.h
--- ../binutils-last/src/bfd/elfxx-target.h     2006-03-16 22:17:02.000000000 -0
800
+++ src/bfd/elfxx-target.h      2006-03-16 22:29:42.000000000 -0800
@@ -416,7 +416,7 @@
 #define elf_backend_merge_symbol_attribute     NULL
 #endif
 #ifndef elf_backend_emit_relocs
-#define elf_backend_emit_relocs                        NULL
+#define elf_backend_emit_relocs                        _bfd_elf_link_output_rel
ocs
 #endif
 #ifndef elf_backend_count_relocs
 #define elf_backend_count_relocs               NULL

Now all targets will call _bfd_elf_link_output_relocs which generates some
random bytes at the end.
Comment 10 H.J. Lu 2006-03-17 14:03:51 UTC
A patch is posted at

http://sourceware.org/ml/binutils/2006-03/msg00239.html
Comment 11 H.J. Lu 2006-03-17 23:07:34 UTC
Fixed by

http://sourceware.org/ml/binutils/2006-03/msg00251.html
Comment 12 Frédéric L. W. Meunier 2006-03-17 23:30:40 UTC
Thanks, I just tested it.