summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexey Neyman <stilor@att.net>2016-11-23 18:03:16 (GMT)
committerGitHub <noreply@github.com>2016-11-23 18:03:16 (GMT)
commit699a54d8cedef2883ca6834feed99f8f2b077332 (patch)
treec8fec4b69332c18562161cb0a6fff6cfa0723bcf
parent0946ce59a09609b743b7dba40f7212778011f286 (diff)
parent51b4a509db982349af6c9b2072b7a6fad0547570 (diff)
Merge pull request #465 from jcmvbkbc/xtensa-endian
Xtensa fixes
-rw-r--r--config/arch/xtensa.in2
-rw-r--r--patches/gcc/5.4.0/875-xtensa-fix-xtensa_fallback_frame_state-for-call0-ABI.patch108
-rw-r--r--patches/gcc/5.4.0/876-xtensa-fix-libgcc-build-with-text-section-literals.patch67
-rw-r--r--patches/gcc/5.4.0/877-xtensa-don-t-use-unwind-dw2-fde-dip-with-elf-targets.patch62
-rw-r--r--patches/gcc/6.2.0/870-xtensa-don-t-use-unwind-dw2-fde-dip-with-elf-targets.patch62
-rw-r--r--patches/gcc/6.2.0/871-xtensa-Fix-PR-target-78118.patch318
-rw-r--r--samples/xtensa-fsf-linux-uclibc/crosstool.config (renamed from samples/xtensa-unknown-linux-uclibc/crosstool.config)3
-rw-r--r--samples/xtensa-fsf-linux-uclibc/reported.by (renamed from samples/xtensa-unknown-linux-uclibc/reported.by)0
-rw-r--r--scripts/build/arch/xtensa.sh2
9 files changed, 624 insertions, 0 deletions
diff --git a/config/arch/xtensa.in b/config/arch/xtensa.in
index e08b842..3ffa4e8 100644
--- a/config/arch/xtensa.in
+++ b/config/arch/xtensa.in
@@ -1,6 +1,8 @@
# xtensa specific configuration file
## select ARCH_SUPPORTS_32
+## select ARCH_SUPPORTS_BOTH_ENDIAN
+## select ARCH_DEFAULT_LE
## select ARCH_SUPPORTS_BOTH_MMU
## select ARCH_DEFAULT_HAS_MMU
##
diff --git a/patches/gcc/5.4.0/875-xtensa-fix-xtensa_fallback_frame_state-for-call0-ABI.patch b/patches/gcc/5.4.0/875-xtensa-fix-xtensa_fallback_frame_state-for-call0-ABI.patch
new file mode 100644
index 0000000..d128596
--- /dev/null
+++ b/patches/gcc/5.4.0/875-xtensa-fix-xtensa_fallback_frame_state-for-call0-ABI.patch
@@ -0,0 +1,108 @@
+From 7d3692c6933f7ff87bf110dede8e33e922b164c6 Mon Sep 17 00:00:00 2001
+From: jcmvbkbc <jcmvbkbc@138bc75d-0d04-0410-961f-82ee72b054a4>
+Date: Tue, 15 Sep 2015 19:30:32 +0000
+Subject: [PATCH] xtensa: fix xtensa_fallback_frame_state for call0 ABI
+
+2015-09-15 Max Filippov <jcmvbkbc@gmail.com>
+gcc/
+ * config/xtensa/xtensa.h (DWARF_ALT_FRAME_RETURN_COLUMN): New
+ definition.
+ (DWARF_FRAME_REGISTERS): Reserve space for one extra register in
+ call0 ABI.
+
+libgcc/
+ * config/xtensa/linux-unwind.h (xtensa_fallback_frame_state):
+ Add support for call0 ABI.
+
+git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@227809 138bc75d-0d04-0410-961f-82ee72b054a4
+
+Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
+---
+ gcc/config/xtensa/xtensa.h | 4 +++-
+ libgcc/config/xtensa/linux-unwind.h | 30 ++++++++++++++++++++++++++++--
+ 2 files changed, 31 insertions(+), 3 deletions(-)
+
+diff --git a/gcc/config/xtensa/xtensa.h b/gcc/config/xtensa/xtensa.h
+index 584080b..e165def 100644
+--- a/gcc/config/xtensa/xtensa.h
++++ b/gcc/config/xtensa/xtensa.h
+@@ -813,7 +813,9 @@ typedef struct xtensa_args
+ for debugging. */
+ #define INCOMING_RETURN_ADDR_RTX gen_rtx_REG (Pmode, 0)
+ #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (0)
+-#define DWARF_FRAME_REGISTERS 16
++#define DWARF_ALT_FRAME_RETURN_COLUMN 16
++#define DWARF_FRAME_REGISTERS (DWARF_ALT_FRAME_RETURN_COLUMN \
++ + (TARGET_WINDOWED_ABI ? 0 : 1))
+ #define EH_RETURN_DATA_REGNO(N) ((N) < 2 ? (N) + 2 : INVALID_REGNUM)
+ #define ASM_PREFERRED_EH_DATA_FORMAT(CODE, GLOBAL) \
+ (flag_pic \
+diff --git a/libgcc/config/xtensa/linux-unwind.h b/libgcc/config/xtensa/linux-unwind.h
+index 9daf738..9a67b5d 100644
+--- a/libgcc/config/xtensa/linux-unwind.h
++++ b/libgcc/config/xtensa/linux-unwind.h
+@@ -52,7 +52,6 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
+ #define ENTRY_BYTE 0x36
+ #endif
+
+-#ifdef __XTENSA_WINDOWED_ABI__
+ #define MD_FALLBACK_FRAME_STATE_FOR xtensa_fallback_frame_state
+
+ static _Unwind_Reason_Code
+@@ -61,6 +60,10 @@ xtensa_fallback_frame_state (struct _Unwind_Context *context,
+ {
+ unsigned char *pc = context->ra;
+ struct sigcontext *sc;
++#if defined(__XTENSA_CALL0_ABI__)
++ _Unwind_Ptr new_cfa;
++ int i;
++#endif
+
+ struct rt_sigframe {
+ siginfo_t info;
+@@ -76,6 +79,7 @@ xtensa_fallback_frame_state (struct _Unwind_Context *context,
+ || pc[5] != SYSC_BYTE2)
+ return _URC_END_OF_STACK;
+
++#if defined(__XTENSA_WINDOWED_ABI__)
+ rt_ = context->sp;
+ sc = &rt_->uc.uc_mcontext;
+ fs->signal_regs = (_Unwind_Word *) sc->sc_a;
+@@ -90,11 +94,33 @@ xtensa_fallback_frame_state (struct _Unwind_Context *context,
+ }
+ else
+ fs->signal_ra = sc->sc_pc;
++#elif defined(__XTENSA_CALL0_ABI__)
++ rt_ = context->cfa;
++ sc = &rt_->uc.uc_mcontext;
++
++ new_cfa = (_Unwind_Ptr) sc;
++ fs->regs.cfa_how = CFA_REG_OFFSET;
++ fs->regs.cfa_reg = __LIBGCC_STACK_POINTER_REGNUM__;
++ fs->regs.cfa_offset = new_cfa - (_Unwind_Ptr) context->cfa;
++
++ for (i = 0; i < 16; i++)
++ {
++ fs->regs.reg[i].how = REG_SAVED_OFFSET;
++ fs->regs.reg[i].loc.offset = (_Unwind_Ptr) &(sc->sc_a[i]) - new_cfa;
++ }
++
++ fs->regs.reg[__LIBGCC_DWARF_ALT_FRAME_RETURN_COLUMN__].how =
++ REG_SAVED_VAL_OFFSET;
++ fs->regs.reg[__LIBGCC_DWARF_ALT_FRAME_RETURN_COLUMN__].loc.offset =
++ (_Unwind_Ptr) (sc->sc_pc) - new_cfa;
++ fs->retaddr_column = __LIBGCC_DWARF_ALT_FRAME_RETURN_COLUMN__;
++#else
++#error Unsupported Xtensa ABI
++#endif
+
+ fs->signal_frame = 1;
+ return _URC_NO_REASON;
+ }
+
+-#endif /* __XTENSA_WINDOWED_ABI__ */
+
+ #endif /* ifdef inhibit_libc */
+--
+2.1.4
+
diff --git a/patches/gcc/5.4.0/876-xtensa-fix-libgcc-build-with-text-section-literals.patch b/patches/gcc/5.4.0/876-xtensa-fix-libgcc-build-with-text-section-literals.patch
new file mode 100644
index 0000000..4b2334a
--- /dev/null
+++ b/patches/gcc/5.4.0/876-xtensa-fix-libgcc-build-with-text-section-literals.patch
@@ -0,0 +1,67 @@
+From 44fbad9f8bed55f690f251b530ab38df1e696d95 Mon Sep 17 00:00:00 2001
+From: jcmvbkbc <jcmvbkbc@138bc75d-0d04-0410-961f-82ee72b054a4>
+Date: Wed, 17 Feb 2016 20:21:48 +0000
+Subject: [PATCH] xtensa: fix libgcc build with --text-section-literals
+
+Functions __muldf3_aux, __divdf3_aux, __mulsf3_aux and __divsf3_aux
+don't start with leaf_entry, so they need explicit .literal_position,
+otherwise libgcc build fails in the presence of --text-section-literals.
+
+2016-02-17 Max Filippov <jcmvbkbc@gmail.com>
+libgcc/
+ * config/xtensa/ieee754-df.S (__muldf3_aux, __divdf3_aux): Add
+ .literal_position before the function.
+ * config/xtensa/ieee754-sf.S (__mulsf3_aux, __divsf3_aux):
+ Likewise.
+
+git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@233505 138bc75d-0d04-0410-961f-82ee72b054a4
+
+Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
+---
+ libgcc/config/xtensa/ieee754-df.S | 2 ++
+ libgcc/config/xtensa/ieee754-sf.S | 2 ++
+ 2 files changed, 4 insertions(+)
+
+diff --git a/libgcc/config/xtensa/ieee754-df.S b/libgcc/config/xtensa/ieee754-df.S
+index a7ae209..26f2abd 100644
+--- a/libgcc/config/xtensa/ieee754-df.S
++++ b/libgcc/config/xtensa/ieee754-df.S
+@@ -606,6 +606,7 @@ __subdf3:
+ #define XCHAL_NO_MUL 1
+ #endif
+
++ .literal_position
+ __muldf3_aux:
+
+ /* Handle unusual cases (zeros, subnormals, NaNs and Infinities).
+@@ -1216,6 +1217,7 @@ __muldf3:
+
+ #ifdef L_divdf3
+
++ .literal_position
+ /* Division */
+ __divdf3_aux:
+
+diff --git a/libgcc/config/xtensa/ieee754-sf.S b/libgcc/config/xtensa/ieee754-sf.S
+index 7e397dc..a5e6e3c 100644
+--- a/libgcc/config/xtensa/ieee754-sf.S
++++ b/libgcc/config/xtensa/ieee754-sf.S
+@@ -487,6 +487,7 @@ __subsf3:
+ #define XCHAL_NO_MUL 1
+ #endif
+
++ .literal_position
+ __mulsf3_aux:
+
+ /* Handle unusual cases (zeros, subnormals, NaNs and Infinities).
+@@ -884,6 +885,7 @@ __mulsf3:
+
+ #ifdef L_divsf3
+
++ .literal_position
+ /* Division */
+ __divsf3_aux:
+
+--
+2.1.4
+
diff --git a/patches/gcc/5.4.0/877-xtensa-don-t-use-unwind-dw2-fde-dip-with-elf-targets.patch b/patches/gcc/5.4.0/877-xtensa-don-t-use-unwind-dw2-fde-dip-with-elf-targets.patch
new file mode 100644
index 0000000..6e0ce6e
--- /dev/null
+++ b/patches/gcc/5.4.0/877-xtensa-don-t-use-unwind-dw2-fde-dip-with-elf-targets.patch
@@ -0,0 +1,62 @@
+From d28554ee61a1ab1263274d66386e4051bca0ce05 Mon Sep 17 00:00:00 2001
+From: jcmvbkbc <jcmvbkbc@138bc75d-0d04-0410-961f-82ee72b054a4>
+Date: Tue, 18 Oct 2016 19:12:19 +0000
+Subject: [PATCH] xtensa: don't use unwind-dw2-fde-dip with elf targets
+
+Define LIB2ADDEH_XTENSA_UNWIND_DW2_FDE to unwind-dw2-fde.c in
+xtensa/t-elf and to unwind-dw2-fde-dip.c in xtensa/t-linux and use
+LIB2ADDEH_XTENSA_UNWIND_DW2_FDE in LIB2ADDEH definition.
+
+This fixes build for elf target with windowed xtensa core that currently
+breaks with the following error message:
+
+ unwind-dw2-fde-dip.c:36:40: fatal error: elf.h: No such file or directory
+
+2016-10-18 Max Filippov <jcmvbkbc@gmail.com>
+libgcc/
+ * config/xtensa/t-elf (LIB2ADDEH_XTENSA_UNWIND_DW2_FDE): New
+ definition.
+ * config/xtensa/t-linux (LIB2ADDEH_XTENSA_UNWIND_DW2_FDE): New
+ definition.
+ * config/xtensa/t-windowed (LIB2ADDEH): Use
+ LIB2ADDEH_XTENSA_UNWIND_DW2_FDE defined by either xtensa/t-elf
+ or xtensa/t-linux.
+
+git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@241313 138bc75d-0d04-0410-961f-82ee72b054a4
+
+Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
+---
+ libgcc/config/xtensa/t-elf | 2 ++
+ libgcc/config/xtensa/t-linux | 2 ++
+ libgcc/config/xtensa/t-windowed | 2 +-
+ 3 files changed, 5 insertions(+), 1 deletion(-)
+
+diff --git a/libgcc/config/xtensa/t-elf b/libgcc/config/xtensa/t-elf
+index 59d5121..967cf9b 100644
+--- a/libgcc/config/xtensa/t-elf
++++ b/libgcc/config/xtensa/t-elf
+@@ -3,3 +3,5 @@ CRTSTUFF_T_CFLAGS += -mlongcalls
+ CRTSTUFF_T_CFLAGS_S += -mlongcalls
+
+ HOST_LIBGCC2_CFLAGS += -mlongcalls
++
++LIB2ADDEH_XTENSA_UNWIND_DW2_FDE = $(srcdir)/unwind-dw2-fde.c
+diff --git a/libgcc/config/xtensa/t-linux b/libgcc/config/xtensa/t-linux
+index 6f4ae89..412ecca 100644
+--- a/libgcc/config/xtensa/t-linux
++++ b/libgcc/config/xtensa/t-linux
+@@ -1 +1,3 @@
+ SHLIB_MAPFILES += $(srcdir)/config/xtensa/libgcc-glibc.ver
++
++LIB2ADDEH_XTENSA_UNWIND_DW2_FDE = $(srcdir)/unwind-dw2-fde-dip.c
+diff --git a/libgcc/config/xtensa/t-windowed b/libgcc/config/xtensa/t-windowed
+index a99156c..f140136 100644
+--- a/libgcc/config/xtensa/t-windowed
++++ b/libgcc/config/xtensa/t-windowed
+@@ -1,2 +1,2 @@
+ LIB2ADDEH = $(srcdir)/config/xtensa/unwind-dw2-xtensa.c \
+- $(srcdir)/unwind-dw2-fde-dip.c $(srcdir)/unwind-sjlj.c $(srcdir)/unwind-c.c
++ $(LIB2ADDEH_XTENSA_UNWIND_DW2_FDE) $(srcdir)/unwind-sjlj.c $(srcdir)/unwind-c.c
+--
+2.1.4
+
diff --git a/patches/gcc/6.2.0/870-xtensa-don-t-use-unwind-dw2-fde-dip-with-elf-targets.patch b/patches/gcc/6.2.0/870-xtensa-don-t-use-unwind-dw2-fde-dip-with-elf-targets.patch
new file mode 100644
index 0000000..6e0ce6e
--- /dev/null
+++ b/patches/gcc/6.2.0/870-xtensa-don-t-use-unwind-dw2-fde-dip-with-elf-targets.patch
@@ -0,0 +1,62 @@
+From d28554ee61a1ab1263274d66386e4051bca0ce05 Mon Sep 17 00:00:00 2001
+From: jcmvbkbc <jcmvbkbc@138bc75d-0d04-0410-961f-82ee72b054a4>
+Date: Tue, 18 Oct 2016 19:12:19 +0000
+Subject: [PATCH] xtensa: don't use unwind-dw2-fde-dip with elf targets
+
+Define LIB2ADDEH_XTENSA_UNWIND_DW2_FDE to unwind-dw2-fde.c in
+xtensa/t-elf and to unwind-dw2-fde-dip.c in xtensa/t-linux and use
+LIB2ADDEH_XTENSA_UNWIND_DW2_FDE in LIB2ADDEH definition.
+
+This fixes build for elf target with windowed xtensa core that currently
+breaks with the following error message:
+
+ unwind-dw2-fde-dip.c:36:40: fatal error: elf.h: No such file or directory
+
+2016-10-18 Max Filippov <jcmvbkbc@gmail.com>
+libgcc/
+ * config/xtensa/t-elf (LIB2ADDEH_XTENSA_UNWIND_DW2_FDE): New
+ definition.
+ * config/xtensa/t-linux (LIB2ADDEH_XTENSA_UNWIND_DW2_FDE): New
+ definition.
+ * config/xtensa/t-windowed (LIB2ADDEH): Use
+ LIB2ADDEH_XTENSA_UNWIND_DW2_FDE defined by either xtensa/t-elf
+ or xtensa/t-linux.
+
+git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@241313 138bc75d-0d04-0410-961f-82ee72b054a4
+
+Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
+---
+ libgcc/config/xtensa/t-elf | 2 ++
+ libgcc/config/xtensa/t-linux | 2 ++
+ libgcc/config/xtensa/t-windowed | 2 +-
+ 3 files changed, 5 insertions(+), 1 deletion(-)
+
+diff --git a/libgcc/config/xtensa/t-elf b/libgcc/config/xtensa/t-elf
+index 59d5121..967cf9b 100644
+--- a/libgcc/config/xtensa/t-elf
++++ b/libgcc/config/xtensa/t-elf
+@@ -3,3 +3,5 @@ CRTSTUFF_T_CFLAGS += -mlongcalls
+ CRTSTUFF_T_CFLAGS_S += -mlongcalls
+
+ HOST_LIBGCC2_CFLAGS += -mlongcalls
++
++LIB2ADDEH_XTENSA_UNWIND_DW2_FDE = $(srcdir)/unwind-dw2-fde.c
+diff --git a/libgcc/config/xtensa/t-linux b/libgcc/config/xtensa/t-linux
+index 6f4ae89..412ecca 100644
+--- a/libgcc/config/xtensa/t-linux
++++ b/libgcc/config/xtensa/t-linux
+@@ -1 +1,3 @@
+ SHLIB_MAPFILES += $(srcdir)/config/xtensa/libgcc-glibc.ver
++
++LIB2ADDEH_XTENSA_UNWIND_DW2_FDE = $(srcdir)/unwind-dw2-fde-dip.c
+diff --git a/libgcc/config/xtensa/t-windowed b/libgcc/config/xtensa/t-windowed
+index a99156c..f140136 100644
+--- a/libgcc/config/xtensa/t-windowed
++++ b/libgcc/config/xtensa/t-windowed
+@@ -1,2 +1,2 @@
+ LIB2ADDEH = $(srcdir)/config/xtensa/unwind-dw2-xtensa.c \
+- $(srcdir)/unwind-dw2-fde-dip.c $(srcdir)/unwind-sjlj.c $(srcdir)/unwind-c.c
++ $(LIB2ADDEH_XTENSA_UNWIND_DW2_FDE) $(srcdir)/unwind-sjlj.c $(srcdir)/unwind-c.c
+--
+2.1.4
+
diff --git a/patches/gcc/6.2.0/871-xtensa-Fix-PR-target-78118.patch b/patches/gcc/6.2.0/871-xtensa-Fix-PR-target-78118.patch
new file mode 100644
index 0000000..c6ae103
--- /dev/null
+++ b/patches/gcc/6.2.0/871-xtensa-Fix-PR-target-78118.patch
@@ -0,0 +1,318 @@
+From bdda1689faf608ad7c83b5bd2e21a236b0047579 Mon Sep 17 00:00:00 2001
+From: Max Filippov <jcmvbkbc@gmail.com>
+Date: Wed, 26 Oct 2016 08:02:51 +0000
+Subject: [PATCH] xtensa: Fix PR target/78118
+
+It started failing after the following commit: 32e90dc6a0cda45 ("PR
+rtl-optimization/61047").
+
+The change that made xtensa backend go ICE looks completely unrelated,
+and indeed, the issue is caused by the side effect of
+compute_frame_size() function call hidden in the
+INITIAL_ELIMINATION_OFFSET macro. This call updates the value of the
+xtensa_current_frame_size static variable, used in "return" instruction
+predicate. Prior to the change the value of xtensa_current_frame_size was
+set to 0 after the end of epilogue generation, which enabled the "return"
+instruction for the CALL0 ABI, but after the change the additional
+INITIAL_ELIMINATION_OFFSET calls make xtensa_current_frame_size non-zero
+and "return" pattern unavailable.
+
+Get rid of the global xtensa_current_frame_size and
+xtensa_callee_save_size variables by moving them into the
+machine_function structure. Implement predicate for the "return" pattern
+as a function. Don't communicate completion of epilogue generation
+through zeroing of xtensa_current_frame_size, add explicit epilogue_done
+variable to the machine_function structure. Don't update stack frame
+layout after the completion of reload.
+
+2016-10-26 Max Filippov <jcmvbkbc@gmail.com>
+gcc/
+ * config/xtensa/xtensa-protos.h
+ (xtensa_use_return_instruction_p): New prototype.
+ * config/xtensa/xtensa.c (xtensa_current_frame_size,
+ xtensa_callee_save_size): Remove.
+ (struct machine_function): Add new fields: current_frame_size,
+ callee_save_size, frame_laid_out and epilogue_done.
+ (compute_frame_size, xtensa_expand_prologue,
+ xtensa_expand_epilogue): Replace xtensa_callee_save_size with
+ cfun->machine->callee_save_size and xtensa_current_frame_size
+ with cfun->machine->current_frame_size.
+ (compute_frame_size): Update cfun->machine->frame_laid_out and
+ don't update frame layout after reload completion.
+ (xtensa_expand_epilogue): Set cfun->machine->epilogue_done
+ instead of zeroing xtensa_current_frame_size.
+ (xtensa_use_return_instruction_p): New function.
+ * config/xtensa/xtensa.h (xtensa_current_frame_size): Remove
+ declaration.
+ (INITIAL_ELIMINATION_OFFSET): Use return value of
+ compute_frame_size instead of xtensa_current_frame_size value.
+ * config/xtensa/xtensa.md ("return" pattern): Use new predicate
+ function xtensa_use_return_instruction_p instead of inline code.
+
+Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
+---
+ gcc/config/xtensa/xtensa-protos.h | 1 +
+ gcc/config/xtensa/xtensa.c | 82 ++++++++++++++++++++++++---------------
+ gcc/config/xtensa/xtensa.h | 6 +--
+ gcc/config/xtensa/xtensa.md | 2 +-
+ 4 files changed, 55 insertions(+), 36 deletions(-)
+
+diff --git a/gcc/config/xtensa/xtensa-protos.h b/gcc/config/xtensa/xtensa-protos.h
+index f2ca526..873557f 100644
+--- a/gcc/config/xtensa/xtensa-protos.h
++++ b/gcc/config/xtensa/xtensa-protos.h
+@@ -68,6 +68,7 @@ extern rtx xtensa_return_addr (int, rtx);
+ extern void xtensa_setup_frame_addresses (void);
+ extern int xtensa_dbx_register_number (int);
+ extern long compute_frame_size (int);
++extern bool xtensa_use_return_instruction_p (void);
+ extern void xtensa_expand_prologue (void);
+ extern void xtensa_expand_epilogue (void);
+ extern void order_regs_for_local_alloc (void);
+diff --git a/gcc/config/xtensa/xtensa.c b/gcc/config/xtensa/xtensa.c
+index 64d089b..e49f784 100644
+--- a/gcc/config/xtensa/xtensa.c
++++ b/gcc/config/xtensa/xtensa.c
+@@ -78,11 +78,6 @@ enum internal_test
+ can support a given mode. */
+ char xtensa_hard_regno_mode_ok[(int) MAX_MACHINE_MODE][FIRST_PSEUDO_REGISTER];
+
+-/* Current frame size calculated by compute_frame_size. */
+-unsigned xtensa_current_frame_size;
+-/* Callee-save area size in the current frame calculated by compute_frame_size. */
+-int xtensa_callee_save_size;
+-
+ /* Largest block move to handle in-line. */
+ #define LARGEST_MOVE_RATIO 15
+
+@@ -94,6 +89,13 @@ struct GTY(()) machine_function
+ bool vararg_a7;
+ rtx vararg_a7_copy;
+ rtx_insn *set_frame_ptr_insn;
++ /* Current frame size calculated by compute_frame_size. */
++ unsigned current_frame_size;
++ /* Callee-save area size in the current frame calculated by
++ compute_frame_size. */
++ int callee_save_size;
++ bool frame_laid_out;
++ bool epilogue_done;
+ };
+
+ /* Vector, indexed by hard register number, which contains 1 for a
+@@ -2628,24 +2630,29 @@ compute_frame_size (int size)
+ {
+ int regno;
+
++ if (reload_completed && cfun->machine->frame_laid_out)
++ return cfun->machine->current_frame_size;
++
+ /* Add space for the incoming static chain value. */
+ if (cfun->static_chain_decl != NULL)
+ size += (1 * UNITS_PER_WORD);
+
+- xtensa_callee_save_size = 0;
++ cfun->machine->callee_save_size = 0;
+ for (regno = 0; regno < FIRST_PSEUDO_REGISTER; ++regno)
+ {
+ if (xtensa_call_save_reg(regno))
+- xtensa_callee_save_size += UNITS_PER_WORD;
++ cfun->machine->callee_save_size += UNITS_PER_WORD;
+ }
+
+- xtensa_current_frame_size =
++ cfun->machine->current_frame_size =
+ XTENSA_STACK_ALIGN (size
+- + xtensa_callee_save_size
++ + cfun->machine->callee_save_size
+ + crtl->outgoing_args_size
+ + (WINDOW_SIZE * UNITS_PER_WORD));
+- xtensa_callee_save_size = XTENSA_STACK_ALIGN (xtensa_callee_save_size);
+- return xtensa_current_frame_size;
++ cfun->machine->callee_save_size =
++ XTENSA_STACK_ALIGN (cfun->machine->callee_save_size);
++ cfun->machine->frame_laid_out = true;
++ return cfun->machine->current_frame_size;
+ }
+
+
+@@ -2696,6 +2703,7 @@ xtensa_expand_prologue (void)
+ {
+ int regno;
+ HOST_WIDE_INT offset = 0;
++ int callee_save_size = cfun->machine->callee_save_size;
+
+ /* -128 is a limit of single addi instruction. */
+ if (total_size > 0 && total_size <= 128)
+@@ -2709,7 +2717,7 @@ xtensa_expand_prologue (void)
+ add_reg_note (insn, REG_FRAME_RELATED_EXPR, note_rtx);
+ offset = total_size - UNITS_PER_WORD;
+ }
+- else if (xtensa_callee_save_size)
++ else if (callee_save_size)
+ {
+ /* 1020 is maximal s32i offset, if the frame is bigger than that
+ * we move sp to the end of callee-saved save area, save and then
+@@ -2717,13 +2725,13 @@ xtensa_expand_prologue (void)
+ if (total_size > 1024)
+ {
+ insn = emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx,
+- GEN_INT (-xtensa_callee_save_size)));
++ GEN_INT (-callee_save_size)));
+ RTX_FRAME_RELATED_P (insn) = 1;
+ note_rtx = gen_rtx_SET (stack_pointer_rtx,
+ plus_constant (Pmode, stack_pointer_rtx,
+- -xtensa_callee_save_size));
++ -callee_save_size));
+ add_reg_note (insn, REG_FRAME_RELATED_EXPR, note_rtx);
+- offset = xtensa_callee_save_size - UNITS_PER_WORD;
++ offset = callee_save_size - UNITS_PER_WORD;
+ }
+ else
+ {
+@@ -2759,13 +2767,13 @@ xtensa_expand_prologue (void)
+ {
+ rtx tmp_reg = gen_rtx_REG (Pmode, A9_REG);
+ emit_move_insn (tmp_reg, GEN_INT (total_size -
+- xtensa_callee_save_size));
++ callee_save_size));
+ insn = emit_insn (gen_subsi3 (stack_pointer_rtx,
+ stack_pointer_rtx, tmp_reg));
+ RTX_FRAME_RELATED_P (insn) = 1;
+ note_rtx = gen_rtx_SET (stack_pointer_rtx,
+ plus_constant (Pmode, stack_pointer_rtx,
+- xtensa_callee_save_size -
++ callee_save_size -
+ total_size));
+ add_reg_note (insn, REG_FRAME_RELATED_EXPR, note_rtx);
+ }
+@@ -2833,21 +2841,21 @@ xtensa_expand_epilogue (void)
+ int regno;
+ HOST_WIDE_INT offset;
+
+- if (xtensa_current_frame_size > (frame_pointer_needed ? 127 : 1024))
++ if (cfun->machine->current_frame_size > (frame_pointer_needed ? 127 : 1024))
+ {
+ rtx tmp_reg = gen_rtx_REG (Pmode, A9_REG);
+- emit_move_insn (tmp_reg, GEN_INT (xtensa_current_frame_size -
+- xtensa_callee_save_size));
++ emit_move_insn (tmp_reg, GEN_INT (cfun->machine->current_frame_size -
++ cfun->machine->callee_save_size));
+ emit_insn (gen_addsi3 (stack_pointer_rtx, frame_pointer_needed ?
+ hard_frame_pointer_rtx : stack_pointer_rtx,
+ tmp_reg));
+- offset = xtensa_callee_save_size - UNITS_PER_WORD;
++ offset = cfun->machine->callee_save_size - UNITS_PER_WORD;
+ }
+ else
+ {
+ if (frame_pointer_needed)
+ emit_move_insn (stack_pointer_rtx, hard_frame_pointer_rtx);
+- offset = xtensa_current_frame_size - UNITS_PER_WORD;
++ offset = cfun->machine->current_frame_size - UNITS_PER_WORD;
+ }
+
+ /* Prevent reordering of saved a0 update and loading it back from
+@@ -2867,16 +2875,16 @@ xtensa_expand_epilogue (void)
+ }
+ }
+
+- if (xtensa_current_frame_size > 0)
++ if (cfun->machine->current_frame_size > 0)
+ {
+ if (frame_pointer_needed || /* always reachable with addi */
+- xtensa_current_frame_size > 1024 ||
+- xtensa_current_frame_size <= 127)
++ cfun->machine->current_frame_size > 1024 ||
++ cfun->machine->current_frame_size <= 127)
+ {
+- if (xtensa_current_frame_size <= 127)
+- offset = xtensa_current_frame_size;
++ if (cfun->machine->current_frame_size <= 127)
++ offset = cfun->machine->current_frame_size;
+ else
+- offset = xtensa_callee_save_size;
++ offset = cfun->machine->callee_save_size;
+
+ emit_insn (gen_addsi3 (stack_pointer_rtx,
+ stack_pointer_rtx,
+@@ -2885,7 +2893,8 @@ xtensa_expand_epilogue (void)
+ else
+ {
+ rtx tmp_reg = gen_rtx_REG (Pmode, A9_REG);
+- emit_move_insn (tmp_reg, GEN_INT (xtensa_current_frame_size));
++ emit_move_insn (tmp_reg,
++ GEN_INT (cfun->machine->current_frame_size));
+ emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx,
+ tmp_reg));
+ }
+@@ -2896,11 +2905,22 @@ xtensa_expand_epilogue (void)
+ stack_pointer_rtx,
+ EH_RETURN_STACKADJ_RTX));
+ }
+- xtensa_current_frame_size = 0;
+- xtensa_callee_save_size = 0;
++ cfun->machine->epilogue_done = true;
+ emit_jump_insn (gen_return ());
+ }
+
++bool
++xtensa_use_return_instruction_p (void)
++{
++ if (!reload_completed)
++ return false;
++ if (TARGET_WINDOWED_ABI)
++ return true;
++ if (compute_frame_size (get_frame_size ()) == 0)
++ return true;
++ return cfun->machine->epilogue_done;
++}
++
+ void
+ xtensa_set_return_address (rtx address, rtx scratch)
+ {
+diff --git a/gcc/config/xtensa/xtensa.h b/gcc/config/xtensa/xtensa.h
+index 82e9900..58eb1b2 100644
+--- a/gcc/config/xtensa/xtensa.h
++++ b/gcc/config/xtensa/xtensa.h
+@@ -23,8 +23,6 @@ along with GCC; see the file COPYING3. If not see
+
+ /* External variables defined in xtensa.c. */
+
+-extern unsigned xtensa_current_frame_size;
+-
+ /* Macros used in the machine description to select various Xtensa
+ configuration options. */
+ #ifndef XCHAL_HAVE_MUL32_HIGH
+@@ -477,14 +475,14 @@ enum reg_class
+ /* Specify the initial difference between the specified pair of registers. */
+ #define INITIAL_ELIMINATION_OFFSET(FROM, TO, OFFSET) \
+ do { \
+- compute_frame_size (get_frame_size ()); \
++ long frame_size = compute_frame_size (get_frame_size ()); \
+ switch (FROM) \
+ { \
+ case FRAME_POINTER_REGNUM: \
+ (OFFSET) = 0; \
+ break; \
+ case ARG_POINTER_REGNUM: \
+- (OFFSET) = xtensa_current_frame_size; \
++ (OFFSET) = frame_size; \
+ break; \
+ default: \
+ gcc_unreachable (); \
+diff --git a/gcc/config/xtensa/xtensa.md b/gcc/config/xtensa/xtensa.md
+index db54a12..fcdb6c8 100644
+--- a/gcc/config/xtensa/xtensa.md
++++ b/gcc/config/xtensa/xtensa.md
+@@ -1663,7 +1663,7 @@
+ (define_insn "return"
+ [(return)
+ (use (reg:SI A0_REG))]
+- "(TARGET_WINDOWED_ABI || !xtensa_current_frame_size) && reload_completed"
++ "xtensa_use_return_instruction_p ()"
+ {
+ return TARGET_WINDOWED_ABI ?
+ (TARGET_DENSITY ? "retw.n" : "retw") :
+--
+2.1.4
+
diff --git a/samples/xtensa-unknown-linux-uclibc/crosstool.config b/samples/xtensa-fsf-linux-uclibc/crosstool.config
index e7ab10e..5033622 100644
--- a/samples/xtensa-unknown-linux-uclibc/crosstool.config
+++ b/samples/xtensa-fsf-linux-uclibc/crosstool.config
@@ -1,7 +1,10 @@
CT_LOCAL_TARBALLS_DIR="${HOME}/src"
CT_SAVE_TARBALLS=y
CT_LOG_EXTRA=y
+CT_ARCH_BE=y
+CT_TARGET_CFLAGS="-mlongcalls -mtext-section-literals"
CT_ARCH_xtensa=y
+CT_TARGET_VENDOR="fsf"
CT_KERNEL_linux=y
CT_LIBC_uClibc=y
CT_LIBC_UCLIBC_WCHAR=y
diff --git a/samples/xtensa-unknown-linux-uclibc/reported.by b/samples/xtensa-fsf-linux-uclibc/reported.by
index 7ba8950..7ba8950 100644
--- a/samples/xtensa-unknown-linux-uclibc/reported.by
+++ b/samples/xtensa-fsf-linux-uclibc/reported.by
diff --git a/scripts/build/arch/xtensa.sh b/scripts/build/arch/xtensa.sh
index a3010c6..bf94ddf 100644
--- a/scripts/build/arch/xtensa.sh
+++ b/scripts/build/arch/xtensa.sh
@@ -3,6 +3,8 @@
CT_DoArchTupleValues() {
# The architecture part of the tuple:
CT_TARGET_ARCH="${CT_ARCH}${CT_ARCH_SUFFIX}"
+ CT_ARCH_ENDIAN_CFLAG=""
+ CT_ARCH_ENDIAN_LDFLAG=""
# The system part of the tuple:
case "${CT_LIBC}" in
*glibc) CT_TARGET_SYS=gnu;;