This is the mail archive of the
mailing list for the GCC project.
Fwd: Question about codes in libgcc/crtstuff.c
- From: lei wang <lei dot wang dot left at gmail dot com>
- To: gcc at gcc dot gnu dot org
- Date: Fri, 4 Nov 2016 10:55:00 -0400
- Subject: Fwd: Question about codes in libgcc/crtstuff.c
- Authentication-results: sourceware.org; auth=none
- References: <04728ABB-D10C-4644-A7D0-FB308B45BEE6@gmail.com> <CAKOQZ8weGkLC6tNJ_-0c36W5S=RKpnaT6wiVq+vEUenKgt7qKA@mail.gmail.com> <CANZXyhR_SCZhAqRv6zXMFS_63g6BHM3YHsLMnj-gTgJXQbRLYA@mail.gmail.com>
In fact, I just want to find a practical way to make the crt work.
Currently, I did the following configure in my port:
include "elfos.h" in tm.h
use default INIT_SECTION_OP
My port is working on a bare metal machine with newlib support. Seems
I fall into an spurious configure for compiling crtstuff.c. Could you
give me some guide to lead me back to common configuration of this?
2016-11-04 10:33 GMT-04:00 Ian Lance Taylor <firstname.lastname@example.org>:
> On Thu, Nov 3, 2016 at 7:20 PM, Lei Wang <email@example.com> wrote:
>> The brief structure of libgcc/crtstuff.c is as follows:
>> #ifdef CRT_BEGIN
>> #elif defined(CRT_END)
>> # ifdef OBJECT_FORMAT_ELF
>> # else
>> static void
>> __do_global_ctors_aux (void) /* prologue goes in .text section */
>> asm (__LIBGCC_INIT_SECTION_ASM_OP__);
>> atexit (__do_global_dtors);
>> } /* epilogue and body go in .init section */
>> asm (__LIBGCC_TEXT_SECTION_ASM_OP__);
>> #endif // OBJECT_FORMAT_ELF
>> #else // !CRT_BEGIN && !CRT_END
>> The __do_global_ctors_aux function shown above is static and without “used” attribute which result in optimizing out when compiled with optimization. This currently causes my port failed.
>> My understanding is that this function is supposed to be split into two parts: a prologue in .text section and the rest part in .init section. Meanwhile there is another symmetric function with the same name which is also split into two parts: an prologue in .init section and the rest part in .text section, which result in two identical copies of this function, one in .init section and the other in .text section.
>> Or is there any other purpose of this code?
> This code is all ridiculously complicated. It's also not used on
> modern ELF systems, which use a .init_array section instead. Tell us
> more about your port, and why you need to worry about this.