Bug 788107

Summary: latest binutils seems to introduce problems with -Wl,--gc-sections
Product: [Fedora] Fedora Reporter: Kay Sievers <kay>
Component: binutilsAssignee: Nick Clifton <nickc>
Status: CLOSED RAWHIDE QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: rawhideCC: alekcejk, atu, eparis, jakub, ktmdms, loganjerry, michal, mschmidt, nickc, robatino
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2012-02-09 07:20:49 EST Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Bug Depends On:    
Bug Blocks: 752648    
Attachments:
Description Flags
old
none
new none

Description Kay Sievers 2012-02-07 08:45:17 EST
We encounter failures in binaries using program_invocation_short_name, which
seems to be NULL now for some reason.

Here is a test log of the recent and the older gcc:

# cat argv.c
#define _GNU_SOURCE
#include <errno.h>
#include <stdio.h>

int main(int argc, char *argv[])
{
	printf("%s\n", argv[0]);
	printf("%s\n", program_invocation_name);
	printf("%s\n", program_invocation_short_name);
	return 0;
}


# gcc --version
gcc (GCC) 4.7.0 20120206 (Red Hat 4.7.0-0.11)
Copyright (C) 2012 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

[root@mop stuff]# gcc -Wall -Wl,--gc-sections -O2 -o argv argv.c
[root@mop stuff]# ./argv
./argv
Segmentation fault (core dumped)


# gcc --version
gcc (GCC) 4.7.0 20120123 (Red Hat 4.7.0-0.9)
Copyright (C) 2012 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

[root@mop stuff]# gcc -Wall -Wl,--gc-sections -O2 -o argv argv.c
[root@mop stuff]# ./argv
./argv
./argv
argv
Comment 1 Jakub Jelinek 2012-02-07 08:53:38 EST
Is that with the same version of glibc?  I certainly don't see any differences in compiled code.
Comment 2 Kay Sievers 2012-02-07 09:20:23 EST
Created attachment 559966 [details]
old

The new gcc compile fails running on the new glibc.
The new gcc compile fails running on the old glibc.

The old gcc compile is fine running on the new glibc.
The old gcc compile is fine running on the old glibc.

Attaching the two binaries.

Also note:
The new gcc is on a system, where /lib, /bin, ... are symlinks to /usr.
Maybe that causes some trouble ...
Comment 3 Kay Sievers 2012-02-07 09:20:52 EST
Created attachment 559967 [details]
new
Comment 4 Jakub Jelinek 2012-02-07 09:32:36 EST
That doesn't look like a gcc bug, the generated code is still the same, just the linker behaved differently (didn't apparently create copy relocs).
You can link with -Wl,-M to see what exactly has been linked into it in each case.
The UsrMove is a huge mess and mistake IMHO.
Comment 5 Michal Schmidt 2012-02-07 11:38:16 EST
The testcase works fine when built with binutils-2.22-4.fc17.
It is broken when built with binutils-2.22.52.0.1-2.fc17.
I'm changing nothing else in the system.
Comment 6 Kay Sievers 2012-02-07 11:58:07 EST
This is a test on the same file system, just with the old and the new
binutils installed. The generated binary works only with the old version
of binutils. I can reliably reproduce the behaviour just by switching
between the two binutil versions.

[root@mop stuff]# ld --version
GNU ld version 2.22
Copyright 2011 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License version 3 or (at your option) a later version.
This program has absolutely no warranty.
[root@mop stuff]# 
[root@mop stuff]# 
[root@mop stuff]# gcc -Wall -Wl,--gc-sections -O2 -o argv argv.c
[root@mop stuff]# ./argv
./argv
./argv
argv


[root@mop stuff]# ld --version
GNU ld version 2.22.52.0.1-2.fc17 20120131
Copyright 2012 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License version 3 or (at your option) a later version.
This program has absolutely no warranty.
[root@mop stuff]# 
[root@mop stuff]# gcc -Wall -Wl,--gc-sections -O2 -o argv argv.c
[root@mop stuff]# ./argv
./argv
Segmentation fault (core dumped)
Comment 7 Michal Schmidt 2012-02-07 12:06:09 EST
systemd is affected and we don't know what else is miscompiled.
Proposing as F17 Alpha blocker.
Comment 8 Michal Schmidt 2012-02-07 12:30:13 EST
The specific Alpha release criterion that this breaks is this one:

  21. It must be possible to trigger a system shutdown using standard console
      commands, [...]

'reboot', 'poweroff' do not work because they are symlinks to systemctl, which relies on program_invocation_short_name to know what to do.
'init 0' causes a segfault.
Comment 9 Michal Schmidt 2012-02-07 17:34:23 EST
Andre, this is not specific to x86_64, it affects i686 too.
[Platform: x86_64 -> All]
Comment 10 Kay Sievers 2012-02-07 20:18:54 EST
*** Bug 788300 has been marked as a duplicate of this bug. ***
Comment 11 Kay Sievers 2012-02-07 22:56:02 EST
*** Bug 788304 has been marked as a duplicate of this bug. ***
Comment 12 Michal Schmidt 2012-02-08 10:36:59 EST
This looks related: "Fix -gc-sections related abort":
http://cygwin.com/ml/binutils/2012-02/msg00056.html
Comment 13 Michal Schmidt 2012-02-08 11:14:15 EST
(In reply to comment #12)
> This looks related: "Fix -gc-sections related abort":
> http://cygwin.com/ml/binutils/2012-02/msg00056.html

I made local mockbuild of binutils with the patch. It fixes the bug for me.
Comment 14 Michal Schmidt 2012-02-08 11:29:16 EST
The patch is applied upstream:

http://sourceware.org/git/?p=binutils.git;a=commitdiff;h=f5edd1ac0e79c0356c6a1e2beffcadc0c532be98
Comment 15 Michal Schmidt 2012-02-09 07:20:49 EST
Adam Williamson applied the fix to binutils already and rebuilt systemd with it:

$ koji latest-pkg f17 binutils systemd 
Build                                     Tag                   Built by
----------------------------------------  --------------------  ----------------
binutils-2.22.52.0.1-4.fc17               f17                   adamwill
systemd-41-2.fc17                         f17                   adamwill
Comment 16 Michal Schmidt 2012-02-10 05:34:28 EST
*** Bug 789137 has been marked as a duplicate of this bug. ***
Comment 17 kevin martin 2012-02-10 14:57:36 EST
updating to latest systemd / binutils seems to have fixed that problem.  Now if I can just figure out why my reboot drops to a dracut prompt every time instead of getting all the way to a grub menu....
Comment 18 Michal Schmidt 2012-02-10 19:19:33 EST
(In reply to comment #17)
Your initramfs image may still contain the broken version of systemctl. Regenerate the image with 'dracut -f'.
Comment 19 Michal Jaegermann 2012-02-11 01:23:32 EST
(In reply to comment #18)
> (In reply to comment #17)
>> I can just figure out why my reboot drops to a dracut prompt every time instead
>> of getting all the way to a grub menu....
> Your initramfs image may still contain the broken version of systemctl.

Or you bumped into bug 789119.  There is a patch in comments there if this is the case.