This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc 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]

[RFC] Provide crt[in].S for x86-64


This is an attempt to add sysdeps/x86_64/crt[in].S support.  I mostly
followed crt[in].S from i386 dir and from builddir/csu.  It looks like
it works, but I don't know how to test this properly apart from running
something like this:

#include <stdio.h>
#include <gnu/libc-version.h>

static void __attribute__ ((constructor))
con (void)
{
  puts ("con");
}

static void __attribute__ ((destructor))
dest (void)
{
  puts ("dest");
}

int
main (void)
{
  puts (gnu_get_libc_version ());
}

It compiles both on x86_64-unknown-linux-gnu and x86_64-redhat-linux and
the aforementioned program runs fine as well.
I'm not attaching the CL entry, license etc yet, I'll do this later.  It also looks
like we don't need any CFLAGS tweak (e.g. like on i386 with
-fno-asynchronous-unwind-tables).  I think we should also remove 
sysdeps/x86_64/elf/initfini.c file later on--this will not be needed any more.

So, comments, please?  Thanks,

--- libc/sysdeps/x86_64/crtn.S.mp	2012-02-08 15:33:53.221898023 +0100
+++ libc/sysdeps/x86_64/crtn.S	2012-02-08 13:50:44.487021038 +0100
@@ -0,0 +1,10 @@
+/* crtn.S puts function epilogues in the .init and .fini sections
+   corresponding to the prologues in crti.S. */
+
+	.section .init,"ax",@progbits
+	addq	$8, %rsp
+	ret
+
+	.section .fini,"ax",@progbits
+	addq	$8, %rsp
+	ret
--- libc/sysdeps/x86_64/crti.S.mp	2012-02-08 15:33:49.198888609 +0100
+++ libc/sysdeps/x86_64/crti.S	2012-02-08 15:20:14.569669814 +0100
@@ -0,0 +1,46 @@
+/* crti.S puts a function prologue at the beginning of the .init and
+   .fini sections and defines global symbols for those addresses, so
+   they can be called as functions.  The symbols _init and _fini are
+   magic and cause the linker to emit DT_INIT and DT_FINI.  */
+
+#include <libc-symbols.h>
+#include <sysdep.h>
+
+#ifndef PREINIT_FUNCTION
+# define PREINIT_FUNCTION __gmon_start__
+#endif
+
+#ifndef PREINIT_FUNCTION_WEAK
+# define PREINIT_FUNCTION_WEAK 1
+#endif
+
+#if PREINIT_FUNCTION_WEAK
+	weak_extern (PREINIT_FUNCTION)
+#else
+	.hidden PREINIT_FUNCTION
+#endif
+
+	.section .init,"ax",@progbits
+	.p2align 2
+	.globl _init
+	.type _init, @function
+_init:
+	/* Maintain 16-byte stack alignment for called functions.  */
+	subq $8, %rsp
+#if PREINIT_FUNCTION_WEAK
+	movq PREINIT_FUNCTION@GOTPCREL(%rip), %rax
+	testq %rax, %rax
+	je .Lno_weak_fn
+	call PREINIT_FUNCTION@PLT
+.Lno_weak_fn:
+#else
+	addq $8, %rsp
+	ret
+#endif
+
+	.section .fini,"ax",@progbits
+	.p2align 2
+	.globl _fini
+	.type _fini, @function
+_fini:
+	subq $8, %rsp

	Marek


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