public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH v2] Fix __patchable_function_entries section flags
@ 2019-04-11 18:09 Joao Moreira
  2019-04-12 16:23 ` Jeff Law
  0 siblings, 1 reply; 4+ messages in thread
From: Joao Moreira @ 2019-04-11 18:09 UTC (permalink / raw)
  To: gcc-patches; +Cc: jmoreira, matz

When -fpatchable-relocation-entry is used, gcc places nops on the
prologue of each compiled function and creates a section named
__patchable_function_entries which holds relocation entries for the
positions in which the nops were placed. As is, gcc creates this
section without the proper section flags, causing crashes in the
compiled program during its load.

Given the above, fix the problem by creating the section with the
SECTION_WRITE and SECTION_RELRO flags.

The problem was noticed while compiling glibc with
-fpatchable-function-entry compiler flag. After applying the patch,
this issue was solved.

This was also tested on x86-64 arch without visible problems under
the gcc standard tests.

2019-04-10  Joao Moreira  <jmoreira@suse.de>

	* targhooks.c (default_print_patchable_function_entry): Emit
	__patchable_function_entries section with writable flags to allow
	relocation resolution.

Signed-off-by: Joao Moreira <jmoreira@suse.de>
---
 gcc/targhooks.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/targhooks.c b/gcc/targhooks.c
index 318f7e9784a..e6f54ddf41b 100644
--- a/gcc/targhooks.c
+++ b/gcc/targhooks.c
@@ -1814,7 +1814,7 @@ default_print_patchable_function_entry (FILE *file,
       ASM_GENERATE_INTERNAL_LABEL (buf, "LPFE", patch_area_number);
 
       switch_to_section (get_section ("__patchable_function_entries",
-				      0, NULL));
+				      SECTION_WRITE | SECTION_RELRO, NULL));
       fputs (asm_op, file);
       assemble_name_raw (file, buf);
       fputc ('\n', file);
-- 
2.16.4

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

* Re: [PATCH v2] Fix __patchable_function_entries section flags
  2019-04-11 18:09 [PATCH v2] Fix __patchable_function_entries section flags Joao Moreira
@ 2019-04-12 16:23 ` Jeff Law
  2019-04-15 16:43   ` Joao Moreira
  0 siblings, 1 reply; 4+ messages in thread
From: Jeff Law @ 2019-04-12 16:23 UTC (permalink / raw)
  To: Joao Moreira, gcc-patches; +Cc: matz

On 4/11/19 11:18 AM, Joao Moreira wrote:
> When -fpatchable-relocation-entry is used, gcc places nops on the
> prologue of each compiled function and creates a section named
> __patchable_function_entries which holds relocation entries for the
> positions in which the nops were placed. As is, gcc creates this
> section without the proper section flags, causing crashes in the
> compiled program during its load.
> 
> Given the above, fix the problem by creating the section with the
> SECTION_WRITE and SECTION_RELRO flags.
> 
> The problem was noticed while compiling glibc with
> -fpatchable-function-entry compiler flag. After applying the patch,
> this issue was solved.
> 
> This was also tested on x86-64 arch without visible problems under
> the gcc standard tests.
> 
> 2019-04-10  Joao Moreira  <jmoreira@suse.de>
> 
> 	* targhooks.c (default_print_patchable_function_entry): Emit
> 	__patchable_function_entries section with writable flags to allow
> 	relocation resolution.
OK.  Do you have write access to the GCC repo?

jeff
> 

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

* Re: [PATCH v2] Fix __patchable_function_entries section flags
  2019-04-12 16:23 ` Jeff Law
@ 2019-04-15 16:43   ` Joao Moreira
  2019-04-17 18:28     ` Jeff Law
  0 siblings, 1 reply; 4+ messages in thread
From: Joao Moreira @ 2019-04-15 16:43 UTC (permalink / raw)
  To: Jeff Law, gcc-patches; +Cc: matz



On 4/12/19 1:19 PM, Jeff Law wrote:
> On 4/11/19 11:18 AM, Joao Moreira wrote:
>> When -fpatchable-relocation-entry is used, gcc places nops on the
>> prologue of each compiled function and creates a section named
>> __patchable_function_entries which holds relocation entries for the
>> positions in which the nops were placed. As is, gcc creates this
>> section without the proper section flags, causing crashes in the
>> compiled program during its load.
>>
>> Given the above, fix the problem by creating the section with the
>> SECTION_WRITE and SECTION_RELRO flags.
>>
>> The problem was noticed while compiling glibc with
>> -fpatchable-function-entry compiler flag. After applying the patch,
>> this issue was solved.
>>
>> This was also tested on x86-64 arch without visible problems under
>> the gcc standard tests.
>>
>> 2019-04-10  Joao Moreira  <jmoreira@suse.de>
>>
>> 	* targhooks.c (default_print_patchable_function_entry): Emit
>> 	__patchable_function_entries section with writable flags to allow
>> 	relocation resolution.
> OK.  Do you have write access to the GCC repo?
> 
No.

Tks,
Joao.

> jeff
>>

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

* Re: [PATCH v2] Fix __patchable_function_entries section flags
  2019-04-15 16:43   ` Joao Moreira
@ 2019-04-17 18:28     ` Jeff Law
  0 siblings, 0 replies; 4+ messages in thread
From: Jeff Law @ 2019-04-17 18:28 UTC (permalink / raw)
  To: Joao Moreira, gcc-patches; +Cc: matz

On 4/15/19 10:31 AM, Joao Moreira wrote:
> 
> 
> On 4/12/19 1:19 PM, Jeff Law wrote:
>> On 4/11/19 11:18 AM, Joao Moreira wrote:
>>> When -fpatchable-relocation-entry is used, gcc places nops on the
>>> prologue of each compiled function and creates a section named
>>> __patchable_function_entries which holds relocation entries for the
>>> positions in which the nops were placed. As is, gcc creates this
>>> section without the proper section flags, causing crashes in the
>>> compiled program during its load.
>>>
>>> Given the above, fix the problem by creating the section with the
>>> SECTION_WRITE and SECTION_RELRO flags.
>>>
>>> The problem was noticed while compiling glibc with
>>> -fpatchable-function-entry compiler flag. After applying the patch,
>>> this issue was solved.
>>>
>>> This was also tested on x86-64 arch without visible problems under
>>> the gcc standard tests.
>>>
>>> 2019-04-10  Joao Moreira  <jmoreira@suse.de>
>>>
>>>     * targhooks.c (default_print_patchable_function_entry): Emit
>>>     __patchable_function_entries section with writable flags to allow
>>>     relocation resolution.
>> OK.  Do you have write access to the GCC repo?
>>
> No.
I went ahead and installed on the trunk for you.  Are you going to be
working on GCC regularly?  If so it might make sense to go ahead and get
that access setup.

Jeff

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

end of thread, other threads:[~2019-04-17 18:25 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-11 18:09 [PATCH v2] Fix __patchable_function_entries section flags Joao Moreira
2019-04-12 16:23 ` Jeff Law
2019-04-15 16:43   ` Joao Moreira
2019-04-17 18:28     ` Jeff Law

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).