[{"id":1764227,"web_url":"http://patchwork.ozlabs.org/comment/1764227/","msgid":"<20170906161007.GH13471@gate.crashing.org>","list_archive_url":null,"date":"2017-09-06T16:10:07","subject":"Re: [PATCH] Fix rs6000 sysv4 -fPIC hot/cold partitioning handling\n\t(PR target/81979)","submitter":{"id":134,"url":"http://patchwork.ozlabs.org/api/people/134/","name":"Segher Boessenkool","email":"segher@kernel.crashing.org"},"content":"Hi,\n\nOn Tue, Sep 05, 2017 at 11:27:25PM +0200, Jakub Jelinek wrote:\n> On powerpc with sysv4 -fPIC we emit something like\n> .LCL0:\n> \t.long .LCTOC1-.LCF0\n> before we start emitting the function, and in the prologue we emit\n> .LCF0:\n> and some code.  This fails to assemble if the prologue is emitted in a\n> different partition from the start of the function, as e.g. the following\n> testcase, where the start of the function is hot, i.e. in .text section,\n> but the shrink-wrapped prologue is cold, emitted in .text.unlikely section.\n> .LCL0 is still emitted in the section the function starts, thus .text, and\n> there is no relocation for subtraction of two symbols in other sections\n> (the second - operand has to be in the current section so that a PC-relative\n> relocation can be used).  This probably never worked, but is now more\n> severe, as we enable hot/cold partitioning in GCC 8, where it\n> has been previously only enabled for -fprofile-use.\n\nI wonder if that helps performance at all, for rs6000 anyway...  It's is\na never-ending source of ICEs though :-(\n\n> --- gcc/config/rs6000/rs6000.c.jj\t2017-09-04 09:55:28.000000000 +0200\n> +++ gcc/config/rs6000/rs6000.c\t2017-09-04 16:36:49.033213325 +0200\n> @@ -25248,12 +25248,15 @@ get_TOC_alias_set (void)\n>  \n>  /* This returns nonzero if the current function uses the TOC.  This is\n>     determined by the presence of (use (unspec ... UNSPEC_TOC)), which\n> -   is generated by the ABI_V4 load_toc_* patterns.  */\n> +   is generated by the ABI_V4 load_toc_* patterns.\n> +   Return 2 instead of 1 if the load_toc_* pattern is in the function\n> +   partition that doesn't start the function.  */\n>  #if TARGET_ELF\n>  static int\n>  uses_TOC (void)\n>  {\n>    rtx_insn *insn;\n> +  int ret = 1;\n>  \n>    for (insn = get_insns (); insn; insn = NEXT_INSN (insn))\n\n{\n\n>      if (INSN_P (insn))\n> @@ -25270,10 +25273,14 @@ uses_TOC (void)\n>  \t\t  sub = XEXP (sub, 0);\n>  \t\t  if (GET_CODE (sub) == UNSPEC\n>  \t\t      && XINT (sub, 1) == UNSPEC_TOC)\n> -\t\t    return 1;\n> +\t\t    return ret;\n>  \t\t}\n>  \t    }\n>        }\n> +    else if (crtl->has_bb_partition\n> +\t     && NOTE_P (insn)\n> +\t     && NOTE_KIND (insn) == NOTE_INSN_SWITCH_TEXT_SECTIONS)\n> +      ret = 2;\n\n}\n\n>    return 0;\n>  }\n>  #endif\n\n\n> @@ -33304,14 +33311,20 @@ rs6000_elf_declare_function_name (FILE *\n>        return;\n>      }\n>  \n> +  int uses_toc;\n>    if (DEFAULT_ABI == ABI_V4\n>        && (TARGET_RELOCATABLE || flag_pic > 1)\n>        && !TARGET_SECURE_PLT\n>        && (!constant_pool_empty_p () || crtl->profile)\n> -      && uses_TOC ())\n> +      && (uses_toc = uses_TOC ()))\n>      {\n>        char buf[256];\n>  \n> +      if (uses_toc == 2)\n> +\t{\n> +\t  in_cold_section_p = !in_cold_section_p;\n> +\t  switch_to_section (current_function_section ());\n> +\t}\n>        (*targetm.asm_out.internal_label) (file, \"LCL\", rs6000_pic_labelno);\n>  \n>        fprintf (file, \"\\t.long \");\n> @@ -33321,6 +33334,11 @@ rs6000_elf_declare_function_name (FILE *\n>        ASM_GENERATE_INTERNAL_LABEL (buf, \"LCF\", rs6000_pic_labelno);\n>        assemble_name (file, buf);\n>        putc ('\\n', file);\n> +      if (uses_toc == 2)\n> +\t{\n> +\t  in_cold_section_p = !in_cold_section_p;\n> +\t  switch_to_section (current_function_section ());\n> +\t}\n>      }\n\nHrm, does that work if not hot/cold partitioning?  Oh, that cannot happen\nbecause uses_toc==2.  Tricky.\n\nMaybe this \"switch to the other section\" thing should be abstracted out?\nMessing with in_cold_section_p is a bit dirty.\n\nOtherwise looks okay; please add the {} in the first fragment.\n\nThanks,\n\n\nSegher","headers":{"Return-Path":"<gcc-patches-return-461629-incoming=patchwork.ozlabs.org@gcc.gnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":["patchwork-incoming@bilbo.ozlabs.org","mailing list gcc-patches@gcc.gnu.org"],"Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org\n\t(client-ip=209.132.180.131; helo=sourceware.org;\n\tenvelope-from=gcc-patches-return-461629-incoming=patchwork.ozlabs.org@gcc.gnu.org;\n\treceiver=<UNKNOWN>)","ozlabs.org; dkim=pass (1024-bit key;\n\tunprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org\n\theader.b=\"TrH7CJgs\"; dkim-atps=neutral","sourceware.org; auth=none"],"Received":["from sourceware.org (server1.sourceware.org [209.132.180.131])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256\n\tbits)) (No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xnT8X6Cfsz9s7F\n\tfor <incoming@patchwork.ozlabs.org>;\n\tThu,  7 Sep 2017 02:10:51 +1000 (AEST)","(qmail 39063 invoked by alias); 6 Sep 2017 16:10:38 -0000","(qmail 38983 invoked by uid 89); 6 Sep 2017 16:10:35 -0000","from gate.crashing.org (HELO gate.crashing.org) (63.228.1.57) by\n\tsourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP;\n\tWed, 06 Sep 2017 16:10:29 +0000","from gate.crashing.org (localhost.localdomain [127.0.0.1])\tby\n\tgate.crashing.org (8.14.1/8.13.8) with ESMTP id\n\tv86GABUV032760; Wed, 6 Sep 2017 11:10:13 -0500","(from segher@localhost)\tby gate.crashing.org\n\t(8.14.1/8.14.1/Submit) id v86GA8oV032750;\n\tWed, 6 Sep 2017 11:10:08 -0500"],"DomainKey-Signature":"a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id\n\t:list-unsubscribe:list-archive:list-post:list-help:sender:date\n\t:from:to:cc:subject:message-id:references:mime-version\n\t:content-type:in-reply-to; q=dns; s=default; b=mv/Rn1uymzTwBQYdp\n\tVd6EJi5HDnIrDFouah8NDOV2PhdcCyzm9FQ1BYemzx+sPyxZT6gO8NRLnULSUB7x\n\txUl0K46LNk8Nz25CWUc+0q7KN/LjCwcRAbjjo3OW05Du4r1qcFImlnadiyF/0QDh\n\tP/L0ERS11svBIesiVHnrIsUWH4=","DKIM-Signature":"v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id\n\t:list-unsubscribe:list-archive:list-post:list-help:sender:date\n\t:from:to:cc:subject:message-id:references:mime-version\n\t:content-type:in-reply-to; s=default; bh=q+cRt4aIsIol6fw+m40zg9h\n\tMm0k=; b=TrH7CJgsRQfAP/gctZcJiRvsgihbdBw61RMzkMrw/D4iA3gEKHE0RUE\n\tCyaaWJYh2k0v5ICLocDZ42Rls//HmkuRACdshCIOosQTKcbZDjrjeXE5ZYw1n0Va\n\twy8w+M1ncNkI0BSPJ6lAV1rmdwLjxam6O9FL0KMh3HDe3R3gs3ps=","Mailing-List":"contact gcc-patches-help@gcc.gnu.org; run by ezmlm","Precedence":"bulk","List-Id":"<gcc-patches.gcc.gnu.org>","List-Unsubscribe":"<mailto:gcc-patches-unsubscribe-incoming=patchwork.ozlabs.org@gcc.gnu.org>","List-Archive":"<http://gcc.gnu.org/ml/gcc-patches/>","List-Post":"<mailto:gcc-patches@gcc.gnu.org>","List-Help":"<mailto:gcc-patches-help@gcc.gnu.org>","Sender":"gcc-patches-owner@gcc.gnu.org","X-Virus-Found":"No","X-Spam-SWARE-Status":"No, score=-11.1 required=5.0 tests=AWL, BAYES_00,\n\tGIT_PATCH_2, GIT_PATCH_3,\n\tRP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=never-ending,\n\tneverending","X-HELO":"gate.crashing.org","Date":"Wed, 6 Sep 2017 11:10:07 -0500","From":"Segher Boessenkool <segher@kernel.crashing.org>","To":"Jakub Jelinek <jakub@redhat.com>","Cc":"David Edelsohn <dje.gcc@gmail.com>, gcc-patches@gcc.gnu.org,\n\tAndrew Jenner <andrew@codesourcery.com>","Subject":"Re: [PATCH] Fix rs6000 sysv4 -fPIC hot/cold partitioning handling\n\t(PR target/81979)","Message-ID":"<20170906161007.GH13471@gate.crashing.org>","References":"<20170905212725.GA2291@tucnak>","Mime-Version":"1.0","Content-Type":"text/plain; charset=us-ascii","Content-Disposition":"inline","In-Reply-To":"<20170905212725.GA2291@tucnak>","User-Agent":"Mutt/1.4.2.3i","X-IsSubscribed":"yes"}},{"id":1764244,"web_url":"http://patchwork.ozlabs.org/comment/1764244/","msgid":"<20170906162610.GQ2323@tucnak>","list_archive_url":null,"date":"2017-09-06T16:26:10","subject":"Re: [PATCH] Fix rs6000 sysv4 -fPIC hot/cold partitioning handling\n\t(PR target/81979)","submitter":{"id":671,"url":"http://patchwork.ozlabs.org/api/people/671/","name":"Jakub Jelinek","email":"jakub@redhat.com"},"content":"On Wed, Sep 06, 2017 at 11:10:07AM -0500, Segher Boessenkool wrote:\n> >    for (insn = get_insns (); insn; insn = NEXT_INSN (insn))\n> \n> {\n> \n> >      if (INSN_P (insn))\n> > @@ -25270,10 +25273,14 @@ uses_TOC (void)\n> >  \t\t  sub = XEXP (sub, 0);\n> >  \t\t  if (GET_CODE (sub) == UNSPEC\n> >  \t\t      && XINT (sub, 1) == UNSPEC_TOC)\n> > -\t\t    return 1;\n> > +\t\t    return ret;\n> >  \t\t}\n> >  \t    }\n> >        }\n> > +    else if (crtl->has_bb_partition\n> > +\t     && NOTE_P (insn)\n> > +\t     && NOTE_KIND (insn) == NOTE_INSN_SWITCH_TEXT_SECTIONS)\n> > +      ret = 2;\n> \n> }\n\nOk.\n\n> > +      if (uses_toc == 2)\n\nI could repeat the crtl->has_bb_partition test here if it made things\nclearer, but it is redundant with the above.\n\n> > +\t{\n> > +\t  in_cold_section_p = !in_cold_section_p;\n> > +\t  switch_to_section (current_function_section ());\n> > +\t}\n> >        (*targetm.asm_out.internal_label) (file, \"LCL\", rs6000_pic_labelno);\n> >  \n> >        fprintf (file, \"\\t.long \");\n> > @@ -33321,6 +33334,11 @@ rs6000_elf_declare_function_name (FILE *\n> >        ASM_GENERATE_INTERNAL_LABEL (buf, \"LCF\", rs6000_pic_labelno);\n> >        assemble_name (file, buf);\n> >        putc ('\\n', file);\n> > +      if (uses_toc == 2)\n> > +\t{\n> > +\t  in_cold_section_p = !in_cold_section_p;\n> > +\t  switch_to_section (current_function_section ());\n> > +\t}\n> >      }\n> \n> Hrm, does that work if not hot/cold partitioning?  Oh, that cannot happen\n> because uses_toc==2.  Tricky.\n> \n> Maybe this \"switch to the other section\" thing should be abstracted out?\n> Messing with in_cold_section_p is a bit dirty.\n\nBut it reflects the reality, and is what final.c and varasm.c also do.\nWithout changing in_cold_section_p, that flag will be incorrect while inside\nof the other section.  There are no switch_to_* functions except to\nswitch_to_section, and as argument that can use current_function_section\nwhich uses the in_cold_section_p flag, or unlikely_text_section which\nhardcodes true for in cold, or function_section which uses\nfirst_function_block_is_cold.  Even if we introduced function_other_section\nthat used !first_function_block_is_cold the in_cold_section_p flag would be\nincorrect there.\n\n\tJakub","headers":{"Return-Path":"<gcc-patches-return-461631-incoming=patchwork.ozlabs.org@gcc.gnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":["patchwork-incoming@bilbo.ozlabs.org","mailing list gcc-patches@gcc.gnu.org"],"Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org\n\t(client-ip=209.132.180.131; helo=sourceware.org;\n\tenvelope-from=gcc-patches-return-461631-incoming=patchwork.ozlabs.org@gcc.gnu.org;\n\treceiver=<UNKNOWN>)","ozlabs.org; dkim=pass (1024-bit key;\n\tunprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org\n\theader.b=\"WNPC6tJK\"; dkim-atps=neutral","sourceware.org; auth=none","ext-mx01.extmail.prod.ext.phx2.redhat.com;\n\tdmarc=none (p=none dis=none) header.from=redhat.com","ext-mx01.extmail.prod.ext.phx2.redhat.com;\n\tspf=fail smtp.mailfrom=jakub@redhat.com"],"Received":["from sourceware.org (server1.sourceware.org [209.132.180.131])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256\n\tbits)) (No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xnTVW71Tkz9s7F\n\tfor <incoming@patchwork.ozlabs.org>;\n\tThu,  7 Sep 2017 02:26:27 +1000 (AEST)","(qmail 11685 invoked by alias); 6 Sep 2017 16:26:19 -0000","(qmail 11676 invoked by uid 89); 6 Sep 2017 16:26:18 -0000","from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by\n\tsourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP;\n\tWed, 06 Sep 2017 16:26:17 +0000","from smtp.corp.redhat.com\n\t(int-mx04.intmail.prod.int.phx2.redhat.com\n\t[10.5.11.14])\t(using TLSv1.2 with cipher AECDH-AES256-SHA\n\t(256/256 bits))\t(No client certificate requested)\tby\n\tmx1.redhat.com (Postfix) with ESMTPS id 374B981DE3;\n\tWed,  6 Sep 2017 16:26:16 +0000 (UTC)","from tucnak.zalov.cz (ovpn-116-33.ams2.redhat.com\n\t[10.36.116.33])\tby smtp.corp.redhat.com (Postfix) with ESMTPS\n\tid C23D64F292; Wed,  6 Sep 2017 16:26:15 +0000 (UTC)","from tucnak.zalov.cz (localhost [127.0.0.1])\tby tucnak.zalov.cz\n\t(8.15.2/8.15.2) with ESMTP id v86GQD1c013364;\n\tWed, 6 Sep 2017 18:26:13 +0200","(from jakub@localhost)\tby tucnak.zalov.cz (8.15.2/8.15.2/Submit)\n\tid v86GQA3H013363; Wed, 6 Sep 2017 18:26:10 +0200"],"DomainKey-Signature":"a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id\n\t:list-unsubscribe:list-archive:list-post:list-help:sender:date\n\t:from:to:cc:subject:message-id:reply-to:references:mime-version\n\t:content-type:in-reply-to; q=dns; s=default; b=q7CqIxb8VExQpcBVr\n\tW0qu7H2KagEQ8otGW4L/bVS9LgcpisYRLmFYr9Yz1UB9t26/9Ih9QSX9mCxUNCuN\n\tVv5bmJUb6Z6nYFQdXfAhfN07KaQeUd+FtJwUAt/FePTgg9YCwQfH2hNt7Z1tvOjb\n\tXH1EbLx/RVcK+vpHwytHbEh3eI=","DKIM-Signature":"v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id\n\t:list-unsubscribe:list-archive:list-post:list-help:sender:date\n\t:from:to:cc:subject:message-id:reply-to:references:mime-version\n\t:content-type:in-reply-to; s=default; bh=B1D5xxVyPJcizX0qQmXlj0c\n\tSEvQ=; b=WNPC6tJKhotSAHaWNKOqWr9wrYPBrnnoQKp1+JmIeSbGLrLNDaFl0Kz\n\tC4u+KsB2G15yC7FXDTBaFkx6DqlZtJiP3a0HJkmxcEiefTUZRYoJogiaJ1FdZ/KY\n\t6sK0a0KfFTC6M1Okg1D0NTaq2PvxwG9XAjrvXszKEPC/dH6xuYrU=","Mailing-List":"contact gcc-patches-help@gcc.gnu.org; run by ezmlm","Precedence":"bulk","List-Id":"<gcc-patches.gcc.gnu.org>","List-Unsubscribe":"<mailto:gcc-patches-unsubscribe-incoming=patchwork.ozlabs.org@gcc.gnu.org>","List-Archive":"<http://gcc.gnu.org/ml/gcc-patches/>","List-Post":"<mailto:gcc-patches@gcc.gnu.org>","List-Help":"<mailto:gcc-patches-help@gcc.gnu.org>","Sender":"gcc-patches-owner@gcc.gnu.org","X-Virus-Found":"No","X-Spam-SWARE-Status":"No, score=-1.9 required=5.0 tests=BAYES_00,\n\tRP_MATCHES_RCVD,\n\tSPF_HELO_PASS autolearn=ham version=3.3.2\n\tspammy=Hx-languages-length:2120","X-HELO":"mx1.redhat.com","DMARC-Filter":"OpenDMARC Filter v1.3.2 mx1.redhat.com 374B981DE3","Date":"Wed, 6 Sep 2017 18:26:10 +0200","From":"Jakub Jelinek <jakub@redhat.com>","To":"Segher Boessenkool <segher@kernel.crashing.org>","Cc":"David Edelsohn <dje.gcc@gmail.com>, gcc-patches@gcc.gnu.org,\n\tAndrew Jenner <andrew@codesourcery.com>","Subject":"Re: [PATCH] Fix rs6000 sysv4 -fPIC hot/cold partitioning handling\n\t(PR target/81979)","Message-ID":"<20170906162610.GQ2323@tucnak>","Reply-To":"Jakub Jelinek <jakub@redhat.com>","References":"<20170905212725.GA2291@tucnak>\n\t<20170906161007.GH13471@gate.crashing.org>","MIME-Version":"1.0","Content-Type":"text/plain; charset=us-ascii","Content-Disposition":"inline","In-Reply-To":"<20170906161007.GH13471@gate.crashing.org>","User-Agent":"Mutt/1.7.1 (2016-10-04)","X-IsSubscribed":"yes"}},{"id":1764258,"web_url":"http://patchwork.ozlabs.org/comment/1764258/","msgid":"<20170906164800.GJ13471@gate.crashing.org>","list_archive_url":null,"date":"2017-09-06T16:48:00","subject":"Re: [PATCH] Fix rs6000 sysv4 -fPIC hot/cold partitioning handling\n\t(PR target/81979)","submitter":{"id":134,"url":"http://patchwork.ozlabs.org/api/people/134/","name":"Segher Boessenkool","email":"segher@kernel.crashing.org"},"content":"On Wed, Sep 06, 2017 at 06:26:10PM +0200, Jakub Jelinek wrote:\n> > Maybe this \"switch to the other section\" thing should be abstracted out?\n> > Messing with in_cold_section_p is a bit dirty.\n> \n> But it reflects the reality, and is what final.c and varasm.c also do.\n\nYes, but those aren't target code :-)\n\nI'm suggesting adding a generic switch_from_hot_to_cold_or_the_other_way_around\nfunction (but with a better name ;-) ) that just does these same two lines,\nonly not in target code.  Seems cleaner to me, less surprising.\n\nBut, okay either way.\n\n\nSegher","headers":{"Return-Path":"<gcc-patches-return-461633-incoming=patchwork.ozlabs.org@gcc.gnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":["patchwork-incoming@bilbo.ozlabs.org","mailing list gcc-patches@gcc.gnu.org"],"Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org\n\t(client-ip=209.132.180.131; helo=sourceware.org;\n\tenvelope-from=gcc-patches-return-461633-incoming=patchwork.ozlabs.org@gcc.gnu.org;\n\treceiver=<UNKNOWN>)","ozlabs.org; dkim=pass (1024-bit key;\n\tunprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org\n\theader.b=\"hJMsI23U\"; dkim-atps=neutral","sourceware.org; auth=none"],"Received":["from sourceware.org (server1.sourceware.org [209.132.180.131])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256\n\tbits)) (No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xnV005ctwz9t2d\n\tfor <incoming@patchwork.ozlabs.org>;\n\tThu,  7 Sep 2017 02:48:31 +1000 (AEST)","(qmail 87633 invoked by alias); 6 Sep 2017 16:48:24 -0000","(qmail 82831 invoked by uid 89); 6 Sep 2017 16:48:15 -0000","from gate.crashing.org (HELO gate.crashing.org) (63.228.1.57) by\n\tsourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP;\n\tWed, 06 Sep 2017 16:48:14 +0000","from gate.crashing.org (localhost.localdomain [127.0.0.1])\tby\n\tgate.crashing.org (8.14.1/8.13.8) with ESMTP id\n\tv86Gm2Rd003721; Wed, 6 Sep 2017 11:48:02 -0500","(from segher@localhost)\tby gate.crashing.org\n\t(8.14.1/8.14.1/Submit) id v86Gm1fn003718;\n\tWed, 6 Sep 2017 11:48:01 -0500"],"DomainKey-Signature":"a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id\n\t:list-unsubscribe:list-archive:list-post:list-help:sender:date\n\t:from:to:cc:subject:message-id:references:mime-version\n\t:content-type:in-reply-to; q=dns; s=default; b=ls1Jxia7jeIaqxsnw\n\tIyPPm97bcf52hWF/CBVaT4UMXPDYK743giHdDY2DsfodJeAtFq7a5mWVQRJ4HxPG\n\tHUsoM6bVnYZQkH67G+2i9vSpZ+yzyqHwaBHUaSfj6VJIKgeiuW2BkifcuD75OCDT\n\temX2hW98BNWIWf2in/1vUdfWEg=","DKIM-Signature":"v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id\n\t:list-unsubscribe:list-archive:list-post:list-help:sender:date\n\t:from:to:cc:subject:message-id:references:mime-version\n\t:content-type:in-reply-to; s=default; bh=R78cSsoRbkuduMhXoiNCu4g\n\tDuo8=; b=hJMsI23UlYyM9VeBveoDHx62OkdELXJO1aWZmcfDDr2StYubzaDdh71\n\tGiy00+KuyuG9zRKrGiXbramvRyd21Gvvb4j5GlFe/cLR8TmWNYYH+B7v3GnUYN5j\n\tgPSYFjiWlJkS44dN9XqXxZ//Tj/WkwZNATwVD4A+pNc6j8+uOWCk=","Mailing-List":"contact gcc-patches-help@gcc.gnu.org; run by ezmlm","Precedence":"bulk","List-Id":"<gcc-patches.gcc.gnu.org>","List-Unsubscribe":"<mailto:gcc-patches-unsubscribe-incoming=patchwork.ozlabs.org@gcc.gnu.org>","List-Archive":"<http://gcc.gnu.org/ml/gcc-patches/>","List-Post":"<mailto:gcc-patches@gcc.gnu.org>","List-Help":"<mailto:gcc-patches-help@gcc.gnu.org>","Sender":"gcc-patches-owner@gcc.gnu.org","X-Virus-Found":"No","X-Spam-SWARE-Status":"No, score=-2.1 required=5.0 tests=AWL, BAYES_00,\n\tRP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=","X-HELO":"gate.crashing.org","Date":"Wed, 6 Sep 2017 11:48:00 -0500","From":"Segher Boessenkool <segher@kernel.crashing.org>","To":"Jakub Jelinek <jakub@redhat.com>","Cc":"David Edelsohn <dje.gcc@gmail.com>, gcc-patches@gcc.gnu.org,\n\tAndrew Jenner <andrew@codesourcery.com>","Subject":"Re: [PATCH] Fix rs6000 sysv4 -fPIC hot/cold partitioning handling\n\t(PR target/81979)","Message-ID":"<20170906164800.GJ13471@gate.crashing.org>","References":"<20170905212725.GA2291@tucnak>\n\t<20170906161007.GH13471@gate.crashing.org>\n\t<20170906162610.GQ2323@tucnak>","Mime-Version":"1.0","Content-Type":"text/plain; charset=us-ascii","Content-Disposition":"inline","In-Reply-To":"<20170906162610.GQ2323@tucnak>","User-Agent":"Mutt/1.4.2.3i","X-IsSubscribed":"yes"}},{"id":1764617,"web_url":"http://patchwork.ozlabs.org/comment/1764617/","msgid":"<20170907094609.GU2323@tucnak>","list_archive_url":null,"date":"2017-09-07T09:46:09","subject":"Re: [PATCH] Fix rs6000 sysv4 -fPIC hot/cold partitioning handling\n\t(PR target/81979)","submitter":{"id":671,"url":"http://patchwork.ozlabs.org/api/people/671/","name":"Jakub Jelinek","email":"jakub@redhat.com"},"content":"On Wed, Sep 06, 2017 at 11:48:00AM -0500, Segher Boessenkool wrote:\n> On Wed, Sep 06, 2017 at 06:26:10PM +0200, Jakub Jelinek wrote:\n> > > Maybe this \"switch to the other section\" thing should be abstracted out?\n> > > Messing with in_cold_section_p is a bit dirty.\n> > \n> > But it reflects the reality, and is what final.c and varasm.c also do.\n> \n> Yes, but those aren't target code :-)\n> \n> I'm suggesting adding a generic switch_from_hot_to_cold_or_the_other_way_around\n> function (but with a better name ;-) ) that just does these same two lines,\n> only not in target code.  Seems cleaner to me, less surprising.\n\nRichard, is this generic change ok?\n\n2017-09-07  Jakub Jelinek  <jakub@redhat.com>\n\n\tPR target/81979\n\t* output.h (switch_to_other_text_partition): New declaration.\n\t* varasm.c (switch_to_other_text_partition): New function.\n\t* config/rs6000/rs6000.c (uses_TOC): Return 2 if\n\tNOTE_INSN_SWITCH_TEXT_SECTIONS is seen before finding load_toc_* insn.\n\t(rs6000_elf_declare_function_name): If uses_TOC returned 2, switch\n\tto the other text partition before emitting LCL label and switch back\n\tafter emitting the word after it.\n\n\t* gcc.dg/pr81979.c: New test.\n\n--- gcc/output.h.jj\t2017-09-01 09:26:48.000000000 +0200\n+++ gcc/output.h\t2017-09-07 11:38:48.668090305 +0200\n@@ -537,6 +537,7 @@ extern section *mergeable_constant_secti\n extern section *function_section (tree);\n extern section *unlikely_text_section (void);\n extern section *current_function_section (void);\n+extern void switch_to_other_text_partition (void);\n \n /* Return the numbered .ctors.N (if CONSTRUCTOR_P) or .dtors.N (if\n    not) section for PRIORITY.  */\n--- gcc/varasm.c.jj\t2017-09-06 11:09:39.000000000 +0200\n+++ gcc/varasm.c\t2017-09-07 11:35:34.366442544 +0200\n@@ -695,6 +695,16 @@ unlikely_text_section_p (section *sect)\n   return sect == function_section_1 (current_function_decl, true);\n }\n \n+/* Switch to the other function partition (if inside of hot section\n+   into cold section, otherwise into the hot section).  */\n+\n+void\n+switch_to_other_text_partition (void)\n+{\n+  in_cold_section_p = !in_cold_section_p;\n+  switch_to_section (current_function_section ());\n+}\n+\n /* Return the read-only data section associated with function DECL.  */\n \n section *\n--- gcc/config/rs6000/rs6000.c.jj\t2017-09-05 23:28:22.238928428 +0200\n+++ gcc/config/rs6000/rs6000.c\t2017-09-07 11:39:25.781640963 +0200\n@@ -25324,32 +25324,41 @@ get_TOC_alias_set (void)\n \n /* This returns nonzero if the current function uses the TOC.  This is\n    determined by the presence of (use (unspec ... UNSPEC_TOC)), which\n-   is generated by the ABI_V4 load_toc_* patterns.  */\n+   is generated by the ABI_V4 load_toc_* patterns.\n+   Return 2 instead of 1 if the load_toc_* pattern is in the function\n+   partition that doesn't start the function.  */\n #if TARGET_ELF\n static int\n uses_TOC (void)\n {\n   rtx_insn *insn;\n+  int ret = 1;\n \n   for (insn = get_insns (); insn; insn = NEXT_INSN (insn))\n-    if (INSN_P (insn))\n-      {\n-\trtx pat = PATTERN (insn);\n-\tint i;\n+    {\n+      if (INSN_P (insn))\n+\t{\n+\t  rtx pat = PATTERN (insn);\n+\t  int i;\n \n-\tif (GET_CODE (pat) == PARALLEL)\n-\t  for (i = 0; i < XVECLEN (pat, 0); i++)\n-\t    {\n-\t      rtx sub = XVECEXP (pat, 0, i);\n-\t      if (GET_CODE (sub) == USE)\n-\t\t{\n-\t\t  sub = XEXP (sub, 0);\n-\t\t  if (GET_CODE (sub) == UNSPEC\n-\t\t      && XINT (sub, 1) == UNSPEC_TOC)\n-\t\t    return 1;\n-\t\t}\n-\t    }\n-      }\n+\t  if (GET_CODE (pat) == PARALLEL)\n+\t    for (i = 0; i < XVECLEN (pat, 0); i++)\n+\t      {\n+\t\trtx sub = XVECEXP (pat, 0, i);\n+\t\tif (GET_CODE (sub) == USE)\n+\t\t  {\n+\t\t    sub = XEXP (sub, 0);\n+\t\t    if (GET_CODE (sub) == UNSPEC\n+\t\t\t&& XINT (sub, 1) == UNSPEC_TOC)\n+\t\t      return ret;\n+\t\t  }\n+\t      }\n+\t}\n+      else if (crtl->has_bb_partition\n+\t       && NOTE_P (insn)\n+\t       && NOTE_KIND (insn) == NOTE_INSN_SWITCH_TEXT_SECTIONS)\n+\tret = 2;\n+    }\n   return 0;\n }\n #endif\n@@ -33380,14 +33389,17 @@ rs6000_elf_declare_function_name (FILE *\n       return;\n     }\n \n+  int uses_toc;\n   if (DEFAULT_ABI == ABI_V4\n       && (TARGET_RELOCATABLE || flag_pic > 1)\n       && !TARGET_SECURE_PLT\n       && (!constant_pool_empty_p () || crtl->profile)\n-      && uses_TOC ())\n+      && (uses_toc = uses_TOC ()))\n     {\n       char buf[256];\n \n+      if (uses_toc == 2)\n+\tswitch_to_other_text_partition ();\n       (*targetm.asm_out.internal_label) (file, \"LCL\", rs6000_pic_labelno);\n \n       fprintf (file, \"\\t.long \");\n@@ -33397,6 +33409,8 @@ rs6000_elf_declare_function_name (FILE *\n       ASM_GENERATE_INTERNAL_LABEL (buf, \"LCF\", rs6000_pic_labelno);\n       assemble_name (file, buf);\n       putc ('\\n', file);\n+      if (uses_toc == 2)\n+\tswitch_to_other_text_partition ();\n     }\n \n   ASM_OUTPUT_TYPE_DIRECTIVE (file, name, \"function\");\n--- gcc/testsuite/gcc.dg/pr81979.c.jj\t2017-09-07 11:31:15.893566211 +0200\n+++ gcc/testsuite/gcc.dg/pr81979.c\t2017-09-07 11:31:15.893566211 +0200\n@@ -0,0 +1,32 @@\n+/* PR target/81979 */\n+/* { dg-do link } */\n+/* { dg-options \"-O2 -w\" } */\n+/* { dg-additional-options \"-fPIC\" { target fpic } } */\n+/* { dg-additional-options \"-freorder-blocks-and-partition\" { target freorder } } */\n+\n+int d;\n+\n+__attribute__((noinline, noclone)) void\n+foo (int x)\n+{\n+  int c;\n+  while (c < 1)\n+    {\n+      int o;\n+      for (o = 0; o < 4; ++o)\n+\tc /= (x != 0) ? 2 : x;\n+    }\n+\n+  d = 1;\n+  for (;;)\n+    ;\n+}\n+\n+int\n+main ()\n+{\n+  asm volatile (\"\" : : \"r\" (&d) : \"memory\");\n+  foo (d);\n+  asm volatile (\"\" : : \"r\" (&d) : \"memory\");\n+  return 0;\n+}\n\n\n\tJakub","headers":{"Return-Path":"<gcc-patches-return-461673-incoming=patchwork.ozlabs.org@gcc.gnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":["patchwork-incoming@bilbo.ozlabs.org","mailing list gcc-patches@gcc.gnu.org"],"Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org\n\t(client-ip=209.132.180.131; helo=sourceware.org;\n\tenvelope-from=gcc-patches-return-461673-incoming=patchwork.ozlabs.org@gcc.gnu.org;\n\treceiver=<UNKNOWN>)","ozlabs.org; dkim=pass (1024-bit key;\n\tunprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org\n\theader.b=\"KQsPg2lX\"; dkim-atps=neutral","sourceware.org; auth=none","ext-mx09.extmail.prod.ext.phx2.redhat.com;\n\tdmarc=none (p=none dis=none) header.from=redhat.com","ext-mx09.extmail.prod.ext.phx2.redhat.com;\n\tspf=fail smtp.mailfrom=jakub@redhat.com"],"Received":["from sourceware.org (server1.sourceware.org [209.132.180.131])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256\n\tbits)) (No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xnwZb2XFqz9t2R\n\tfor <incoming@patchwork.ozlabs.org>;\n\tThu,  7 Sep 2017 19:46:28 +1000 (AEST)","(qmail 38562 invoked by alias); 7 Sep 2017 09:46:19 -0000","(qmail 38121 invoked by uid 89); 7 Sep 2017 09:46:19 -0000","from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by\n\tsourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP;\n\tThu, 07 Sep 2017 09:46:17 +0000","from smtp.corp.redhat.com\n\t(int-mx01.intmail.prod.int.phx2.redhat.com\n\t[10.5.11.11])\t(using TLSv1.2 with cipher AECDH-AES256-SHA\n\t(256/256 bits))\t(No client certificate requested)\tby\n\tmx1.redhat.com (Postfix) with ESMTPS id 92EE14E34A;\n\tThu,  7 Sep 2017 09:46:15 +0000 (UTC)","from tucnak.zalov.cz (ovpn-116-33.ams2.redhat.com\n\t[10.36.116.33])\tby smtp.corp.redhat.com (Postfix) with ESMTPS\n\tid 151526058F; Thu,  7 Sep 2017 09:46:14 +0000 (UTC)","from tucnak.zalov.cz (localhost [127.0.0.1])\tby tucnak.zalov.cz\n\t(8.15.2/8.15.2) with ESMTP id v879kCLf020478;\n\tThu, 7 Sep 2017 11:46:12 +0200","(from jakub@localhost)\tby tucnak.zalov.cz (8.15.2/8.15.2/Submit)\n\tid v879k9NC020477; Thu, 7 Sep 2017 11:46:09 +0200"],"DomainKey-Signature":"a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id\n\t:list-unsubscribe:list-archive:list-post:list-help:sender:date\n\t:from:to:cc:subject:message-id:reply-to:references:mime-version\n\t:content-type:in-reply-to; q=dns; s=default; b=qD5bSTgGKJDlXnkZW\n\tkGMdQPfQH4pxywoF78O611euo2nLK4SwhLc7Pde+lZpTZXBK1nahafMmRZYXWqj1\n\ttTHVdUaekZBRy9SYVmex1cqRpLBrBoFUyjIHMF5wDTgOoa8GfyLwz9HHKDeSKB4M\n\tuUfGIpFeq4Zg4QjZBEVY8Tjd5A=","DKIM-Signature":"v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id\n\t:list-unsubscribe:list-archive:list-post:list-help:sender:date\n\t:from:to:cc:subject:message-id:reply-to:references:mime-version\n\t:content-type:in-reply-to; s=default; bh=DO4dAqOZo+hDGMQyZX2Txb+\n\tEKO0=; b=KQsPg2lXV1GwS7+tz5wnOyIDUEoaF41nwjzFvECNebfBM2uUrcxFEUI\n\t/e/swyZuGC0uFwBWVXhP9DuT7lmeYvGbhxnpB+9nbr/I821Rmbmb3ca71eTdqBrq\n\tkxWrr1LB7CxiWNx7lnhac+hiD85FELSq36DeUgKnRxH32tUQYmKU=","Mailing-List":"contact gcc-patches-help@gcc.gnu.org; run by ezmlm","Precedence":"bulk","List-Id":"<gcc-patches.gcc.gnu.org>","List-Unsubscribe":"<mailto:gcc-patches-unsubscribe-incoming=patchwork.ozlabs.org@gcc.gnu.org>","List-Archive":"<http://gcc.gnu.org/ml/gcc-patches/>","List-Post":"<mailto:gcc-patches@gcc.gnu.org>","List-Help":"<mailto:gcc-patches-help@gcc.gnu.org>","Sender":"gcc-patches-owner@gcc.gnu.org","X-Virus-Found":"No","X-Spam-SWARE-Status":"No, score=-11.9 required=5.0 tests=BAYES_00, GIT_PATCH_2,\n\tGIT_PATCH_3, RP_MATCHES_RCVD,\n\tSPF_HELO_PASS autolearn=ham version=3.3.2 spammy=","X-HELO":"mx1.redhat.com","DMARC-Filter":"OpenDMARC Filter v1.3.2 mx1.redhat.com 92EE14E34A","Date":"Thu, 7 Sep 2017 11:46:09 +0200","From":"Jakub Jelinek <jakub@redhat.com>","To":"Richard Biener <rguenther@suse.de>,\n\tSegher Boessenkool <segher@kernel.crashing.org>","Cc":"David Edelsohn <dje.gcc@gmail.com>, gcc-patches@gcc.gnu.org,\n\tAndrew Jenner <andrew@codesourcery.com>","Subject":"Re: [PATCH] Fix rs6000 sysv4 -fPIC hot/cold partitioning handling\n\t(PR target/81979)","Message-ID":"<20170907094609.GU2323@tucnak>","Reply-To":"Jakub Jelinek <jakub@redhat.com>","References":"<20170905212725.GA2291@tucnak>\n\t<20170906161007.GH13471@gate.crashing.org>\n\t<20170906162610.GQ2323@tucnak>\n\t<20170906164800.GJ13471@gate.crashing.org>","MIME-Version":"1.0","Content-Type":"text/plain; charset=us-ascii","Content-Disposition":"inline","In-Reply-To":"<20170906164800.GJ13471@gate.crashing.org>","User-Agent":"Mutt/1.7.1 (2016-10-04)","X-IsSubscribed":"yes"}},{"id":1764654,"web_url":"http://patchwork.ozlabs.org/comment/1764654/","msgid":"<alpine.LSU.2.20.1709071314140.14191@zhemvz.fhfr.qr>","list_archive_url":null,"date":"2017-09-07T11:14:24","subject":"Re: [PATCH] Fix rs6000 sysv4 -fPIC hot/cold partitioning handling\n\t(PR target/81979)","submitter":{"id":4338,"url":"http://patchwork.ozlabs.org/api/people/4338/","name":"Richard Biener","email":"rguenther@suse.de"},"content":"On Thu, 7 Sep 2017, Jakub Jelinek wrote:\n\n> On Wed, Sep 06, 2017 at 11:48:00AM -0500, Segher Boessenkool wrote:\n> > On Wed, Sep 06, 2017 at 06:26:10PM +0200, Jakub Jelinek wrote:\n> > > > Maybe this \"switch to the other section\" thing should be abstracted out?\n> > > > Messing with in_cold_section_p is a bit dirty.\n> > > \n> > > But it reflects the reality, and is what final.c and varasm.c also do.\n> > \n> > Yes, but those aren't target code :-)\n> > \n> > I'm suggesting adding a generic switch_from_hot_to_cold_or_the_other_way_around\n> > function (but with a better name ;-) ) that just does these same two lines,\n> > only not in target code.  Seems cleaner to me, less surprising.\n> \n> Richard, is this generic change ok?\n\nworks for me.\n\nThanks,\nRichard.\n\n> 2017-09-07  Jakub Jelinek  <jakub@redhat.com>\n> \n> \tPR target/81979\n> \t* output.h (switch_to_other_text_partition): New declaration.\n> \t* varasm.c (switch_to_other_text_partition): New function.\n> \t* config/rs6000/rs6000.c (uses_TOC): Return 2 if\n> \tNOTE_INSN_SWITCH_TEXT_SECTIONS is seen before finding load_toc_* insn.\n> \t(rs6000_elf_declare_function_name): If uses_TOC returned 2, switch\n> \tto the other text partition before emitting LCL label and switch back\n> \tafter emitting the word after it.\n> \n> \t* gcc.dg/pr81979.c: New test.\n> \n> --- gcc/output.h.jj\t2017-09-01 09:26:48.000000000 +0200\n> +++ gcc/output.h\t2017-09-07 11:38:48.668090305 +0200\n> @@ -537,6 +537,7 @@ extern section *mergeable_constant_secti\n>  extern section *function_section (tree);\n>  extern section *unlikely_text_section (void);\n>  extern section *current_function_section (void);\n> +extern void switch_to_other_text_partition (void);\n>  \n>  /* Return the numbered .ctors.N (if CONSTRUCTOR_P) or .dtors.N (if\n>     not) section for PRIORITY.  */\n> --- gcc/varasm.c.jj\t2017-09-06 11:09:39.000000000 +0200\n> +++ gcc/varasm.c\t2017-09-07 11:35:34.366442544 +0200\n> @@ -695,6 +695,16 @@ unlikely_text_section_p (section *sect)\n>    return sect == function_section_1 (current_function_decl, true);\n>  }\n>  \n> +/* Switch to the other function partition (if inside of hot section\n> +   into cold section, otherwise into the hot section).  */\n> +\n> +void\n> +switch_to_other_text_partition (void)\n> +{\n> +  in_cold_section_p = !in_cold_section_p;\n> +  switch_to_section (current_function_section ());\n> +}\n> +\n>  /* Return the read-only data section associated with function DECL.  */\n>  \n>  section *\n> --- gcc/config/rs6000/rs6000.c.jj\t2017-09-05 23:28:22.238928428 +0200\n> +++ gcc/config/rs6000/rs6000.c\t2017-09-07 11:39:25.781640963 +0200\n> @@ -25324,32 +25324,41 @@ get_TOC_alias_set (void)\n>  \n>  /* This returns nonzero if the current function uses the TOC.  This is\n>     determined by the presence of (use (unspec ... UNSPEC_TOC)), which\n> -   is generated by the ABI_V4 load_toc_* patterns.  */\n> +   is generated by the ABI_V4 load_toc_* patterns.\n> +   Return 2 instead of 1 if the load_toc_* pattern is in the function\n> +   partition that doesn't start the function.  */\n>  #if TARGET_ELF\n>  static int\n>  uses_TOC (void)\n>  {\n>    rtx_insn *insn;\n> +  int ret = 1;\n>  \n>    for (insn = get_insns (); insn; insn = NEXT_INSN (insn))\n> -    if (INSN_P (insn))\n> -      {\n> -\trtx pat = PATTERN (insn);\n> -\tint i;\n> +    {\n> +      if (INSN_P (insn))\n> +\t{\n> +\t  rtx pat = PATTERN (insn);\n> +\t  int i;\n>  \n> -\tif (GET_CODE (pat) == PARALLEL)\n> -\t  for (i = 0; i < XVECLEN (pat, 0); i++)\n> -\t    {\n> -\t      rtx sub = XVECEXP (pat, 0, i);\n> -\t      if (GET_CODE (sub) == USE)\n> -\t\t{\n> -\t\t  sub = XEXP (sub, 0);\n> -\t\t  if (GET_CODE (sub) == UNSPEC\n> -\t\t      && XINT (sub, 1) == UNSPEC_TOC)\n> -\t\t    return 1;\n> -\t\t}\n> -\t    }\n> -      }\n> +\t  if (GET_CODE (pat) == PARALLEL)\n> +\t    for (i = 0; i < XVECLEN (pat, 0); i++)\n> +\t      {\n> +\t\trtx sub = XVECEXP (pat, 0, i);\n> +\t\tif (GET_CODE (sub) == USE)\n> +\t\t  {\n> +\t\t    sub = XEXP (sub, 0);\n> +\t\t    if (GET_CODE (sub) == UNSPEC\n> +\t\t\t&& XINT (sub, 1) == UNSPEC_TOC)\n> +\t\t      return ret;\n> +\t\t  }\n> +\t      }\n> +\t}\n> +      else if (crtl->has_bb_partition\n> +\t       && NOTE_P (insn)\n> +\t       && NOTE_KIND (insn) == NOTE_INSN_SWITCH_TEXT_SECTIONS)\n> +\tret = 2;\n> +    }\n>    return 0;\n>  }\n>  #endif\n> @@ -33380,14 +33389,17 @@ rs6000_elf_declare_function_name (FILE *\n>        return;\n>      }\n>  \n> +  int uses_toc;\n>    if (DEFAULT_ABI == ABI_V4\n>        && (TARGET_RELOCATABLE || flag_pic > 1)\n>        && !TARGET_SECURE_PLT\n>        && (!constant_pool_empty_p () || crtl->profile)\n> -      && uses_TOC ())\n> +      && (uses_toc = uses_TOC ()))\n>      {\n>        char buf[256];\n>  \n> +      if (uses_toc == 2)\n> +\tswitch_to_other_text_partition ();\n>        (*targetm.asm_out.internal_label) (file, \"LCL\", rs6000_pic_labelno);\n>  \n>        fprintf (file, \"\\t.long \");\n> @@ -33397,6 +33409,8 @@ rs6000_elf_declare_function_name (FILE *\n>        ASM_GENERATE_INTERNAL_LABEL (buf, \"LCF\", rs6000_pic_labelno);\n>        assemble_name (file, buf);\n>        putc ('\\n', file);\n> +      if (uses_toc == 2)\n> +\tswitch_to_other_text_partition ();\n>      }\n>  \n>    ASM_OUTPUT_TYPE_DIRECTIVE (file, name, \"function\");\n> --- gcc/testsuite/gcc.dg/pr81979.c.jj\t2017-09-07 11:31:15.893566211 +0200\n> +++ gcc/testsuite/gcc.dg/pr81979.c\t2017-09-07 11:31:15.893566211 +0200\n> @@ -0,0 +1,32 @@\n> +/* PR target/81979 */\n> +/* { dg-do link } */\n> +/* { dg-options \"-O2 -w\" } */\n> +/* { dg-additional-options \"-fPIC\" { target fpic } } */\n> +/* { dg-additional-options \"-freorder-blocks-and-partition\" { target freorder } } */\n> +\n> +int d;\n> +\n> +__attribute__((noinline, noclone)) void\n> +foo (int x)\n> +{\n> +  int c;\n> +  while (c < 1)\n> +    {\n> +      int o;\n> +      for (o = 0; o < 4; ++o)\n> +\tc /= (x != 0) ? 2 : x;\n> +    }\n> +\n> +  d = 1;\n> +  for (;;)\n> +    ;\n> +}\n> +\n> +int\n> +main ()\n> +{\n> +  asm volatile (\"\" : : \"r\" (&d) : \"memory\");\n> +  foo (d);\n> +  asm volatile (\"\" : : \"r\" (&d) : \"memory\");\n> +  return 0;\n> +}\n> \n> \n> \tJakub\n> \n>","headers":{"Return-Path":"<gcc-patches-return-461680-incoming=patchwork.ozlabs.org@gcc.gnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":["patchwork-incoming@bilbo.ozlabs.org","mailing list gcc-patches@gcc.gnu.org"],"Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org\n\t(client-ip=209.132.180.131; helo=sourceware.org;\n\tenvelope-from=gcc-patches-return-461680-incoming=patchwork.ozlabs.org@gcc.gnu.org;\n\treceiver=<UNKNOWN>)","ozlabs.org; dkim=pass (1024-bit key;\n\tunprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org\n\theader.b=\"Olfis1u5\"; dkim-atps=neutral","sourceware.org; auth=none"],"Received":["from sourceware.org (server1.sourceware.org [209.132.180.131])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256\n\tbits)) (No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xnyXM3D55z9sCZ\n\tfor <incoming@patchwork.ozlabs.org>;\n\tThu,  7 Sep 2017 21:14:41 +1000 (AEST)","(qmail 85086 invoked by alias); 7 Sep 2017 11:14:33 -0000","(qmail 85070 invoked by uid 89); 7 Sep 2017 11:14:33 -0000","from mx2.suse.de (HELO mx1.suse.de) (195.135.220.15) by\n\tsourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP;\n\tThu, 07 Sep 2017 11:14:27 +0000","from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254])\tby\n\tmx1.suse.de (Postfix) with ESMTP id B9751AB9B;\n\tThu,  7 Sep 2017 11:14:24 +0000 (UTC)"],"DomainKey-Signature":"a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id\n\t:list-unsubscribe:list-archive:list-post:list-help:sender:date\n\t:from:to:cc:subject:in-reply-to:message-id:references\n\t:mime-version:content-type; q=dns; s=default; b=Tov76uPnnDldGc9U\n\tszLrWjM+hvAzf2628yQ8TD/Ke7NCUUByPqOdAX4MNZiGnmrFlYhGJ8eTqZco3Kae\n\tCvhtFCWic0r4F7tMA2jBB+RL6Ic7nMMN9bGEvBwegIUJ2U/4UtxwT46wZtC/2dDb\n\tJpMnbD0DBLskj1bHuVqFJhk1Jj8=","DKIM-Signature":"v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id\n\t:list-unsubscribe:list-archive:list-post:list-help:sender:date\n\t:from:to:cc:subject:in-reply-to:message-id:references\n\t:mime-version:content-type; s=default; bh=LHADo56FX2CTKJPBe0a9vo\n\ttxcm0=; b=Olfis1u5p5zj5lR8kXMF8HBMv1Q0ABQYYQiyMrgtcqBvDUAkX9C3U0\n\trDmB1YXJ885h+DfTd3hsvaQhpMchvAlUdcdN71pXr+Dh93cEVUmp9Nro8qvFkbqD\n\tthrtpPFDZamet59Y8GmJJxtw08TDLsZ9hiDKefbOd5n1/V7pUog40=","Mailing-List":"contact gcc-patches-help@gcc.gnu.org; run by ezmlm","Precedence":"bulk","List-Id":"<gcc-patches.gcc.gnu.org>","List-Unsubscribe":"<mailto:gcc-patches-unsubscribe-incoming=patchwork.ozlabs.org@gcc.gnu.org>","List-Archive":"<http://gcc.gnu.org/ml/gcc-patches/>","List-Post":"<mailto:gcc-patches@gcc.gnu.org>","List-Help":"<mailto:gcc-patches-help@gcc.gnu.org>","Sender":"gcc-patches-owner@gcc.gnu.org","X-Virus-Found":"No","X-Spam-SWARE-Status":"No, score=-11.9 required=5.0 tests=BAYES_00, GIT_PATCH_2,\n\tGIT_PATCH_3, RP_MATCHES_RCVD,\n\tSPF_PASS autolearn=ham version=3.3.2 spammy=","X-HELO":"mx1.suse.de","Date":"Thu, 7 Sep 2017 13:14:24 +0200 (CEST)","From":"Richard Biener <rguenther@suse.de>","To":"Jakub Jelinek <jakub@redhat.com>","cc":"Segher Boessenkool <segher@kernel.crashing.org>,\n\tDavid Edelsohn <dje.gcc@gmail.com>, gcc-patches@gcc.gnu.org,\n\tAndrew Jenner <andrew@codesourcery.com>","Subject":"Re: [PATCH] Fix rs6000 sysv4 -fPIC hot/cold partitioning handling\n\t(PR target/81979)","In-Reply-To":"<20170907094609.GU2323@tucnak>","Message-ID":"<alpine.LSU.2.20.1709071314140.14191@zhemvz.fhfr.qr>","References":"<20170905212725.GA2291@tucnak>\n\t<20170906161007.GH13471@gate.crashing.org>\n\t<20170906162610.GQ2323@tucnak>\n\t<20170906164800.GJ13471@gate.crashing.org>\n\t<20170907094609.GU2323@tucnak>","User-Agent":"Alpine 2.20 (LSU 67 2015-01-07)","MIME-Version":"1.0","Content-Type":"text/plain; charset=US-ASCII"}},{"id":1764672,"web_url":"http://patchwork.ozlabs.org/comment/1764672/","msgid":"<20170907114228.GP13471@gate.crashing.org>","list_archive_url":null,"date":"2017-09-07T11:42:29","subject":"Re: [PATCH] Fix rs6000 sysv4 -fPIC hot/cold partitioning handling\n\t(PR target/81979)","submitter":{"id":134,"url":"http://patchwork.ozlabs.org/api/people/134/","name":"Segher Boessenkool","email":"segher@kernel.crashing.org"},"content":"On Thu, Sep 07, 2017 at 11:46:09AM +0200, Jakub Jelinek wrote:\n> On Wed, Sep 06, 2017 at 11:48:00AM -0500, Segher Boessenkool wrote:\n> > On Wed, Sep 06, 2017 at 06:26:10PM +0200, Jakub Jelinek wrote:\n> > > > Maybe this \"switch to the other section\" thing should be abstracted out?\n> > > > Messing with in_cold_section_p is a bit dirty.\n> > > \n> > > But it reflects the reality, and is what final.c and varasm.c also do.\n> > \n> > Yes, but those aren't target code :-)\n> > \n> > I'm suggesting adding a generic switch_from_hot_to_cold_or_the_other_way_around\n> > function (but with a better name ;-) ) that just does these same two lines,\n> > only not in target code.  Seems cleaner to me, less surprising.\n> \n> Richard, is this generic change ok?\n\nThanks Jakub.  The rs6000 parts are okay, if I didn't say that yet.\n\n\nSegher\n\n\n> \tPR target/81979\n> \t* output.h (switch_to_other_text_partition): New declaration.\n> \t* varasm.c (switch_to_other_text_partition): New function.\n> \t* config/rs6000/rs6000.c (uses_TOC): Return 2 if\n> \tNOTE_INSN_SWITCH_TEXT_SECTIONS is seen before finding load_toc_* insn.\n> \t(rs6000_elf_declare_function_name): If uses_TOC returned 2, switch\n> \tto the other text partition before emitting LCL label and switch back\n> \tafter emitting the word after it.\n> \n> \t* gcc.dg/pr81979.c: New test.","headers":{"Return-Path":"<gcc-patches-return-461683-incoming=patchwork.ozlabs.org@gcc.gnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":["patchwork-incoming@bilbo.ozlabs.org","mailing list gcc-patches@gcc.gnu.org"],"Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org\n\t(client-ip=209.132.180.131; helo=sourceware.org;\n\tenvelope-from=gcc-patches-return-461683-incoming=patchwork.ozlabs.org@gcc.gnu.org;\n\treceiver=<UNKNOWN>)","ozlabs.org; dkim=pass (1024-bit key;\n\tunprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org\n\theader.b=\"qO5cGCk3\"; dkim-atps=neutral","sourceware.org; auth=none"],"Received":["from sourceware.org (server1.sourceware.org [209.132.180.131])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256\n\tbits)) (No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xnz8v3cc3z9sRY\n\tfor <incoming@patchwork.ozlabs.org>;\n\tThu,  7 Sep 2017 21:42:54 +1000 (AEST)","(qmail 17291 invoked by alias); 7 Sep 2017 11:42:48 -0000","(qmail 17278 invoked by uid 89); 7 Sep 2017 11:42:47 -0000","from gate.crashing.org (HELO gate.crashing.org) (63.228.1.57) by\n\tsourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP;\n\tThu, 07 Sep 2017 11:42:42 +0000","from gate.crashing.org (localhost.localdomain [127.0.0.1])\tby\n\tgate.crashing.org (8.14.1/8.13.8) with ESMTP id\n\tv87BgWKq000430; Thu, 7 Sep 2017 06:42:33 -0500","(from segher@localhost)\tby gate.crashing.org\n\t(8.14.1/8.14.1/Submit) id v87BgT9f000427;\n\tThu, 7 Sep 2017 06:42:29 -0500"],"DomainKey-Signature":"a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id\n\t:list-unsubscribe:list-archive:list-post:list-help:sender:date\n\t:from:to:cc:subject:message-id:references:mime-version\n\t:content-type:in-reply-to; q=dns; s=default; b=qikHVgfvX5GB79n5z\n\t/0I/4dlMIFg6rbx1f48v7Hobz1Wl3b53jkayJX9Qbowl/Gy93ItnBGRWBMXPgrWM\n\tl76UBDsGcRl0U/o9EC4kzD/Ghhu+IL34nQpCUHHgKdwCqLy77CeXxaU3mTi8hk4o\n\teARfUMVzbCqzNIl9v+s4wjmeWE=","DKIM-Signature":"v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id\n\t:list-unsubscribe:list-archive:list-post:list-help:sender:date\n\t:from:to:cc:subject:message-id:references:mime-version\n\t:content-type:in-reply-to; s=default; bh=/zwjcUCsj75bvNF2GfvooVR\n\tgYYs=; b=qO5cGCk3qcFi5JTQw00N4CTIKNht41EDgBNwBDivpOc4rkOyZHFo7NB\n\tvEHgDtIucdON+fen2A8f+2FWcGL6zCR5opZh+OI0Ku7YgnPpJKWMbdp52Arx8xlD\n\tI1sJLw8tlHj6IyPYzcLnGuyi1ir4xDFWAFzUEcHYkNDeEqc4kjzw=","Mailing-List":"contact gcc-patches-help@gcc.gnu.org; run by ezmlm","Precedence":"bulk","List-Id":"<gcc-patches.gcc.gnu.org>","List-Unsubscribe":"<mailto:gcc-patches-unsubscribe-incoming=patchwork.ozlabs.org@gcc.gnu.org>","List-Archive":"<http://gcc.gnu.org/ml/gcc-patches/>","List-Post":"<mailto:gcc-patches@gcc.gnu.org>","List-Help":"<mailto:gcc-patches-help@gcc.gnu.org>","Sender":"gcc-patches-owner@gcc.gnu.org","X-Virus-Found":"No","X-Spam-SWARE-Status":"No, score=-2.1 required=5.0 tests=AWL, BAYES_00,\n\tRP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=","X-HELO":"gate.crashing.org","Date":"Thu, 7 Sep 2017 06:42:29 -0500","From":"Segher Boessenkool <segher@kernel.crashing.org>","To":"Jakub Jelinek <jakub@redhat.com>","Cc":"Richard Biener <rguenther@suse.de>, David Edelsohn <dje.gcc@gmail.com>,\n\tgcc-patches@gcc.gnu.org, Andrew Jenner <andrew@codesourcery.com>","Subject":"Re: [PATCH] Fix rs6000 sysv4 -fPIC hot/cold partitioning handling\n\t(PR target/81979)","Message-ID":"<20170907114228.GP13471@gate.crashing.org>","References":"<20170905212725.GA2291@tucnak>\n\t<20170906161007.GH13471@gate.crashing.org>\n\t<20170906162610.GQ2323@tucnak>\n\t<20170906164800.GJ13471@gate.crashing.org>\n\t<20170907094609.GU2323@tucnak>","Mime-Version":"1.0","Content-Type":"text/plain; charset=us-ascii","Content-Disposition":"inline","In-Reply-To":"<20170907094609.GU2323@tucnak>","User-Agent":"Mutt/1.4.2.3i","X-IsSubscribed":"yes"}}]