Segher, Please ignore the attachments in my last email. My editor cached the old things. Now they should be correct. Sorry for that. On 17/8/2020 上午 10:20, HAO CHEN GUI wrote: > Segher, > > Seems I sent the wrong diff file. Now the attachments should be > correct ones. Sorry for that. > > For the reloc,  my understanding is the jump table needs to be > relocated if it's a non-relative jump table and PIC flag is set at the > same time. > > //stmt.c > >  if (CASE_VECTOR_PC_RELATIVE >           || (flag_pic && targetm.asm_out.generate_pic_addr_diff_vec ())) >     emit_jump_table_data (gen_rtx_ADDR_DIFF_VEC (CASE_VECTOR_MODE, >                                                  gen_rtx_LABEL_REF > (Pmode, > table_label), >                                                  gen_rtvec_v (ncases, > labelvec), >                                                  const0_rtx, > const0_rtx)); >   else >     emit_jump_table_data (gen_rtx_ADDR_VEC (CASE_VECTOR_MODE, >                                             gen_rtvec_v (ncases, > labelvec))); > > According to the slice of code in stmt.c,  the non-relative jump table > is created with PIC flag set when CASE_VECTOR_PC_RELATIVE is false, > flag_pic is true and targetm.asm_out.generate_pic_addr_diff_vec is > false. So I set the reloc to > > reloc = (! CASE_VECTOR_PC_RELATIVE && flag_pic && >            ! targetm.asm_out.generate_pic_addr_diff_vec ()) ? 1 : 0; > > The funcation_rodata_section is not only for jump tables. It's no > relro in other cases. I am not sure if it's suitable to put selecting > relro section in it. Of course, I can create a separate function for > section selection of jump table and send its output to > funcation_rodata_section. > > Please advice. Thanks a lot. > > > On 15/8/2020 上午 7:39, Segher Boessenkool wrote: > >> Hi! >> >> On Fri, Aug 14, 2020 at 03:20:03PM +0800, HAO CHEN GUI wrote: >>> section * >>> select_jump_table_section (tree decl) >>> { >>>    int reloc; >>>    bool section_reloc; >>> >>>    reloc = (! CASE_VECTOR_PC_RELATIVE && flag_pic && >>>             ! targetm.asm_out.generate_pic_addr_diff_vec ()) ? 1 : >>> 0; >> (Modern style is no space after "!", and your mailer wrapped the code). >> >>>    section_reloc = (reloc & targetm.asm_out.reloc_rw_mask ()); >> (No space after & either). >> >>>    return targetm.asm_out.function_rodata_section (decl, >>> section_reloc); >> So you are saying it should not go into relro if either there is no pic >> flag, the targets are pc relative, or pic uses some address diff? >> >> This seems too complicated, and/or not the right abstraction. >> >> >>> diff --git a/gcc/doc/tm.texi.in b/gcc/doc/tm.texi.in >>> index 3be984bbd5c..0ac1488c837 100644 >>> --- a/gcc/doc/tm.texi.in >>> +++ b/gcc/doc/tm.texi.in >>> @@ -5007,6 +5007,8 @@ it is unlikely to be called. >>>     @hook TARGET_ASM_FUNCTION_RODATA_SECTION >>>   +@hook TARGET_ASM_FUNCTION_RELRO_SECTION >> I would expect people to just use TARGET_ASM_FUNCTION_RODATA_SECTION to >> get the .data.rel.ro?  With another argument then. >> >>> +section * >>> +select_jump_table_section (tree decl) >>> +{ >>> +  int relco; >> "reloc"? >> >>> +  relco = JUMP_TABLES_IN_RELRO; >> Just put that on the same line as the declaration? >> >>> +  if (relco & targetm.asm_out.reloc_rw_mask ()) >>> +    return targetm.asm_out.function_relro_section (decl); >>> +  else >>> +    return targetm.asm_out.function_rodata_section (decl); >>> +} >> (trailing spaces btw) >> >>> @@ -2492,7 +2513,7 @@ final_scan_insn_1 (rtx_insn *insn, FILE *file, >>> int optimize_p ATTRIBUTE_UNUSED, >>>           { >>>             int log_align; >>>   -          switch_to_section (targetm.asm_out.function_rodata_section >>> +          switch_to_section (select_jump_table_section >>>                    (current_function_decl)); >>           section *section >>         = select_jump_table_section (current_function_decl)); >>           switch_to_section (section); >> >> (but it would be better if we didn't indent so deeply here). >> >> >> I think this should be split into a function just selecting the relro >> section (either directly, or from the rodata selection function), and >> then separately the jumptable section thing. >> >> There is a lot of stuff here that seems confused, and a lot of that >> already was there :-( >> >> >> Segher