On Wed, Sep 06, 2017 at 11:10:07AM -0500, Segher Boessenkool wrote: > > for (insn = get_insns (); insn; insn = NEXT_INSN (insn)) > > { > > > if (INSN_P (insn)) > > @@ -25270,10 +25273,14 @@ uses_TOC (void) > > sub = XEXP (sub, 0); > > if (GET_CODE (sub) == UNSPEC > > && XINT (sub, 1) == UNSPEC_TOC) > > - return 1; > > + return ret; > > } > > } > > } > > + else if (crtl->has_bb_partition > > + && NOTE_P (insn) > > + && NOTE_KIND (insn) == NOTE_INSN_SWITCH_TEXT_SECTIONS) > > + ret = 2; > > }
Ok. > > + if (uses_toc == 2) I could repeat the crtl->has_bb_partition test here if it made things clearer, but it is redundant with the above. > > + { > > + in_cold_section_p = !in_cold_section_p; > > + switch_to_section (current_function_section ()); > > + } > > (*targetm.asm_out.internal_label) (file, "LCL", rs6000_pic_labelno); > > > > fprintf (file, "\t.long "); > > @@ -33321,6 +33334,11 @@ rs6000_elf_declare_function_name (FILE * > > ASM_GENERATE_INTERNAL_LABEL (buf, "LCF", rs6000_pic_labelno); > > assemble_name (file, buf); > > putc ('\n', file); > > + if (uses_toc == 2) > > + { > > + in_cold_section_p = !in_cold_section_p; > > + switch_to_section (current_function_section ()); > > + } > > } > > Hrm, does that work if not hot/cold partitioning? Oh, that cannot happen > because uses_toc==2. Tricky. > > Maybe this "switch to the other section" thing should be abstracted out? > Messing with in_cold_section_p is a bit dirty. But it reflects the reality, and is what final.c and varasm.c also do. Without changing in_cold_section_p, that flag will be incorrect while inside of the other section. There are no switch_to_* functions except to switch_to_section, and as argument that can use current_function_section which uses the in_cold_section_p flag, or unlikely_text_section which hardcodes true for in cold, or function_section which uses first_function_block_is_cold. Even if we introduced function_other_section that used !first_function_block_is_cold the in_cold_section_p flag would be incorrect there. Jakub