[PATCH] S/390: Function hotpatching option and function attribute

Dominik Vogt vogt@linux.vnet.ibm.com
Wed Dec 11 09:10:00 GMT 2013


Backporting this patch to 4.8, 4.4 and 4.1 brougth some issues to
light.  The new version of the patch optimizes some code and
warnings and adapts the test cases so that they run without
modifications on 4.8 and earlier.

Original message:
On Thu, Dec 05, 2013 at 09:06:31AM +0100, Dominik Vogt wrote:
> Andreas Krebbel an I have ported the function hotpatching feature
> from i386 (aka ms_hook_prologue attribute) to S/390.  Andreas has
> already internally approved the attached patch and will commit it
> soon (for legal reasons he has to do that himself).
> 
> The attached patch introduces command line options as well as a
> function attribute to control the function hotpatching prologue:
> 
>   -m[no-]hotpatch
>     Enable or disable hotpatching prologues for all functions in
>     the compilation unit (with the default prologue size).
> 
>   -mhotpatch=<n>
>     Same as -mhotpatch, but the size of the prologue is <n+2>
>     halfwords (i.e. the trampoline area is <n> halwords).
> 
>   __attribute__ ((hotpatch)) and 
>   __attribute__ ((hotpatch(<n>)))
>     Work like the option, but only for the specific function.  If
>     the attribute and one of the options is given, the attribute
>     always wins.
> 
> <n> above is limited to values 0 through 1000000 (default 12).
> Functions that are explicitly inline cannot be hotpatched, and
> hotpatched functions are never implicitly inlined.
> 
> The layout of a hotpatchable function prologue is
> 
>     nopr %r7 (<n> times, 2 bytes each, aka "trampoline area")
>   function_label:
>     nop 0 (four bytes)
> 
> The function label alignment is changed to eight bytes to make
> sure that the eight bytes directly in front of the label reside
> in the same cacheline.
> 
> To hotpatch a function, the program first writes the address of
> the new version of the hotpatched function to the eight bytes
> before the label (four bytes on 32-bit), then writes code to read
> that address and to jump to it into the trampoline area and then
> replaces the nop behind the label with a relative backwards jump
> into the trampoline area.  (Some maintenance of the Icache is
> necessary in this procedure.)
> 
> If the program can make sure that the patched functions are always
> close enough to the original in the memory map, the trampoline
> area can be omitted (<n> = 0), and a short relative jump to the
> patched function can be written over the four byte nop.
> 
> The patch includes a number of test cases that all run without
> trouble here.  The tests validate the syntax of the options an the
> attribute and check for the correct number of nops.  I have
> verified the correct layout of the trampoline manually (i.e. the
> correct placement of the nops).

Ciao

Dominik ^_^  ^_^

-- 

Dominik Vogt
IBM Germany
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-S-390-Function-hotpatching-option-and-function-attri.patch
Type: text/x-diff
Size: 29732 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20131211/d32fc59e/attachment.bin>
-------------- next part --------------
2013-12-11  Dominik Vogt  <vogt@linux.vnet.ibm.com>
	    Andreas Krebbel  <Andreas.Krebbel@de.ibm.com>

	* config/s390/s390.c (s390_hotpatch_trampoline_halfwords_default): New
	constant
	(s390_hotpatch_trampoline_halfwords_max): New constant
	(s390_hotpatch_trampoline_halfwords): New static variable
	(get_hotpatch_attribute): New function
	(s390_handle_hotpatch_attribute): New function
	(s390_attribute_table): New target specific attribute table to implement
	the hotpatch attribute
	(s390_option_override): Parse hotpatch options
	(s390_function_num_hotpatch_trampoline_halfwords): New function
	(s390_can_inline_p): Implement target hook to
	suppress hotpatching for explicitly inlined functions
	(s390_asm_output_function_label): Generate hotpatch prologue
	(TARGET_ATTRIBUTE_TABLE): Define to implement target attribute table
	(TARGET_CAN_INLINE_P): Define to implement target hook
	* config/s390/s390.opt (mhotpatch): New options -mhotpatch, -mhotpatch=
	* config/s390/s390-protos.h (s390_asm_output_function_label): Add
	prototype
	* config/s390/s390.h (ASM_OUTPUT_FUNCTION_LABEL): Target specific
	function label generation for hotpatching
	(FUNCTION_BOUNDARY): Align functions to eight bytes
	* doc/extend.texi: Document hotpatch attribute
	* doc/invoke.texi: Document -mhotpatch option

2013-12-11  Dominik Vogt  <vogt@linux.vnet.ibm.com>
	    Andreas Krebbel  <Andreas.Krebbel@de.ibm.com>

	* gcc/testsuite/gcc.target/s390/hotpatch-1.c: New test
	* gcc/testsuite/gcc.target/s390/hotpatch-2.c: New test
	* gcc/testsuite/gcc.target/s390/hotpatch-3.c: New test
	* gcc/testsuite/gcc.target/s390/hotpatch-4.c: New test
	* gcc/testsuite/gcc.target/s390/hotpatch-5.c: New test
	* gcc/testsuite/gcc.target/s390/hotpatch-6.c: New test
	* gcc/testsuite/gcc.target/s390/hotpatch-7.c: New test
	* gcc/testsuite/gcc.target/s390/hotpatch-8.c: New test
	* gcc/testsuite/gcc.target/s390/hotpatch-9.c: New test
	* gcc/testsuite/gcc.target/s390/hotpatch-10.c: New test
	* gcc/testsuite/gcc.target/s390/hotpatch-11.c: New test
	* gcc/testsuite/gcc.target/s390/hotpatch-12.c: New test
	* gcc/testsuite/gcc.target/s390/hotpatch-compile-1.c: New test
	* gcc/testsuite/gcc.target/s390/hotpatch-compile-2.c: New test
	* gcc/testsuite/gcc.target/s390/hotpatch-compile-3.c: New test
	* gcc/testsuite/gcc.target/s390/hotpatch-compile-4.c: New test
	* gcc/testsuite/gcc.target/s390/hotpatch-compile-5.c: New test
	* gcc/testsuite/gcc.target/s390/hotpatch-compile-6.c: New test
	* gcc/testsuite/gcc.target/s390/hotpatch-compile-7.c: New test


More information about the Gcc-patches mailing list