Bug 57409 - implement PIE support or reject -pie option
Summary: implement PIE support or reject -pie option
Status: REOPENED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 4.8.0
: P3 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-05-25 06:10 UTC by Christian Jullien
Modified: 2013-05-27 08:39 UTC (History)
1 user (show)

See Also:
Host:
Target: sparc-sun-solaris2.10
Build:
Known to work:
Known to fail:
Last reconfirmed: 2013-05-25 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Christian Jullien 2013-05-25 06:10:24 UTC
Trying to build recent sudo versions which now uses PIE I got core dumps or does memory failures since gcc 4.7. It appears the culprit is PIE.

Using 4.8 and all recent gnu tools compiled with:
../configure \
    --with-gnu-as    --with-as=/usr/local/bin/as \
    --with-gnu-ld    --with-ld=/usr/local/bin/ld \
    --enable-shared                              \
    --disable-nls                                \
    --enable-languages=c,c++

on good old UltraSparc 10 having 512Mb of mem gives me the same error using this simple test:

#include <stdlib.h>
#include <stdio.h>
int
main()
{
  return printf("malloc %p\n", malloc(100));
}

$ gcc -o foo -fPIE -pie foo.c && ./foo
malloc 0
$ gcc -o foo foo.c && ./foo
malloc 20918

here is the result of -v on
$ gcc -o foo -v -fPIE -pie foo.c
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/sparc-sun-solaris2.10/4.8.0/lto-wrapper
Target: sparc-sun-solaris2.10
Configured with: ../configure --with-gnu-as --with-as=/usr/local/bin/as --with-gnu-ld --with-ld=/usr/local/bin/ld --enable-shared --disable-nls --enable-languages=c,c++ Thread model: posix gcc version 4.8.0 (GCC) COLLECT_GCC_OPTIONS='-o' 'foo' '-v' '-fPIE' '-pie' '-mcpu=v9'
 /usr/local/libexec/gcc/sparc-sun-solaris2.10/4.8.0/cc1 -quiet -v -D__sparcv8 foo.c -quiet -dumpbase foo.c -mcpu=v9 -auxbase foo -version -fPIE -o /var/tmp//ccqprUCd.s GNU C (GCC) version 4.8.0 (sparc-sun-solaris2.10)
        compiled by GNU C version 4.8.0, GMP version 5.1.1, MPFR version 3.1.2, MPC version 1.0.1
warning: GMP header version 5.1.1 differs from library version 5.1.2.
GGC heuristics: --param ggc-min-expand=65 --param ggc-min-heapsize=65536 ignoring nonexistent directory "/usr/local/lib/gcc/sparc-sun-solaris2.10/4.8.0/../../../../sparc-sun-solaris2.10/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/lib/gcc/sparc-sun-solaris2.10/4.8.0/include
 /usr/local/include
 /usr/local/lib/gcc/sparc-sun-solaris2.10/4.8.0/include-fixed
 /usr/include
End of search list.
GNU C (GCC) version 4.8.0 (sparc-sun-solaris2.10)
        compiled by GNU C version 4.8.0, GMP version 5.1.1, MPFR version 3.1.2, MPC version 1.0.1
warning: GMP header version 5.1.1 differs from library version 5.1.2.
GGC heuristics: --param ggc-min-expand=65 --param ggc-min-heapsize=65536 Compiler executable checksum: e14fe10990fa31427ec25922a737dd32 COLLECT_GCC_OPTIONS='-o' 'foo' '-v' '-fPIE' '-pie' '-mcpu=v9'
 /usr/local/bin/as -v -V -Qy -s -xarch=v8plus -32 -K PIC -o /var/tmp//cc8jtkmf.o /var/tmp//ccqprUCd.s GNU assembler version 2.23.2 (sparc-sun-solaris2.10) using BFD version (GNU Binutils) 2.23.2 COMPILER_PATH=/usr/local/libexec/gcc/sparc-sun-solaris2.10/4.8.0/:/usr/local/libexec/gcc/sparc-sun-solaris2.10/4.8.0/:/usr/local/libexec/gcc/sparc-sun-solaris2.10/:/usr/local/lib/gcc/sparc-sun-solaris2.10/4.8.0/:/usr/local/lib/gcc/sparc-sun-solaris2.10/:/usr/local/lib/gcc/sparc-sun-solaris2.10/4.8.0/../../../../sparc-sun-solaris2.10/bin/:/usr/ccs/bin/
LIBRARY_PATH=/usr/local/lib/gcc/sparc-sun-solaris2.10/4.8.0/:/usr/local/lib/gcc/sparc-sun-solaris2.10/4.8.0/../../../../sparc-sun-solaris2.10/lib/:/usr/ccs/lib/:/usr/local/lib/gcc/sparc-sun-solaris2.10/4.8.0/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-o' 'foo' '-v' '-fPIE' '-pie' '-mcpu=v9'
 /usr/local/libexec/gcc/sparc-sun-solaris2.10/4.8.0/collect2 -V -m elf32_sparc_sol2 -Y P,/usr/ccs/lib:/lib:/usr/lib -Qy -pie -o foo /usr/local/lib/gcc/sparc-sun-solaris2.10/4.8.0/crt1.o /usr/lib/crti.o /usr/ccs/lib/values-Xa.o /usr/local/lib/gcc/sparc-sun-solaris2.10/4.8.0/crtbegin.o -L/usr/local/lib/gcc/sparc-sun-solaris2.10/4.8.0 -L/usr/local/lib/gcc/sparc-sun-solaris2.10/4.8.0/../../../../sparc-sun-solaris2.10/lib -L/usr/ccs/lib -L/usr/local/lib/gcc/sparc-sun-solaris2.10/4.8.0/../../.. /var/tmp//cc8jtkmf.o -lgcc -lgcc_eh -lc -lgcc -lgcc_eh -lc /usr/local/lib/gcc/sparc-sun-solaris2.10/4.8.0/crtend.o /usr/lib/crtn.o GNU ld (GNU Binutils) 2.23.2
  Supported emulations:
   elf32_sparc_sol2
   elf32_sparc
   elf64_sparc_sol2
   elf64_sparc

Is there is something wrong on the way I compile gcc on solaris sparc? Except for PIE, gcc 4.8 compiled ROOTB many big GNU and non-GNU projects without error.

Tia for the time you may spend on this report.

Christian
Comment 1 Eric Botcazou 2013-05-25 06:42:07 UTC
PIE isn't supported on Solaris, at least on older versions.
Comment 2 Christian Jullien 2013-05-25 07:06:41 UTC
Thanks for your quick reply yet it is not totally satisfactory.

1) if gcc does not support pie on solaris 10 sparc (I can accept that), gcc toolchain should detect this and protest (from ./configure) if PIE can't be used on a given platform. Using PIE flag should make gcc return an error "PIE no supported on this platform"

2) at the same time, Todd Miller (sudo developer) was able to use PIE on a very similar machine (see http://www.sudo.ws/pipermail/sudo-users/2013-May/005195.html) using gcc 4.8. It looks there is a way to make gcc work with PIE. This is configure duty to find this way and/or advice that a configure option is missing in order to support PIE.

3) I also may have an incorrect ./configure options I'll be glad to fix and test

Christian
Comment 3 Eric Botcazou 2013-05-25 07:56:59 UTC
> 1) if gcc does not support pie on solaris 10 sparc (I can accept that), gcc
> toolchain should detect this and protest (from ./configure) if PIE can't be
> used on a given platform. Using PIE flag should make gcc return an error
> "PIE no supported on this platform"

Maybe, but the manual is very clear:

`-pie'
     Produce a position independent executable on targets that support
     it.  For predictable results, you must also specify the same set
     of options used for compilation (`-fpie', `-fPIE', or model
     suboptions) when you specify this linker option.

so one could argue that it's up to the user to check that it works on a given platform.

> 2) at the same time, Todd Miller (sudo developer) was able to use PIE on a
> very similar machine (see
> http://www.sudo.ws/pipermail/sudo-users/2013-May/005195.html) using gcc 4.8.
> It looks there is a way to make gcc work with PIE.

He's using the Sun tools and you're using the GNU binutils, so this may primarily be a binutils issue.  Does it work with the Sun tools on your machine?
Comment 4 Eric Botcazou 2013-05-25 08:31:32 UTC
OK, in fact -pie is simply a no-op with the Sun linker.
Comment 5 Christian Jullien 2013-05-25 08:51:27 UTC
Thanks,
now all is clear to me.

I see different possible solutions:

1) gcc toolchain detects that it is using a linker that does not support pie and issue a error "unsupported flag" when we try to use pie

2) enter a binutils bug report asking to do a nop when it receives pie flags for a platform that does not support it (as does solaris standard ld)

3) Ask Todd to check if pie is working from configure script.

Of course 3) will only fix sudo and no other packages trying to use pie.

What do you prefer?
Comment 6 Eric Botcazou 2013-05-25 10:28:57 UTC
> I see different possible solutions:
> 
> 1) gcc toolchain detects that it is using a linker that does not support pie
> and issue a error "unsupported flag" when we try to use pie
> 
> 2) enter a binutils bug report asking to do a nop when it receives pie flags
> for a platform that does not support it (as does solaris standard ld)
> 
> 3) Ask Todd to check if pie is working from configure script.
> 
> Of course 3) will only fix sudo and no other packages trying to use pie.
> 
> What do you prefer?

No strong opinion, but PIE is essentially a Linux thing so it shouldn't be enabled by default everywhere (unless you really know what you are doing).

The failure mode could admittedly be improved though, so let's record that.
Comment 7 Christian Jullien 2013-05-25 10:59:51 UTC
Thanks for your time on this issue Eric.

My preference goes to PIE failure detection when gcc is bootstrapped and gcc complains when -pie is set on an unsupported platform.

You can do whatever you want with this bug report, unless you ask me a question, I will no more comment on this issue. All is clear to me.

Christian