This is the mail archive of the
libc-hacker@sourceware.cygnus.com
mailing list for the glibc project.
Re: ARM crt.. files
On Sun, Jun 28, 1998 at 05:09:55PM -0400, Roland McGrath wrote:
> I believe I have devised a solution, but I am too lazy to fully implement
> it myself. This would replace my postprocessed-assembly kludge with a
> postprocessed-object file kludge, which is probably more portable given GNU
> binutils.
An interesting idea.
> The objcopy step is necessary because ld will stick all the unmentioned
> sections into the output, and as far as I can tell there is no way to tell
> it on the command line or in a linker script to discard sections.
SECTIONS
{
.init : { *(.init.prologue) }
.fini : { *(.fini.prologue) }
/DISCARD/ : { *(.init.epilogue) *(.fini.epilogue) *(.garbage) }
}
SECTIONS
{
.init : { *(.init.epilogue) }
.fini : { *(.fini.epilogue) }
/DISCARD/ : { *(.init.prologue) *(.fini.prologue) *(.garbage) }
}
It is also necesary to strip the future crtn.o (ld -s) because
the _init and _fini symbols will still be present even though
their defining section is removed (arguably a bug in ld).
I also recommend the following init-fini.c, where ALIGN_INIT_CODE
should come from some target header. The align is necessary to
get the assembler to insert the proper nops. The change to
i_am_not_a_leaf prevents us from having to remove it from the
symbol table.
r~
extern void __gmon_start__ (void);
#pragma weak __gmon_start__
#define ALIGN_INIT_CODE ".align 5"
void __attribute__((section (".init.prologue")))
_init (void)
{
/* We cannot use the normal constructor mechanism in gcrt1.o because it
appears before crtbegin.o in the link, so the header elt of .ctors
would come after the elt for __gmon_start__. One approach is for
gcrt1.o to reference a symbol which would be defined by some library
module which has a constructor; but then user code's constructors
would come first, and not be profiled. */
if (__gmon_start__)
__gmon_start__ ();
asm (ALIGN_INIT_CODE "\n.section .init.epilogue,\"ax\",@progbits");
/* Now the epilog. */
}
void __attribute__((section (".fini.prologue")))
_fini (void)
{
asm (ALIGN_INIT_CODE "\n.section .garbage,\"ax\",@progbits");
/* End of the _fini prolog. */
{
/* Let GCC know that _fini is not a leaf function by having a dummy
function call here. We arrange for this call to be omitted from
either crt file. */
void (*i_am_not_a_leaf)(void) = (void *)0x12345678;
i_am_not_a_leaf ();
}
asm (".section .fini.epilogue,\"ax\",@progbits");
/* Beginning of the _fini epilog. */
}