bug-binutils
[Top][All Lists]
Advanced

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

[Bug ld/29226] gcc -fcf-protection option causes GCC 12 gccgo build to f


From: jason.vas.dias at gmail dot com
Subject: [Bug ld/29226] gcc -fcf-protection option causes GCC 12 gccgo build to fail : "failed to match split-stack sequence"
Date: Sun, 05 Jun 2022 18:49:16 +0000

https://sourceware.org/bugzilla/show_bug.cgi?id=29226

--- Comment #14 from Jason Vas Dias <jason.vas.dias at gmail dot com> ---
OK, CC'ing the RedHat maintainer on this - I do think this
is a bug, and it DOES appear to be fixed by the attached
'binutils-2.38-bug29226.patch', which was successfully
applied by the modified binutils-2.38-14.fc37.src.rpm spec
file , also attached : 'binutils-local.spec', which ran all its
tests successfully with the patch applied, and 'gcc-local.spec',
which finally was able to use the patched binutils 2.38 to
build everything.

Note also that the 'gcc12-libtool-no-rpath.patch' file
is also owned by the gcc SRPM, so if both SRPMs are installed,
one file gets overwritten by the other, which failed the binutils build
after the gcc SRPM is installed - so I renamed the binutils version
'binutils-2.38-libtool-no-rpath.patch' (also attached).

The problem was also that the install scripts get confused by
presence of /usr/bin/ld, and do not install /usr/local/bin/ld,
if /usr/bin/ld exists, so I mistakenly linked 'ld.gold' to ld,
leading me to discover the bug in the first place .
I am fixing that in my binutils-local spec file.

Anyway, GCC now builds either with my patched ld.gold, or with
the proper 'ld' binary produced by the same build.

Please review the attached patch to gold/i386.cc and gold/x86_64.cc -
should they be returning WITHOUT changing the strings, or WITH
changing the strings, IFF we discover that the view+offset points
to an 'rdssp' instruction ?

Best Regards,
Jason Vas Dias, a Software+Embedded Systems (VOIP) Engineer,
West Cork, Ireland
+353 84 874 9040






