public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* -fpatchable-function-entry: leverage multi-byte NOP on x86
@ 2020-01-04 20:48 Fangrui Song
  2020-01-06  8:15 ` Fangrui Song
  2020-01-06  9:34 ` Martin Liška
  0 siblings, 2 replies; 4+ messages in thread
From: Fangrui Song @ 2020-01-04 20:48 UTC (permalink / raw)
  To: gcc; +Cc: Jan Hubicka

-fpatchable-function-entry is used by Linux kernel arm64/parisc. The
feature works for x86, but does not leverage multi-byte NOP.

% cat a.c
int foo() { return 0; }
% gcc -fpatchable-function-entry=5,0 -c a.c
% objdump -d a.o
...
0000000000000000 <foo>:
    0:   90                      nop
    1:   90                      nop
    2:   90                      nop
    3:   90                      nop
    4:   90                      nop
    5:   55                      push   %rbp
    6:   48 89 e5                mov    %rsp,%rbp
    9:   b8 00 00 00 00          mov    $0x0,%eax
    e:   5d                      pop    %rbp
    f:   c3                      retq


(I am not sure who should be notified. I CCed x86-64-port maintainer
(Jan Hubicka <hubicka@ucw.cz>), as listed on gcc/MAINTAINERS.)

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: -fpatchable-function-entry: leverage multi-byte NOP on x86
  2020-01-04 20:48 -fpatchable-function-entry: leverage multi-byte NOP on x86 Fangrui Song
@ 2020-01-06  8:15 ` Fangrui Song
  2020-01-06  9:34 ` Martin Liška
  1 sibling, 0 replies; 4+ messages in thread
From: Fangrui Song @ 2020-01-06  8:15 UTC (permalink / raw)
  To: gcc; +Cc: Jan Hubicka, Torsten Duwe

On 2020-01-04, Fangrui Song wrote:
>-fpatchable-function-entry is used by Linux kernel arm64/parisc. The
>feature works for x86, but does not leverage multi-byte NOP.
>
>% cat a.c
>int foo() { return 0; }
>% gcc -fpatchable-function-entry=5,0 -c a.c
>% objdump -d a.o
>...
>0000000000000000 <foo>:
>   0:   90                      nop
>   1:   90                      nop
>   2:   90                      nop
>   3:   90                      nop
>   4:   90                      nop
>   5:   55                      push   %rbp
>   6:   48 89 e5                mov    %rsp,%rbp
>   9:   b8 00 00 00 00          mov    $0x0,%eax
>   e:   5d                      pop    %rbp
>   f:   c3                      retq
>
>
>(I am not sure who should be notified. I CCed x86-64-port maintainer
>(Jan Hubicka <hubicka@ucw.cz>), as listed on gcc/MAINTAINERS.)

Archaeology is difficult with the mailing list archive...

CC Torsten as the patch author

https://gcc.gnu.org/ml/gcc-patches/2016-09/msg02257.html [PATCH v2] add -fprolog-pad=N option to c-family
https://gcc.gnu.org/ml/gcc-patches/2017-07/msg00391.html [PATCH v12] add -fpatchable-function-entry=N,M option

Another finding is that

-fpatchable-function-entry=N[,M] is very similar to -mhotpatch=pre-halfwords,post-halfwords on S/390
https://gcc.gnu.org/onlinedocs/gcc/S_002f390-and-zSeries-Options.html

   If the hotpatch option is enabled, a “hot-patching” function prologue
   is generated for all functions in the compilation unit. The funtion
   label is prepended with the given number of two-byte NOP instructions
   (pre-halfwords, maximum 1000000). After the label, 2 * post-halfwords
   bytes are appended, using the largest NOP like instructions the
   architecture allows (maximum 1000000).

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: -fpatchable-function-entry: leverage multi-byte NOP on x86
  2020-01-04 20:48 -fpatchable-function-entry: leverage multi-byte NOP on x86 Fangrui Song
  2020-01-06  8:15 ` Fangrui Song
@ 2020-01-06  9:34 ` Martin Liška
  2020-01-06  9:40   ` Alexander Monakov
  1 sibling, 1 reply; 4+ messages in thread
From: Martin Liška @ 2020-01-06  9:34 UTC (permalink / raw)
  To: Fangrui Song, gcc; +Cc: Jan Hubicka

On 1/4/20 9:48 PM, Fangrui Song wrote:
> -fpatchable-function-entry is used by Linux kernel arm64/parisc. The
> feature works for x86, but does not leverage multi-byte NOP.
> 
> % cat a.c
> int foo() { return 0; }
> % gcc -fpatchable-function-entry=5,0 -c a.c
> % objdump -d a.o
> ...
> 0000000000000000 <foo>:
>     0:   90                      nop
>     1:   90                      nop
>     2:   90                      nop
>     3:   90                      nop
>     4:   90                      nop
>     5:   55                      push   %rbp
>     6:   48 89 e5                mov    %rsp,%rbp
>     9:   b8 00 00 00 00          mov    $0x0,%eax
>     e:   5d                      pop    %rbp
>     f:   c3                      retq
> 
> 
> (I am not sure who should be notified. I CCed x86-64-port maintainer
> (Jan Hubicka <hubicka@ucw.cz>), as listed on gcc/MAINTAINERS.)

Hello.

You are right, we do not leverage multi-byte NOPs. Note that the support depends
on a CPU model (-march) and the similar code is quite complex in binutils:
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=blob;f=gas/config/tc-i386.c;h=d0b8f2624a1885d83d2595474bfd78ae844f48f2;hb=HEAD#l1441

I'm not sure how worthy would it be to implement that?
Thanks,
Martin

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: -fpatchable-function-entry: leverage multi-byte NOP on x86
  2020-01-06  9:34 ` Martin Liška
@ 2020-01-06  9:40   ` Alexander Monakov
  0 siblings, 0 replies; 4+ messages in thread
From: Alexander Monakov @ 2020-01-06  9:40 UTC (permalink / raw)
  To: Martin Liška; +Cc: Fangrui Song, gcc, Jan Hubicka

[-- Attachment #1: Type: text/plain, Size: 595 bytes --]

On Mon, 6 Jan 2020, Martin Liška wrote:

> You are right, we do not leverage multi-byte NOPs. Note that the support
> depends
> on a CPU model (-march) and the similar code is quite complex in binutils:
> https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=blob;f=gas/config/tc-i386.c;h=d0b8f2624a1885d83d2595474bfd78ae844f48f2;hb=HEAD#l1441
> 
> I'm not sure how worthy would it be to implement that?

Huh? Surely the right move would be to ask Binutils to expose that via
a new pseudo-op, like .balign but requesting a specific space rather
than aligning up to a boundary.

Alexander

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-01-06  9:40 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-04 20:48 -fpatchable-function-entry: leverage multi-byte NOP on x86 Fangrui Song
2020-01-06  8:15 ` Fangrui Song
2020-01-06  9:34 ` Martin Liška
2020-01-06  9:40   ` Alexander Monakov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).