diff mbox series

Place jump tables in RELRO only when targets require local relocation to be placed in a read-write section

Message ID b931efa5-d881-c144-57ea-970d2a60f750@linux.ibm.com
State New
Headers show
Series Place jump tables in RELRO only when targets require local relocation to be placed in a read-write section | expand

Commit Message

HAO CHEN GUI Jan. 12, 2022, 7:20 a.m. UTC
Hi,
   This patch sets "relocatable" of jump table to true when targets require local relocation to be placed
in a read-write section - bit 0 is set in reloc_rw_mask. Jump tables are in local relocation, so they
should be placed in RELRO only when both global and local relocation need to be placed in a read-write
section. Bit 1 is always set when bit 0 is set.
   Bootstrapped and tested on powerpc64-linux BE/LE and x86 with no regressions. Is this okay for trunk?
Any recommendations? Thanks a lot.

ChangeLog
2022-01-12 Haochen Gui <guihaoc@linux.ibm.com>

gcc/
	* final.c (jumptable_relocatable): Set relocatable to true when
	targets require local relocation to be placed in a read-write section.


patch.diff

Comments

Jeff Law June 1, 2022, 9:39 p.m. UTC | #1
On 1/12/2022 12:20 AM, HAO CHEN GUI via Gcc-patches wrote:
> Hi,
>     This patch sets "relocatable" of jump table to true when targets require local relocation to be placed
> in a read-write section - bit 0 is set in reloc_rw_mask. Jump tables are in local relocation, so they
> should be placed in RELRO only when both global and local relocation need to be placed in a read-write
> section. Bit 1 is always set when bit 0 is set.
>     Bootstrapped and tested on powerpc64-linux BE/LE and x86 with no regressions. Is this okay for trunk?
> Any recommendations? Thanks a lot.
>
> ChangeLog
> 2022-01-12 Haochen Gui <guihaoc@linux.ibm.com>
>
> gcc/
> 	* final.c (jumptable_relocatable): Set relocatable to true when
> 	targets require local relocation to be placed in a read-write section.
It seems unwise to me to rely on the fact that bit1 is already on when 
bit0 is on.    I realize that's likely just preserving existing 
behavior, but unless there's a compelling reason, I'd rather do:

relocatable = (targetm.asm_out.reloc_rw_mask () & 1) != 0;

Which avoids the assumption that if bit0 is on, then bit 1 will always 
be on.
jeff
diff mbox series

Patch

diff --git a/gcc/final.c b/gcc/final.c
index 296a9382e91..e86223cb96b 100644
--- a/gcc/final.c
+++ b/gcc/final.c
@@ -2141,7 +2141,7 @@  jumptable_relocatable (void)
   if (!CASE_VECTOR_PC_RELATIVE
       && !targetm.asm_out.generate_pic_addr_diff_vec ()
       && targetm_common.have_named_sections)
-     relocatable = targetm.asm_out.reloc_rw_mask ();
+     relocatable = targetm.asm_out.reloc_rw_mask () == 3;

   return relocatable;
 }