[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#843826: PIE specs file leads to segfaults on sparc64



Package: dpkg-dev
Version: 1.18.13
Severity: important
User: debian-sparc@lists.debian.org
Usertags: sparc64
X-Debbugs-Cc: debian-sparc@lists.debian.org

Hi Guillem,
Unfortunately, your new specs files lead to segfaults on sparc64:

> $ cat exit.c
> #include <stdlib.h>
>
> int main(int argc, char **argv) {
>     exit(1);
>     return 2;
> }
> $ gcc -specs=/usr/share/dpkg/pie-compile.specs -c exit.c -o exit.o
> $ gcc -specs=/usr/share/dpkg/pie-link.specs exit.o -o exit
> $ ./exit
> Segmentation fault

This is because, while cc1 is given -fPIE, as is not given anything. For
most architectures, this is actually fine, but on SPARC, as *must* be
given -K PIC. When looking at strace, this is the only difference
between gcc -specs=... and gcc -fPIE for compiling. Otherwise, what
happens is the assembler does not emit a PLT call, instead leaving the
call address as an immediate to be filled in by a 30-bit relocation,
which doesn't fit at runtime (with this particular example, libc was
loaded such that exit was at 0xfff80001001624e0) and gets truncated.
Note that the linker invocation itself is fine; it was just given bad
input (although perhaps this is something it could have caught and given
an error message?).

As far as I can tell, changing the cc1_options to self_spec in
(no-)pie-compile.specs should work fine. It certainly fixes the problem
here, and off the top of my head, I can't think of any issues this would
cause.

James


Reply to: