Bug 1343892 - Default hardened ld flags break autoconf/libtool detection of -static flag with gcc
Summary: Default hardened ld flags break autoconf/libtool detection of -static flag wi...
Keywords:
Status: CLOSED EOL
Alias: None
Product: Fedora
Classification: Fedora
Component: redhat-rpm-config
Version: 25
Hardware: Unspecified
OS: Unspecified
unspecified
high
Target Milestone: ---
Assignee: Florian Festi
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
: 1204162 1287743 (view as bug list)
Depends On:
Blocks: harden-failure 1202091 1210424
TreeView+ depends on / blocked
 
Reported: 2016-06-08 09:04 UTC by Daniel Berrangé
Modified: 2017-12-12 10:40 UTC (History)
11 users (show)

Fixed In Version: redhat-rpm-config-54-1.fc26
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2017-12-12 10:40:21 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Bugzilla 1287743 0 unspecified CLOSED -specs=/usr/lib/rpm/redhat/redhat-hardened-ld breaks -static 2021-02-22 00:41:40 UTC

Internal Links: 1287743

Description Daniel Berrangé 2016-06-08 09:04:43 UTC
Description of problem:
Since Fedora was switched to used hardened ld flags by default, autoconf/libtool is no longer able to detect working -static flag with gcc. This prevents libtool from creating statically linked binaries when asked to.

A minimal config that can demonstrate this:

$ cat configure.ac
AC_INIT([demo],[0.1])
AC_CONFIG_SRCDIR([configure.ac])
AM_INIT_AUTOMAKE

LT_INIT

AC_OUTPUT

$ autoreconf -i -f

(ignore the automake error, its harmless for purpose of this demo)


Run configure with no special flags and it'll detect working -static:

$ ./configure  | grep "static flag"
checking if gcc static flag -static works... yes


Run it with the LDFLAGS & CFLAGS that RPM now sets by default:

$ LDFLAGS='-Wl,-z,relro -specs=/usr/lib/rpm/redhat/redhat-hardened-ld' CFLAGS='-O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic'  strace -o c.log -f -ff -s 1000  ./configure   | grep "static flag"
checking if gcc static flag -static works... no

And see it is now broken.

The problem comes from "/usr/lib/rpm/redhat/redhat-hardened-ld" which is adding '-pie' flag to all compiler invocations. This can be confirmed by using strace


c.log.18810:execve("/usr/lib64/ccache/gcc", ["gcc", "-o", "conftest", "-O2", "-g", "-pipe", "-Wall", "-Werror=format-security", "-Wp,-D_FORTIFY_SOURCE=2", "-fexceptions", "-fstack-protector-strong", "--param=ssp-buffer-size=4", "-grecord-gcc-switches", "-specs=/usr/lib/rpm/redhat/redhat-hardened-cc1", "-m64", "-mtune=generic", "-Wl,-z,relro", "-specs=/usr/lib/rpm/redhat/redhat-hardened-ld", "-static", "conftest.c"], [/* 71 vars */]) = 0


this ultimately calls LD with

execve("/usr/bin/ld", ["/usr/bin/ld", "-plugin", "/usr/libexec/gcc/x86_64-redhat-linux/5.3.1/liblto_plugin.so", "-plugin-opt=/usr/libexec/gcc/x86_64-redhat-linux/5.3.1/lto-wrapper", "-plugin-opt=-fresolution=/tmp/ccEZDac7.res", "-plugin-opt=-pass-through=-lgcc", "-plugin-opt=-pass-through=-lgcc_eh", "-plugin-opt=-pass-through=-lc", "--build-id", "--no-add-needed", "--hash-style=gnu", "-m", "elf_x86_64", "-static", "-z", "now", "-pie", "-o", "conftest", "/usr/lib/gcc/x86_64-redhat-linux/5.3.1/../../../../lib64/Scrt1.o", "/usr/lib/gcc/x86_64-redhat-linux/5.3.1/../../../../lib64/crti.o", "/usr/lib/gcc/x86_64-redhat-linux/5.3.1/crtbeginT.o", "-L/usr/lib/gcc/x86_64-redhat-linux/5.3.1", "-L/usr/lib/gcc/x86_64-redhat-linux/5.3.1/../../../../lib64", "-L/lib/../lib64", "-L/usr/lib/../lib64", "-L/usr/lib/gcc/x86_64-redhat-linux/5.3.1/../../..", "-z", "relro", "/tmp/cczoe5fv.o", "--start-group", "-lgcc", "-lgcc_eh", "-lc", "--end-group", "/usr/lib/gcc/x86_64-redhat-linux/5.3.1/crtendS.o", "/usr/lib/gcc/x86_64-redhat-linux/5.3.1/../../../../lib64/crtn.o"], [/* 77 vars */]) = 0


see -static and -pie at the same time

write(2, "/usr/lib/gcc/x86_64-redhat-linux/5.3.1/crtbeginT.o: relocation R_X86_64_32 against `__TMC_END__' can not be used when making a shared object; recompile with -fPIC", 162) = 162




It is not permitted to use -pie and -static at the same time, so this addition causes gcc to report an error, which autoconf interprets as -static being broken.

The hardened ld flags specs need to somehow be changed so that they do not add -pie when -static is being used

Version-Release number of selected component (if applicable):
redhat-rpm-config-36-1.fc23.1.noarch

Comment 1 Pavel Raiskup 2016-06-08 10:07:05 UTC
Seems to be duplicate of 1287743?

Comment 2 Daniel Berrangé 2016-06-08 10:21:28 UTC
I naively tried editting the redhat-hardened-ld file to contain

+ %{!shared:%{!static:%{!r:-pie}}}


but this didn't appear to have any effect - it still passed -pie, even when '-static' was given to gcc. I guess I'm not understanding the specs file semantics correctly

Comment 3 Florian Weimer 2016-06-08 11:03:12 UTC
(In reply to Daniel Berrange from comment #2)
> I naively tried editting the redhat-hardened-ld file to contain
> 
> + %{!shared:%{!static:%{!r:-pie}}}

This works for me in redhat-hardened-ld:

*self_spec:
+ %{!static:%{!shared:%{!r:-pie}}}

It makes sense to add something similar to redhat-hardened-cc1, to avoid -fPIE if -static is specified (because PIC code has a slight overhead).

Comment 4 Florian Weimer 2016-06-08 11:03:40 UTC
(In reply to Pavel Raiskup from comment #1)
> Seems to be duplicate of 1287743?

I agree it's a duplicate.

Comment 5 Daniel Berrangé 2016-06-08 11:07:43 UTC
Hmm, yes, what Florian shows does in fact work for me - I must have typoed when I tried it previously.

Comment 6 Richard W.M. Jones 2016-06-09 14:14:29 UTC
*** Bug 1204162 has been marked as a duplicate of this bug. ***

Comment 7 Daniel Berrangé 2016-07-01 10:57:36 UTC
@ajax: since you seem to have dealt with the hardened build flags previously, could you get the fix Florian describes applied to rawhide & stable branches

Comment 8 Panu Matilainen 2016-11-08 10:50:14 UTC
*** Bug 1287743 has been marked as a duplicate of this bug. ***

Comment 9 Panu Matilainen 2016-11-08 13:26:05 UTC
Fixed as per comment #3 in redhat-rpm-config-54-1.fc26

I suppose affected stable versions need this too but lets see what happens in rawhide first, I can't say I'm familiar with gcc specs so this is all just "well it doesn't seem to break anything so..."

Comment 10 Fedora End Of Life 2016-11-25 09:14:23 UTC
This message is a reminder that Fedora 23 is nearing its end of life.
Approximately 4 (four) weeks from now Fedora will stop maintaining
and issuing updates for Fedora 23. It is Fedora's policy to close all
bug reports from releases that are no longer maintained. At that time
this bug will be closed as EOL if it remains open with a Fedora  'version'
of '23'.

Package Maintainer: If you wish for this bug to remain open because you
plan to fix it in a currently maintained version, simply change the 'version' 
to a later Fedora version.

Thank you for reporting this issue and we are sorry that we were not 
able to fix it before Fedora 23 is end of life. If you would still like 
to see this bug fixed and are able to reproduce it against a later version 
of Fedora, you are encouraged  change the 'version' to a later Fedora 
version prior this bug is closed as described in the policy above.

Although we aim to fix as many bugs as possible during every release's 
lifetime, sometimes those efforts are overtaken by events. Often a 
more recent Fedora release includes newer upstream software that fixes 
bugs or makes them obsolete.

Comment 11 Florian Weimer 2016-12-12 22:24:06 UTC
(In reply to Panu Matilainen from comment #9)
> Fixed as per comment #3 in redhat-rpm-config-54-1.fc26
> 
> I suppose affected stable versions need this too but lets see what happens
> in rawhide first, I can't say I'm familiar with gcc specs so this is all
> just "well it doesn't seem to break anything so..."

Moving to F25 to prevent auto-closing.

Comment 12 Neal Gompa 2017-05-22 12:34:50 UTC
Could we please have this backported to Fedora 24 and Fedora 25? Or at least Fedora 25? This causes me issues with snapd builds as well.

Comment 13 Fedora End Of Life 2017-11-16 19:33:26 UTC
This message is a reminder that Fedora 25 is nearing its end of life.
Approximately 4 (four) weeks from now Fedora will stop maintaining
and issuing updates for Fedora 25. It is Fedora's policy to close all
bug reports from releases that are no longer maintained. At that time
this bug will be closed as EOL if it remains open with a Fedora  'version'
of '25'.

Package Maintainer: If you wish for this bug to remain open because you
plan to fix it in a currently maintained version, simply change the 'version'
to a later Fedora version.

Thank you for reporting this issue and we are sorry that we were not
able to fix it before Fedora 25 is end of life. If you would still like
to see this bug fixed and are able to reproduce it against a later version
of Fedora, you are encouraged  change the 'version' to a later Fedora
version prior this bug is closed as described in the policy above.

Although we aim to fix as many bugs as possible during every release's
lifetime, sometimes those efforts are overtaken by events. Often a
more recent Fedora release includes newer upstream software that fixes
bugs or makes them obsolete.

Comment 14 Fedora End Of Life 2017-12-12 10:40:21 UTC
Fedora 25 changed to end-of-life (EOL) status on 2017-12-12. Fedora 25 is
no longer maintained, which means that it will not receive any further
security or bug fix updates. As a result we are closing this bug.

If you can reproduce this bug against a currently maintained version of
Fedora please feel free to reopen this bug against that version. If you
are unable to reopen this bug, please file a new report against the
current release. If you experience problems, please add a comment to this
bug.

Thank you for reporting this bug and we are sorry it could not be fixed.


Note You need to log in before you can comment on or make changes to this bug.