From patchwork Tue Jun 19 20:27:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Filippov X-Patchwork-Id: 931836 Return-Path: X-Original-To: incoming-buildroot@patchwork.ozlabs.org Delivered-To: patchwork-incoming-buildroot@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=busybox.net (client-ip=140.211.166.136; helo=silver.osuosl.org; envelope-from=buildroot-bounces@busybox.net; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Av6eoKet"; dkim-atps=neutral Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 419KJq56Gfz9s47 for ; Wed, 20 Jun 2018 06:27:39 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id F03812D5B3; Tue, 19 Jun 2018 20:27:36 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id y0VF1Brd6Coa; Tue, 19 Jun 2018 20:27:34 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by silver.osuosl.org (Postfix) with ESMTP id CB5652D5C1; Tue, 19 Jun 2018 20:27:34 +0000 (UTC) X-Original-To: buildroot@lists.busybox.net Delivered-To: buildroot@osuosl.org Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by ash.osuosl.org (Postfix) with ESMTP id D4CF61C0C3E for ; Tue, 19 Jun 2018 20:27:33 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id D17D92D5C1 for ; Tue, 19 Jun 2018 20:27:33 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id sUlA2JLLh8rw for ; Tue, 19 Jun 2018 20:27:33 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-lf0-f68.google.com (mail-lf0-f68.google.com [209.85.215.68]) by silver.osuosl.org (Postfix) with ESMTPS id 767532D5B3 for ; Tue, 19 Jun 2018 20:27:32 +0000 (UTC) Received: by mail-lf0-f68.google.com with SMTP id q11-v6so1469669lfc.7 for ; Tue, 19 Jun 2018 13:27:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=AUxJdB2//VJv0TA9eXG3GtsuQZ+ebJbtxhKCgewu5vQ=; b=Av6eoKetkyEi0nTzhtkOKPY0RTGNt9qgaC9Hb1n6r4bRj7Wt60B9pzw3AcFoG3n7MC zG3ue5wSTCTIxfJbqhsUXwSwBsSV25j+Gaqir1IayF8qGTaYgHT6/e9NsOZjmPaHCt5h AEUALRifyfOTgOc9KKfEEGPYtDeSsnjyxQGks2gM10QnmoeLkXBetnqTBOOzm6ywlssK v5fvkTtIurk1s2zuHrQOEcEWZ2x8DGj8s0rbqAAK84Zr6apOS15GZ4aCJ/m7XNEaQTMo c3XPum9E+t6LiwGGXEO7rIzv0AzY+JdxuoUzVC5uaHHOiuyYY7IHQwl/SQxFz0JoWwbg y69g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=AUxJdB2//VJv0TA9eXG3GtsuQZ+ebJbtxhKCgewu5vQ=; b=mvN/L1ZDHeFP3k6miE+rgNrnkG2zIZZJZ12+Kd2M/xbQPz6d7gG2DHkfGc/7zKkbJ2 M3CUsQ12tZJ6ADWbclaX/tiSKLgSWI2FPQMaKQh47gv6M633nnB2+1JdRIauWlJJdYf5 ZhXkypFo5VHmkV1eexLaesvz36aH9728KqNqfKIptNdtel42qd8j0baityGwONbSmcl1 nmv0ZUD5cd+bRUgzNUdiZonwmQG+80fvzqQ1rKOua3R5SkPZHPaNoNbHTmN1JQHaNLo3 Sq+odkpzQzDEiJprxqZT3hBBhwyQ09cucJ6Y9ILYTqv6ggqEfpbd1M8sNbOhmlWIcWW+ Pumw== X-Gm-Message-State: APt69E01AYjUQEtXulffMYZZkQdxqEOQJbbI0yqw3eAuaUXAsnVnsf8L ayHGSDY2RpX5kHIc+L6c77gi/A== X-Google-Smtp-Source: ADUXVKIyWHx5wOyQQHtyf2TPg8kViyKEPyOjEvFKQCKMboAVxGKmcshMt9BBonwXWjHwCYYzKqAK1g== X-Received: by 2002:a19:e413:: with SMTP id b19-v6mr7933258lfh.113.1529440049956; Tue, 19 Jun 2018 13:27:29 -0700 (PDT) Received: from octofox.cadence.com (jcmvbkbc-1-pt.tunnel.tserv24.sto1.ipv6.he.net. [2001:470:27:1fa::2]) by smtp.gmail.com with ESMTPSA id z1-v6sm83898ljz.69.2018.06.19.13.27.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 19 Jun 2018 13:27:29 -0700 (PDT) From: Max Filippov To: buildroot@uclibc.org Date: Tue, 19 Jun 2018 13:27:06 -0700 Message-Id: <20180619202706.17347-1-jcmvbkbc@gmail.com> X-Mailer: git-send-email 2.11.0 Subject: [Buildroot] [PATCH] gcc: fix uclibc build with gcc-8 for xtensa X-BeenThere: buildroot@busybox.net X-Mailman-Version: 2.1.24 Precedence: list List-Id: Discussion and development of buildroot List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Thomas Petazzoni , Romain Naour MIME-Version: 1.0 Errors-To: buildroot-bounces@busybox.net Sender: "buildroot" gcc-8.1 for xtensa miscompiles uClibc dynamic linker due to gcc PR target/65416. The build completes successfully, but the binary is non-functional because the following fragment in the _dl_get_ready_to_run in ld-uClibc.so overwrites register spill area on stack causing register corruption in the previous call frame and a subsequent crash: 419f: f0c1b2 addi a11, a1, -16 41a2: 1ba9 s32i.n a10, a11, 4 41a4: 0bc9 s32i.n a12, a11, 0 41a6: 5127f2 l32i a15, a7, 0x144 41a9: 1765b2 s32i a11, a5, 92 41ac: 4e2782 l32i a8, a7, 0x138 41af: 146af2 s32i a15, a10, 80 41b2: 001b10 movsp a1, a11 The crash terminates the init process and causes kernel panic. The fix prevents reordering of movsp opcode and any access to the stack frame memory and is applicable to all existing gcc versions.. Signed-off-by: Max Filippov --- .../gcc/6.4.0/871-xtensa-fix-PR-target-65416.patch | 101 +++++++++++++++++++++ .../7.3.0/0002-xtensa-fix-PR-target-65416.patch | 101 +++++++++++++++++++++ .../8.1.0/0004-xtensa-fix-PR-target-65416.patch | 101 +++++++++++++++++++++ 3 files changed, 303 insertions(+) create mode 100644 package/gcc/6.4.0/871-xtensa-fix-PR-target-65416.patch create mode 100644 package/gcc/7.3.0/0002-xtensa-fix-PR-target-65416.patch create mode 100644 package/gcc/8.1.0/0004-xtensa-fix-PR-target-65416.patch diff --git a/package/gcc/6.4.0/871-xtensa-fix-PR-target-65416.patch b/package/gcc/6.4.0/871-xtensa-fix-PR-target-65416.patch new file mode 100644 index 000000000000..7ead575439cc --- /dev/null +++ b/package/gcc/6.4.0/871-xtensa-fix-PR-target-65416.patch @@ -0,0 +1,101 @@ +From 87fda0741d210727672cba5e54a37a189e8ac04e Mon Sep 17 00:00:00 2001 +From: Max Filippov +Date: Sun, 17 Jun 2018 21:18:39 -0700 +Subject: [PATCH] xtensa: fix PR target/65416 + +The issue is caused by reordering of stack pointer update after stack +space allocation with instructions that write to the allocated stack +space. In windowed ABI register spill area for the previous call frame +is located just below the stack pointer and may be reloaded back into +the register file on movsp. +Implement allocate_stack pattern for windowed ABI configuration and +insert an instruction that prevents reordering of frame memory access +and stack pointer update. + +gcc/ +2018-06-19 Max Filippov + + * config/xtensa/xtensa.md (UNSPEC_FRAME_BLOCKAGE): New unspec + constant. + (allocate_stack, frame_blockage, *frame_blockage): New patterns. + +Signed-off-by: Max Filippov +Backported from: r261755 +--- + gcc/config/xtensa/xtensa.md | 46 +++++++++++++++++++++++++++++++++++++++++++++ + 1 file changed, 46 insertions(+) + +diff --git a/gcc/config/xtensa/xtensa.md b/gcc/config/xtensa/xtensa.md +index 84967dbedc08..209f839cfb0f 100644 +--- a/gcc/config/xtensa/xtensa.md ++++ b/gcc/config/xtensa/xtensa.md +@@ -38,6 +38,7 @@ + (UNSPEC_MEMW 11) + (UNSPEC_LSETUP_START 12) + (UNSPEC_LSETUP_END 13) ++ (UNSPEC_FRAME_BLOCKAGE 14) + + (UNSPECV_SET_FP 1) + (UNSPECV_ENTRY 2) +@@ -1676,6 +1677,32 @@ + + ;; Miscellaneous instructions. + ++;; In windowed ABI stack pointer adjustment must happen before any access ++;; to the space allocated on stack is allowed, otherwise register spill ++;; area may be clobbered. That's what frame blockage is supposed to enforce. ++ ++(define_expand "allocate_stack" ++ [(set (match_operand 0 "nonimmed_operand") ++ (minus (reg A1_REG) (match_operand 1 "add_operand"))) ++ (set (reg A1_REG) ++ (minus (reg A1_REG) (match_dup 1)))] ++ "TARGET_WINDOWED_ABI" ++{ ++ if (CONST_INT_P (operands[1])) ++ { ++ rtx neg_op0 = GEN_INT (-INTVAL (operands[1])); ++ emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx, neg_op0)); ++ } ++ else ++ { ++ emit_insn (gen_subsi3 (stack_pointer_rtx, stack_pointer_rtx, ++ operands[1])); ++ } ++ emit_move_insn (operands[0], virtual_stack_dynamic_rtx); ++ emit_insn (gen_frame_blockage ()); ++ DONE; ++}) ++ + (define_expand "prologue" + [(const_int 0)] + "" +@@ -1767,6 +1794,25 @@ + [(set_attr "length" "0") + (set_attr "type" "nop")]) + ++;; Do not schedule instructions accessing memory before this point. ++ ++(define_expand "frame_blockage" ++ [(set (match_dup 0) ++ (unspec:BLK [(match_dup 1)] UNSPEC_FRAME_BLOCKAGE))] ++ "" ++{ ++ operands[0] = gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (Pmode)); ++ MEM_VOLATILE_P (operands[0]) = 1; ++ operands[1] = stack_pointer_rtx; ++}) ++ ++(define_insn "*frame_blockage" ++ [(set (match_operand:BLK 0 "" "") ++ (unspec:BLK [(match_operand:SI 1 "" "")] UNSPEC_FRAME_BLOCKAGE))] ++ "" ++ "" ++ [(set_attr "length" "0")]) ++ + (define_insn "trap" + [(trap_if (const_int 1) (const_int 0))] + "" +-- +2.11.0 + diff --git a/package/gcc/7.3.0/0002-xtensa-fix-PR-target-65416.patch b/package/gcc/7.3.0/0002-xtensa-fix-PR-target-65416.patch new file mode 100644 index 000000000000..7ead575439cc --- /dev/null +++ b/package/gcc/7.3.0/0002-xtensa-fix-PR-target-65416.patch @@ -0,0 +1,101 @@ +From 87fda0741d210727672cba5e54a37a189e8ac04e Mon Sep 17 00:00:00 2001 +From: Max Filippov +Date: Sun, 17 Jun 2018 21:18:39 -0700 +Subject: [PATCH] xtensa: fix PR target/65416 + +The issue is caused by reordering of stack pointer update after stack +space allocation with instructions that write to the allocated stack +space. In windowed ABI register spill area for the previous call frame +is located just below the stack pointer and may be reloaded back into +the register file on movsp. +Implement allocate_stack pattern for windowed ABI configuration and +insert an instruction that prevents reordering of frame memory access +and stack pointer update. + +gcc/ +2018-06-19 Max Filippov + + * config/xtensa/xtensa.md (UNSPEC_FRAME_BLOCKAGE): New unspec + constant. + (allocate_stack, frame_blockage, *frame_blockage): New patterns. + +Signed-off-by: Max Filippov +Backported from: r261755 +--- + gcc/config/xtensa/xtensa.md | 46 +++++++++++++++++++++++++++++++++++++++++++++ + 1 file changed, 46 insertions(+) + +diff --git a/gcc/config/xtensa/xtensa.md b/gcc/config/xtensa/xtensa.md +index 84967dbedc08..209f839cfb0f 100644 +--- a/gcc/config/xtensa/xtensa.md ++++ b/gcc/config/xtensa/xtensa.md +@@ -38,6 +38,7 @@ + (UNSPEC_MEMW 11) + (UNSPEC_LSETUP_START 12) + (UNSPEC_LSETUP_END 13) ++ (UNSPEC_FRAME_BLOCKAGE 14) + + (UNSPECV_SET_FP 1) + (UNSPECV_ENTRY 2) +@@ -1676,6 +1677,32 @@ + + ;; Miscellaneous instructions. + ++;; In windowed ABI stack pointer adjustment must happen before any access ++;; to the space allocated on stack is allowed, otherwise register spill ++;; area may be clobbered. That's what frame blockage is supposed to enforce. ++ ++(define_expand "allocate_stack" ++ [(set (match_operand 0 "nonimmed_operand") ++ (minus (reg A1_REG) (match_operand 1 "add_operand"))) ++ (set (reg A1_REG) ++ (minus (reg A1_REG) (match_dup 1)))] ++ "TARGET_WINDOWED_ABI" ++{ ++ if (CONST_INT_P (operands[1])) ++ { ++ rtx neg_op0 = GEN_INT (-INTVAL (operands[1])); ++ emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx, neg_op0)); ++ } ++ else ++ { ++ emit_insn (gen_subsi3 (stack_pointer_rtx, stack_pointer_rtx, ++ operands[1])); ++ } ++ emit_move_insn (operands[0], virtual_stack_dynamic_rtx); ++ emit_insn (gen_frame_blockage ()); ++ DONE; ++}) ++ + (define_expand "prologue" + [(const_int 0)] + "" +@@ -1767,6 +1794,25 @@ + [(set_attr "length" "0") + (set_attr "type" "nop")]) + ++;; Do not schedule instructions accessing memory before this point. ++ ++(define_expand "frame_blockage" ++ [(set (match_dup 0) ++ (unspec:BLK [(match_dup 1)] UNSPEC_FRAME_BLOCKAGE))] ++ "" ++{ ++ operands[0] = gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (Pmode)); ++ MEM_VOLATILE_P (operands[0]) = 1; ++ operands[1] = stack_pointer_rtx; ++}) ++ ++(define_insn "*frame_blockage" ++ [(set (match_operand:BLK 0 "" "") ++ (unspec:BLK [(match_operand:SI 1 "" "")] UNSPEC_FRAME_BLOCKAGE))] ++ "" ++ "" ++ [(set_attr "length" "0")]) ++ + (define_insn "trap" + [(trap_if (const_int 1) (const_int 0))] + "" +-- +2.11.0 + diff --git a/package/gcc/8.1.0/0004-xtensa-fix-PR-target-65416.patch b/package/gcc/8.1.0/0004-xtensa-fix-PR-target-65416.patch new file mode 100644 index 000000000000..7ead575439cc --- /dev/null +++ b/package/gcc/8.1.0/0004-xtensa-fix-PR-target-65416.patch @@ -0,0 +1,101 @@ +From 87fda0741d210727672cba5e54a37a189e8ac04e Mon Sep 17 00:00:00 2001 +From: Max Filippov +Date: Sun, 17 Jun 2018 21:18:39 -0700 +Subject: [PATCH] xtensa: fix PR target/65416 + +The issue is caused by reordering of stack pointer update after stack +space allocation with instructions that write to the allocated stack +space. In windowed ABI register spill area for the previous call frame +is located just below the stack pointer and may be reloaded back into +the register file on movsp. +Implement allocate_stack pattern for windowed ABI configuration and +insert an instruction that prevents reordering of frame memory access +and stack pointer update. + +gcc/ +2018-06-19 Max Filippov + + * config/xtensa/xtensa.md (UNSPEC_FRAME_BLOCKAGE): New unspec + constant. + (allocate_stack, frame_blockage, *frame_blockage): New patterns. + +Signed-off-by: Max Filippov +Backported from: r261755 +--- + gcc/config/xtensa/xtensa.md | 46 +++++++++++++++++++++++++++++++++++++++++++++ + 1 file changed, 46 insertions(+) + +diff --git a/gcc/config/xtensa/xtensa.md b/gcc/config/xtensa/xtensa.md +index 84967dbedc08..209f839cfb0f 100644 +--- a/gcc/config/xtensa/xtensa.md ++++ b/gcc/config/xtensa/xtensa.md +@@ -38,6 +38,7 @@ + (UNSPEC_MEMW 11) + (UNSPEC_LSETUP_START 12) + (UNSPEC_LSETUP_END 13) ++ (UNSPEC_FRAME_BLOCKAGE 14) + + (UNSPECV_SET_FP 1) + (UNSPECV_ENTRY 2) +@@ -1676,6 +1677,32 @@ + + ;; Miscellaneous instructions. + ++;; In windowed ABI stack pointer adjustment must happen before any access ++;; to the space allocated on stack is allowed, otherwise register spill ++;; area may be clobbered. That's what frame blockage is supposed to enforce. ++ ++(define_expand "allocate_stack" ++ [(set (match_operand 0 "nonimmed_operand") ++ (minus (reg A1_REG) (match_operand 1 "add_operand"))) ++ (set (reg A1_REG) ++ (minus (reg A1_REG) (match_dup 1)))] ++ "TARGET_WINDOWED_ABI" ++{ ++ if (CONST_INT_P (operands[1])) ++ { ++ rtx neg_op0 = GEN_INT (-INTVAL (operands[1])); ++ emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx, neg_op0)); ++ } ++ else ++ { ++ emit_insn (gen_subsi3 (stack_pointer_rtx, stack_pointer_rtx, ++ operands[1])); ++ } ++ emit_move_insn (operands[0], virtual_stack_dynamic_rtx); ++ emit_insn (gen_frame_blockage ()); ++ DONE; ++}) ++ + (define_expand "prologue" + [(const_int 0)] + "" +@@ -1767,6 +1794,25 @@ + [(set_attr "length" "0") + (set_attr "type" "nop")]) + ++;; Do not schedule instructions accessing memory before this point. ++ ++(define_expand "frame_blockage" ++ [(set (match_dup 0) ++ (unspec:BLK [(match_dup 1)] UNSPEC_FRAME_BLOCKAGE))] ++ "" ++{ ++ operands[0] = gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (Pmode)); ++ MEM_VOLATILE_P (operands[0]) = 1; ++ operands[1] = stack_pointer_rtx; ++}) ++ ++(define_insn "*frame_blockage" ++ [(set (match_operand:BLK 0 "" "") ++ (unspec:BLK [(match_operand:SI 1 "" "")] UNSPEC_FRAME_BLOCKAGE))] ++ "" ++ "" ++ [(set_attr "length" "0")]) ++ + (define_insn "trap" + [(trap_if (const_int 1) (const_int 0))] + "" +-- +2.11.0 +