The Nios II ports of glibc and Linux kernel are now both upstream. New system conventions now use a non-executable stack. Attached patch committed to support new conventions, applied to both trunk and 4.9 branch.
Chung-Lin 2015-01-20 Chung-Lin Tang <clt...@codesourcery.com> gcc/ * config/nios2/nios2.c (nios2_asm_file_end): Implement TARGET_ASM_FILE_END hook for adding .note.GNU-stack section when needed. (TARGET_ASM_FILE_END): Define. libgcc/ * config/nios2/linux-unwind.h (nios2_fallback_frame_state): Update rt_sigframe format and address for current Nios II Linux conventions.
Index: libgcc/config/nios2/linux-unwind.h =================================================================== --- libgcc/config/nios2/linux-unwind.h (revision 219897) +++ libgcc/config/nios2/linux-unwind.h (working copy) @@ -67,10 +67,9 @@ nios2_fallback_frame_state (struct _Unwind_Context if (pc[0] == (0x00800004 | (__NR_rt_sigreturn << 6))) { struct rt_sigframe { - char retcode[12]; siginfo_t info; struct nios2_ucontext uc; - } *rt_ = context->ra; + } *rt_ = context->cfa; struct nios2_mcontext *regs = &rt_->uc.uc_mcontext; int i; Index: gcc/config/nios2/nios2.c =================================================================== --- gcc/config/nios2/nios2.c (revision 219897) +++ gcc/config/nios2/nios2.c (working copy) @@ -2223,6 +2223,18 @@ nios2_output_dwarf_dtprel (FILE *file, int size, r fprintf (file, ")"); } +/* Implemet TARGET_ASM_FILE_END. */ + +static void +nios2_asm_file_end (void) +{ + /* The Nios II Linux stack is mapped non-executable by default, so add a + .note.GNU-stack section for switching to executable stacks only when + trampolines are generated. */ + if (TARGET_LINUX_ABI && trampolines_created) + file_end_indicate_exec_stack (); +} + /* Implement TARGET_ASM_FUNCTION_PROLOGUE. */ static void nios2_asm_function_prologue (FILE *file, HOST_WIDE_INT size ATTRIBUTE_UNUSED) @@ -3401,6 +3413,9 @@ nios2_merge_decl_attributes (tree olddecl, tree ne #undef TARGET_ASM_OUTPUT_ADDR_CONST_EXTRA #define TARGET_ASM_OUTPUT_ADDR_CONST_EXTRA nios2_output_addr_const_extra +#undef TARGET_ASM_FILE_END +#define TARGET_ASM_FILE_END nios2_asm_file_end + #undef TARGET_OPTION_OVERRIDE #define TARGET_OPTION_OVERRIDE nios2_option_override