Hello,
I was reading mailing list archives and scratching itches and I
created this patch (which is also available on my github::
https://github.com/dannomac/freebsd), to
add NetBSD's crtbegin and crtend code to FreeBSD. I was hoping to get
some more testing.
NetBSD also has arm and powerpc crt code that could likely be
imported, but I don't have the means to test them right now. I might
do that this weekend.
Dan
diff --git a/gnu/lib/Makefile b/gnu/lib/Makefile
index 6750403..1b1f01f 100644
--- a/gnu/lib/Makefile
+++ b/gnu/lib/Makefile
@@ -2,7 +2,14 @@
.include <bsd.own.mk>
-SUBDIR= csu libgcc libgcov libdialog libgomp libregex libreadline
+# amd64 and i386 have BSD licensed crtbegin.o and crtend.o
+.if ${MACHINE_CPUARCH} != "amd64" && ${MACHINE_CPUARCH} != "i386"
+SUBDIR= csu
+.else
+SUBDIR=
+.endif
+
+SUBDIR+= libgcc libgcov libdialog libgomp libregex libreadline
.if ${MK_SSP} != "no"
SUBDIR+= libssp
diff --git a/lib/csu/amd64/Makefile b/lib/csu/amd64/Makefile
index 80d14a7..f662907 100644
--- a/lib/csu/amd64/Makefile
+++ b/lib/csu/amd64/Makefile
@@ -2,9 +2,9 @@
.PATH: ${.CURDIR}/../common
-SRCS= crt1.c crti.S crtn.S
+SRCS= crt1.c crti.S crtn.S crtbegin.S crtend.S
OBJS= ${SRCS:N*.h:R:S/$/.o/g}
-OBJS+= Scrt1.o gcrt1.o
+OBJS+= Scrt1.o gcrt1.o crtbeginS.o
CFLAGS+= -I${.CURDIR}/../common \
-I${.CURDIR}/../../libc/include
CFLAGS+= -fno-omit-frame-pointer
@@ -38,8 +38,14 @@ Scrt1.s: crt1.c
Scrt1.o: Scrt1.s
${CC} ${ACFLAGS} -c -o ${.TARGET} Scrt1.s
+crtbeginS.o: crtbegin.S
+ ${CC} ${CFLAGS} -fPIC -DPIC -DSHARED -c -o ${.TARGET} ${.CURDIR}/crtbegin.S
+
realinstall:
${INSTALL} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
${OBJS} ${DESTDIR}${LIBDIR}
+SYMLINKS+= crtbegin.o ${LIBDIR}/crtbeginT.o
+SYMLINKS+= crtend.o ${LIBDIR}/crtendS.o
+
.include <bsd.lib.mk>
diff --git a/lib/csu/amd64/crtbegin.S b/lib/csu/amd64/crtbegin.S
new file mode 100644
index 0000000..1a60826
--- /dev/null
+++ b/lib/csu/amd64/crtbegin.S
@@ -0,0 +1,158 @@
+/* $NetBSD: crtbegin.S,v 1.2 2010/11/30 18:37:59 joerg Exp $ */
+/*-
+ * Copyright (c) 2010 Joerg Sonnenberger <[email protected]>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <machine/asm.h>
+
+__FBSDID("$FreeBSD$")
+
+ .section .ctors, "aw", @progbits
+ .align 8
+__CTOR_LIST__:
+ .quad -1
+
+ .section .dtors, "aw", @progbits
+ .align 8
+__DTOR_LIST__:
+ .quad -1
+
+ .section .eh_frame, "a", @progbits
+ .align 8
+__EH_FRAME_LIST__:
+
+ .section .jcr, "aw", @progbits
+ .align 8
+__JCR_LIST__:
+
+ .section .data.rel, "aw", @progbits
+ .align 8
+ .type __dso_handle, @object
+ .size __dso_handle, 8
+ .globl __dso_handle
+ .hidden __dso_handle
+__dso_handle:
+#ifdef SHARED
+ .quad __dso_handle
+#else
+ .quad 0
+#endif
+
+__dwarf_eh_object:
+ .zero 64
+
+__initialized:
+ .zero 1
+__finished:
+ .zero 1
+
+ .text
+ .weak __cxa_finalize
+ .weak __deregister_frame_info
+ .weak __register_frame_info
+ .weak _Jv_RegisterClasses
+
+__do_global_dtors_aux:
+ cmpb $0, __finished(%rip)
+ je 1f
+ ret
+1:
+ pushq %rbx
+ movb $1, __finished(%rip)
+
+
+#ifdef SHARED
+ cmpq $0, __cxa_finalize@GOTPCREL(%rip)
+ je 2f
+ movq __dso_handle(%rip), %rdi
+ call __cxa_finalize@PLT
+2:
+#endif
+
+ leaq 8+__DTOR_LIST__(%rip), %rbx
+3:
+ movq (%rbx), %rax
+ testq %rax, %rax
+ je 4f
+ call *%rax
+ addq $8, %rbx
+ jmp 3b
+4:
+
+ cmpq $0, __deregister_frame_info@GOTPCREL(%rip)
+ je 5f
+ leaq __EH_FRAME_LIST__(%rip), %rdi
+ call __deregister_frame_info@PLT
+5:
+ popq %rbx
+ ret
+
+
+__do_global_ctors_aux:
+ cmpb $0, __initialized(%rip)
+ je 1f
+ ret
+1:
+ pushq %rbx
+ movb $1, __initialized(%rip)
+
+ cmpq $0, __register_frame_info@GOTPCREL(%rip)
+ je 2f
+ leaq __dwarf_eh_object(%rip), %rsi
+ leaq __EH_FRAME_LIST__(%rip), %rdi
+ call __register_frame_info@PLT
+
+2:
+ cmpq $0, _Jv_RegisterClasses@GOTPCREL(%rip)
+ je 3f
+ leaq __JCR_LIST__(%rip), %rdi
+ cmpq $0, (%rdi)
+ je 3f
+ call _Jv_RegisterClasses@PLT
+3:
+
+ leaq -8+__CTOR_LIST_END__(%rip), %rbx
+4:
+ movq (%rbx), %rax
+ cmpq $-1, %rax
+ je 5f
+ call *%rax
+ subq $8, %rbx
+ jmp 4b
+
+5:
+ popq %rbx
+
+ ret
+
+ .section .init, "ax", @progbits
+ call __do_global_ctors_aux
+ .section .fini, "ax", @progbits
+ call __do_global_dtors_aux
+
+ .section .note.GNU-stack,"",%progbits
diff --git a/lib/csu/amd64/crtend.S b/lib/csu/amd64/crtend.S
new file mode 100644
index 0000000..c1411fe
--- /dev/null
+++ b/lib/csu/amd64/crtend.S
@@ -0,0 +1,54 @@
+/* $NetBSD: crtend.S,v 1.1 2010/08/07 18:01:34 joerg Exp $ */
+/*-
+ * Copyright (c) 2010 Joerg Sonnenberger <[email protected]>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <machine/asm.h>
+
+__FBSDID("$FreeBSD$")
+
+ .section .ctors, "aw", @progbits
+ .align 8
+ .global __CTOR_LIST_END__
+ .hidden __CTOR_LIST_END__
+__CTOR_LIST_END__:
+ .quad 0
+
+ .section .dtors, "aw", @progbits
+ .align 8
+ .quad 0
+
+ .section .eh_frame, "a", @progbits
+ .align 8
+ .quad 0
+
+ .section .jcr, "aw", @progbits
+ .align 8
+ .quad 0
+
+ .section .note.GNU-stack,"",%progbits
diff --git a/lib/csu/i386-elf/Makefile b/lib/csu/i386-elf/Makefile
index 286c15c..a8f765a 100644
--- a/lib/csu/i386-elf/Makefile
+++ b/lib/csu/i386-elf/Makefile
@@ -2,8 +2,8 @@
.PATH: ${.CURDIR}/../common
-SRCS= crti.S crtn.S
-FILES= ${SRCS:N*.h:R:S/$/.o/g} gcrt1.o crt1.o Scrt1.o
+SRCS= crti.S crtn.S crtbegin.S crtend.S
+FILES= ${SRCS:N*.h:R:S/$/.o/g} gcrt1.o crt1.o Scrt1.o crtbeginS.o
FILESOWN= ${LIBOWN}
FILESGRP= ${LIBGRP}
FILESMODE= ${LIBMODE}
@@ -48,4 +48,10 @@ Scrt1.o: Scrt1_c.o crt1_s.o
${LD} ${LDFLAGS} -o Scrt1.o -r crt1_s.o Scrt1_c.o
objcopy --localize-symbol _start1 Scrt1.o
+crtbeginS.o: crtbegin.S
+ ${CC} ${CFLAGS} -fPIC -DPIC -DSHARED -c -o ${.TARGET} ${.CURDIR}/crtbegin.S
+
+SYMLINKS+= crtbegin.o ${LIBDIR}/crtbeginT.o
+SYMLINKS+= crtend.o ${LIBDIR}/crtendS.o
+
.include <bsd.prog.mk>
diff --git a/lib/csu/i386-elf/crtbegin.S b/lib/csu/i386-elf/crtbegin.S
new file mode 100644
index 0000000..5afc024
--- /dev/null
+++ b/lib/csu/i386-elf/crtbegin.S
@@ -0,0 +1,174 @@
+/* $NetBSD: crtbegin.S,v 1.1 2010/08/07 18:01:33 joerg Exp $ */
+/*-
+ * Copyright (c) 2010 Joerg Sonnenberger <[email protected]>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <machine/asm.h>
+
+__FBSDID("$FreeBSD$")
+
+ .section .ctors, "aw", @progbits
+ .align 4
+__CTOR_LIST__:
+ .long -1
+
+ .section .dtors, "aw", @progbits
+ .align 4
+__DTOR_LIST__:
+ .long -1
+
+ .section .eh_frame, "a", @progbits
+ .align 4
+__EH_FRAME_LIST__:
+
+ .section .jcr, "aw", @progbits
+ .align 4
+__JCR_LIST__:
+
+ .section .data.rel, "aw", @progbits
+ .align 4
+ .type __dso_handle, @object
+ .size __dso_handle, 4
+ .globl __dso_handle
+ .hidden __dso_handle
+__dso_handle:
+#ifdef SHARED
+ .long __dso_handle
+#else
+ .long 0
+#endif
+
+__dwarf_eh_object:
+ .zero 32
+
+__initialized:
+ .zero 1
+__finished:
+ .zero 1
+
+ .text
+ .weak __cxa_finalize
+ .weak __deregister_frame_info
+ .weak __register_frame_info
+ .weak _Jv_RegisterClasses
+
+__get_thunk:
+ movl (%esp), %ebx
+ ret
+
+__do_global_dtors_aux:
+ pushl %ebx
+ pushl %edi
+ subl $8, %esp
+ call __get_thunk
+ addl $_GLOBAL_OFFSET_TABLE_, %ebx
+
+ cmpb $0, __finished@GOTOFF(%ebx)
+ jne 4f
+ movb $1, __finished@GOTOFF(%ebx)
+
+#ifdef SHARED
+ cmpl $0, __cxa_finalize@GOT(%ebx)
+ je 1f
+ movl __dso_handle@GOTOFF(%ebx), %eax
+ movl %eax, (%esp)
+ call __cxa_finalize@PLT
+1:
+#endif
+
+ leal 4+__DTOR_LIST__@GOTOFF(%ebx), %edi
+2:
+ movl (%edi), %eax
+ testl %eax, %eax
+ je 3f
+ call *%eax
+ addl $8, %edi
+ jmp 2b
+3:
+
+ cmpl $0, __deregister_frame_info@GOT(%ebx)
+ je 4f
+ leal __EH_FRAME_LIST__@GOTOFF(%ebx), %eax
+ movl %eax, (%esp)
+ call __deregister_frame_info@PLT
+4:
+ addl $8, %esp
+ popl %edi
+ popl %ebx
+ ret
+
+
+__do_global_ctors_aux:
+ pushl %ebx
+ pushl %edi
+ subl $8, %esp
+ call __get_thunk
+ addl $_GLOBAL_OFFSET_TABLE_, %ebx
+
+ cmpb $0, __initialized@GOTOFF(%ebx)
+ jne 4f
+ movb $1, __initialized@GOTOFF(%ebx)
+
+ cmpl $0, __register_frame_info@GOT(%ebx)
+ je 1f
+ leal __dwarf_eh_object@GOTOFF(%ebx), %edi
+ movl %edi, 4(%esp)
+ leal __EH_FRAME_LIST__@GOTOFF(%ebx), %edi
+ movl %edi, (%esp)
+ call __register_frame_info@PLT
+
+1:
+ cmpl $0, _Jv_RegisterClasses@GOT(%ebx)
+ je 2f
+ leal __JCR_LIST__@GOTOFF(%ebx), %edi
+ movl (%edi), %edi
+ testl %edi, %edi
+ je 2f
+ movl %edi, (%esp)
+ call _Jv_RegisterClasses@PLT
+2:
+
+ leal -4+__CTOR_LIST_END__@GOTOFF(%ebx), %edi
+3:
+ movl (%edi), %eax
+ cmpl $-1, %eax
+ je 4f
+ call *%eax
+ subl $4, %edi
+ jmp 3b
+
+4:
+ addl $8, %esp
+ popl %edi
+ popl %ebx
+ ret
+
+ .section .init, "ax", @progbits
+ call __do_global_ctors_aux
+ .section .fini, "ax", @progbits
+ call __do_global_dtors_aux
diff --git a/lib/csu/i386-elf/crtend.S b/lib/csu/i386-elf/crtend.S
new file mode 100644
index 0000000..1475ad0
--- /dev/null
+++ b/lib/csu/i386-elf/crtend.S
@@ -0,0 +1,52 @@
+/* $NetBSD: crtend.S,v 1.1 2010/08/07 18:01:33 joerg Exp $ */
+/*-
+ * Copyright (c) 2010 Joerg Sonnenberger <[email protected]>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <machine/asm.h>
+
+__FBSDID("$FreeBSD$")
+
+ .section .ctors, "aw", @progbits
+ .align 4
+ .global __CTOR_LIST_END__
+ .hidden __CTOR_LIST_END__
+__CTOR_LIST_END__:
+ .long 0
+
+ .section .dtors, "aw", @progbits
+ .align 4
+ .long 0
+
+ .section .eh_frame, "a", @progbits
+ .align 4
+ .long 0
+
+ .section .jcr, "aw", @progbits
+ .align 4
+ .long 0
_______________________________________________
[email protected] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-toolchain
To unsubscribe, send any mail to "[email protected]"