On 05/06/2022, jason.vas.dias at gmail dot com
<sourceware-bugzilla@sourceware.org> wrote:
> https://sourceware.org/bugzilla/show_bug.cgi?id=29226
>
> Jason Vas Dias <jason.vas.dias at gmail dot com> changed:
>
>            What    |Removed                     |Added
> ----------------------------------------------------------------------------
>            Priority|P2                          |P1
>                  CC|                            |jason.vas.dias at gmail dot
> com
>
> --- Comment #13 from Jason Vas Dias <jason.vas.dias at gmail dot com> ---
> OK, I discovered the SAME test fails completely without either of my
> patches, but BOTH allow the particular GCC build I was trying to succeed -
> I'm going with the last one :
>
> ---BEGIN PATCH
> diff -up gold/i386.cc~ gold/i386.cc
> --- gold/i386.cc~       2022-06-05 02:23:38.826984954 +0100
> +++ gold/i386.cc        2022-06-05 18:16:55.215927752 +0100
> @@ -4190,12 +4190,34 @@ Target_i386::do_calls_non_split(Relobj*
>        elfcpp::Swap_unaligned<32, false>::writeval(pval, val);
>      }
>    else
> -    {
> -      if (!object->has_no_split_stack())
> +    { bool is_rdssp = this->match_view(view, view_size, fnoffset,
> "\xf3\x0f\x1e", 3);
> +      if ((!object->has_no_split_stack()) &&
> +           !is_rdssp
> +         )
> +      {        unsigned char ib[16]={0};
> +       if ( view )
> +       { ib[0] = *(((unsigned char*)view) + fnoffset);
> +         ib[1] = *(((unsigned char*)view) + fnoffset + 1);
> +         ib[2] = *(((unsigned char*)view) + fnoffset + 2);
> +         ib[3] = *(((unsigned char*)view) + fnoffset + 3);
> +       }
>         object->error(_("failed to match split-stack sequence at "
> -                       "section %u offset %0zx"),
> -                     shndx, static_cast<size_t>(fnoffset));
> -      return;
> +                       "section %u offset %0zx #1:%c #2:%c %u
> %2.2hhx.%2.2hhx.%2.2hhx.%2.2hhx"),
> +                     shndx, static_cast<size_t>(fnoffset)
> +                     , (this->match_view(view, view_size, fnoffset,
> +                                         "\x8d\x8c\x24", 3
> +                                         ) ? '1' : '0'
> +                        )
> +                     , (this->match_view(view, view_size, fnoffset,
> +                                         "\x8d\x8c\x94", 3
> +                                         ) ? '1' : '0'
> +                        )
> +                      , static_cast<uint32_t>(fnsize)
> +                     , ib[0], ib[1], ib[2], ib[3]
> +                    );
> +      }
> +      if ( ! is_rdssp )
> +       return;
>      }
>
>    // We have to change the function so that it calls
> diff -up gold/x86_64.cc~ gold/x86_64.cc
> --- gold/x86_64.cc~     2022-01-22 12:14:09.000000000 +0000
> +++ gold/x86_64.cc      2022-06-05 18:13:08.085938171 +0100
> @@ -6044,10 +6044,12 @@ Target_x86_64<size>::do_ehframe_datarel_
>  static const unsigned char cmp_insn_32[] = { 0x64, 0x3b, 0x24, 0x25 };
>  static const unsigned char lea_r10_insn_32[] = { 0x44, 0x8d, 0x94, 0x24 };
>  static const unsigned char lea_r11_insn_32[] = { 0x44, 0x8d, 0x9c, 0x24 };
> +static const unsigned char rdssp_insn_32[]   = { 0xf3, 0x0f, 0x1e, 0xfa };
>
>  static const unsigned char cmp_insn_64[] = { 0x64, 0x48, 0x3b, 0x24, 0x25
> };
>  static const unsigned char lea_r10_insn_64[] = { 0x4c, 0x8d, 0x94, 0x24 };
>  static const unsigned char lea_r11_insn_64[] = { 0x4c, 0x8d, 0x9c, 0x24 };
> +static const unsigned char rdssp_insn_64[]   = { 0xf3, 0x0f, 0x1e, 0xfa };
>
>  template<int size>
>  void
> @@ -6067,7 +6069,9 @@ Target_x86_64<size>::do_calls_non_split(
>        (size == 32 ? lea_r10_insn_32 : lea_r10_insn_64);
>    const char* const lea_r11_insn = reinterpret_cast<const char*>
>        (size == 32 ? lea_r11_insn_32 : lea_r11_insn_64);
> -
> +  const char* const rdssp_insn = reinterpret_cast<const char*>
> +      (size == 32 ? rdssp_insn_32 : rdssp_insn_64);
> +
>    const size_t cmp_insn_len =
>        (size == 32 ? sizeof(cmp_insn_32) : sizeof(cmp_insn_64));
>    const size_t lea_r10_insn_len =
> @@ -6075,6 +6079,7 @@ Target_x86_64<size>::do_calls_non_split(
>    const size_t lea_r11_insn_len =
>        (size == 32 ? sizeof(lea_r11_insn_32) : sizeof(lea_r11_insn_64));
>    const size_t nop_len = (size == 32 ? 7 : 8);
> +  const size_t rdssp_insn_len = 4;
>
>    // The function starts with a comparison of the stack pointer and a
>    // field in the TCB.  This is followed by a jump.
> @@ -6108,12 +6113,34 @@ Target_x86_64<size>::do_calls_non_split(
>        elfcpp::Swap_unaligned<32, false>::writeval(pval, val);
>      }
>    else
> -    {
> -      if (!object->has_no_split_stack())
> +    { bool is_rdssp = this->match_view( view, view_size, fnoffset,
> rdssp_insn,
> rdssp_insn_len);
> +      if ( (!object->has_no_split_stack())
> +         && !is_rdssp
> +         )
> +      {        unsigned char ib[16]={0};
> +       if ( view )
> +       { ib[0] = *(((unsigned char*)view) + fnoffset);
> +         ib[1] = *(((unsigned char*)view) + fnoffset + 1);
> +         ib[2] = *(((unsigned char*)view) + fnoffset + 2);
> +         ib[3] = *(((unsigned char*)view) + fnoffset + 3);
> +       }
>         object->error(_("failed to match split-stack sequence at "
> -                       "section %u offset %0zx"),
> -                     shndx, static_cast<size_t>(fnoffset));
> -      return;
> +                       "section %u offset %0zx r10:%c r11:%c %u
> %2.2hhx.%2.2hhx.%2.2hhx.%2.2hhx"),
> +                     shndx, static_cast<size_t>(fnoffset)
> +                     , (this->match_view(view, view_size, fnoffset,
> +                                         lea_r10_insn, lea_r10_insn_len
> +                                         ) ? '1' : '0'
> +                        )
> +                     , (this->match_view(view, view_size, fnoffset,
> +                                         lea_r11_insn, lea_r11_insn_len
> +                                         ) ? '1' : '0'
> +                        )
> +                      , static_cast<uint32_t>(fnsize)
> +                      , ib[0], ib[1], ib[2], ib[3]
> +                    );
> +      }
> +      if( !is_rdssp )
> +       return;
>      }
>
>    // We have to change the function so that it calls
> ---END PATCH
>
> --
> You are receiving this mail because:
> You are on the CC list for the bug.
> You reported the bug.

-- 
You are receiving this mail because:
You are on the CC list for the bug.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]