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

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



> On 10 Nov 2016, at 05:35, Guillem Jover <guillem@debian.org> wrote:
> 
> Hi!
> 
> On Wed, 2016-11-09 at 23:46:42 +0000, James Clarke wrote:
>> 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
> 
>> 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.
> 
> Thanks for the analysis! I've done several changes to the specs, I've
> tried on a powerpc schroot I had already lying around due to another
> report, if you could test on sparc64 that would be appreciated!
> 
> Attached the changes.

Yep, I can confirm that this works fine (at least pie-*; no-pie-* are
irrelevant given that PIE is not enabled by default).

Thanks,
James

> diff --git i/data/no-pie-compile.specs w/data/no-pie-compile.specs
> index f85b394..2277b97 100644
> --- i/data/no-pie-compile.specs
> +++ w/data/no-pie-compile.specs
> @@ -1,2 +1,2 @@
> -*cc1_options:
> +*self_spec:
>  + %{!r:%{!fpie:%{!fPIE:%{!fpic:%{!fPIC:%{!fno-pic:-fno-PIE}}}}}}
> diff --git i/data/no-pie-link.specs w/data/no-pie-link.specs
> index 15243a0..54db649 100644
> --- i/data/no-pie-link.specs
> +++ w/data/no-pie-link.specs
> @@ -1,2 +1,2 @@
>  *self_spec:
> -+ %{!shared:%{!r:-fno-PIE -no-pie}}
> ++ %{!shared:%{!r:%{!fPIE:%{!pie:-fno-PIE -no-pie}}}}
> diff --git i/data/pie-compile.specs w/data/pie-compile.specs
> index fc54bcb..74d8215 100644
> --- i/data/pie-compile.specs
> +++ w/data/pie-compile.specs
> @@ -1,2 +1,2 @@
> -*cc1_options:
> -+ %{!r:%{!fpie:%{!fPIE:%{!fpic:%{!fPIC:%{!fno-pic:-fPIE}}}}}}
> +*self_spec:
> ++ %{!r:%{!fpie:%{!fPIE:%{!fpic:%{!fPIC:%{!fno-pic:%{!fno-PIE:%{!no-pie:-fPIE}}}}}}}}
> diff --git i/data/pie-link.specs w/data/pie-link.specs
> index a5e0fe4..35d26e1 100644
> --- i/data/pie-link.specs
> +++ w/data/pie-link.specs
> @@ -1,2 +1,2 @@
>  *self_spec:
> -+ %{!shared:%{!r:-fPIE -pie}}
> ++ %{!shared:%{!r:%{!fno-PIE:%{!no-pie:-fPIE -pie}}}}


Reply to: