This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Use .init_array, .fini_array sections for ARM EABI (broke-target=avr)


Joseph S. Myers wrote:
On Sat, 30 Apr 2005, Mark Mitchell wrote:


Joseph S. Myers wrote:


/usr/ccs/bin/ld: Unsatisfied symbols:
  __main (first referenced in build/genmodes.o) (code)
collect2: ld returned 1 exit status
make[2]: *** [build/genmodes] Error 1

Has this configuration always used __main, but now we fail to define it? Or are we now calling it where before we did not?


Previously (with a 2005-04-29 compiler), "int main(){return 0;}" compiles to code not calling __main. Now (with a 2005-04-30 compiler) it compiles to code calling __main.

I believe this patch will fix the problem. The key mistake was that we were failing to check HAS_INIT_SECTION in deciding whether or not to call __main. I think that when I wrote the original version of this patch I mistakenly believed that HAS_INIT_SECTION would be defined iff INIT_SECTION_ASM_OP was defined; that is not true.


I have tested this patch by looking at the assembly output from compiling a file that defines "main" on hppa2.0w-hp-hpux11.23, and am running a full bootstrap/test on x86_64-unknown-linux-gnu; I will check in once that finishes.

--
Mark Mitchell
CodeSourcery, LLC
mark@codesourcery.com
(916) 791-8304
2005-05-01  Mark Mitchell  <mark@codesourcery.com>

	* function.c (INVOKE__main): Do not define.
	(expand_main_function): Check HAS_INIT_SECTION when determining
	whether or not to call __main.

Index: function.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/function.c,v
retrieving revision 1.616
diff -c -5 -p -r1.616 function.c
*** function.c	30 Apr 2005 03:17:53 -0000	1.616
--- function.c	1 May 2005 16:59:08 -0000
*************** init_function_for_compilation (void)
*** 3865,3882 ****
    VARRAY_GROW (prologue, 0);
    VARRAY_GROW (epilogue, 0);
    VARRAY_GROW (sibcall_epilogue, 0);
  }
  
- /* Define IVOKE__main if we should emit a call to __main at the start
-    of "main".  */ 
- #if (!defined(INVOKE__main)			\
-      && !defined(INIT_SECTION_ASM_OP)		\
-      && !defined(INIT_ARRAY_SECTION_ASM_OP))
- #define INVOKE__main
- #endif
- 
  void
  expand_main_function (void)
  {
  #ifdef FORCE_PREFERRED_STACK_BOUNDARY_IN_MAIN
    if (FORCE_PREFERRED_STACK_BOUNDARY_IN_MAIN)
--- 3865,3874 ----
*************** expand_main_function (void)
*** 3912,3922 ****
        else
  	emit_insn (seq);
      }
  #endif
  
! #if defined(INVOKE__main)
    emit_library_call (init_one_libfunc (NAME__MAIN), LCT_NORMAL, VOIDmode, 0);
  #endif
  }
  
  /* Start the RTL for a new function, and set variables used for
--- 3904,3917 ----
        else
  	emit_insn (seq);
      }
  #endif
  
! #if (defined(INVOKE__main)				\
!      || (!defined(HAS_INIT_SECTION)			\
! 	 && !defined(INIT_SECTION_ASM_OP)		\
! 	 && !defined(INIT_ARRAY_SECTION_ASM_OP)))
    emit_library_call (init_one_libfunc (NAME__MAIN), LCT_NORMAL, VOIDmode, 0);
  #endif
  }
  
  /* Start the RTL for a new function, and set variables used for

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]