* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
- * $FreeBSD: src/lib/csu/common/crtbrand.c,v 1.1.2.1 2000/10/30 20:32:24 obrien Exp $
- * $DragonFly: src/lib/csu/common/crtbrand.c,v 1.5 2006/09/30 18:07:04 corecode Exp $
+ * $FreeBSD: src/lib/csu/common/crtbrand.c SVN 217375 2011/01/13 dim $
*/
#include <sys/param.h>
* Special ".note" entry specifying the ABI version. See
* http://www.netbsd.org/Documentation/kernel/elf-notes.html
* for more information.
+ *
+ * For all arches except sparc, gcc emits the section directive for the
+ * following struct with a PROGBITS type. However, newer versions of binutils
+ * (after 2.16.90) require the section to be of NOTE type, to guarantee that the
+ * .note.ABI-tag section correctly ends up in the first page of the final
+ * executable.
+ *
+ * Unfortunately, there is no clean way to tell gcc to use another section type,
+ * so this C file (or the C file that includes it) must be compiled in multiple
+ * steps:
+ *
+ * - Compile the .c file to a .s file.
+ * - Edit the .s file to change the 'progbits' type to 'note', for the section
+ * directive that defines the .note.ABI-tag section.
+ * - Compile the .s file to an object file.
+ *
+ * These steps are done in the individual Makefiles for each applicable arch.
*/
static const struct {
int32_t namesz;
-# $FreeBSD: src/lib/csu/i386-elf/Makefile,v 1.6.2.5 2002/11/23 17:44:29 ru Exp $
+# $FreeBSD: src/lib/csu/i386-elf/Makefile SVN 217375 2011/01/13 dim $
-SRCS+= crti.S crtn.S
+SRCS= crti.S crtn.S
OBJS+= gcrt1.o crt1.o Scrt1.o
INSTALLOBJS+= crt1.o crti.o crtn.o gcrt1.o Scrt1.o
-CLEANFILES+= crt1.o crti.o crtn.o gcrt1.o Scrt1.o \
- crt1_c.o crt1_s.o gcrtl_c.o Scrt1_c.o
+CLEANFILES= crt1.o crti.o crtn.o gcrt1.o Scrt1.o
+CLEANFILES+= crt1_c.o crt1_s.o gcrt1_c.o Scrt1_c.o
+CLEANFILES+= crt1_c.s gcrt1_c.s Scrt1_c.s
WARNS?= 2
CFLAGS+= -I${CSUDIR}/../common \
.PATH: ${CSUDIR} ${CSUDIR}/../common
-gcrt1_c.o: crt1_c.c
- ${CC} ${CFLAGS} -DGCRT -c -o gcrt1_c.o ${CSUDIR}/crt1_c.c
+# See the comment in lib/csu/common/crtbrand.c for the reason crt1_c.c is not
+# directly compiled to .o files.
-gcrt1.o: gcrt1_c.o crt1_s.o
+gcrt1_c.s: crt1_c.c
+ ${CC} ${CFLAGS} -DGCRT -S -o ${.TARGET} ${CSUDIR}/crt1_c.c
+ sed -i "" -e '/\.note\.ABI-tag/s/progbits/note/' ${.TARGET}
+
+gcrt1_c.o: gcrt1_c.s
+ ${CC} ${CFLAGS} -c -o ${.TARGET} gcrt1_c.s
+
+gcrt1.o: gcrt1_c.o crt1_s.o
${LD} ${LDFLAGS} -o gcrt1.o -r crt1_s.o gcrt1_c.o
-crt1.o: crt1_c.o crt1_s.o
+crt1_c.s: crt1_c.c
+ ${CC} ${CFLAGS} -S -o ${.TARGET} ${CSUDIR}/crt1_c.c
+ sed -i "" -e '/\.note\.ABI-tag/s/progbits/note/' ${.TARGET}
+
+crt1_c.o: crt1_c.s
+ ${CC} ${CFLAGS} -c -o ${.TARGET} crt1_c.s
+
+crt1.o: crt1_c.o crt1_s.o
${LD} ${LDFLAGS} -o crt1.o -r crt1_s.o crt1_c.o
objcopy --localize-symbol _start1 crt1.o
-Scrt1_c.o: crt1_c.c
- ${CC} ${CFLAGS} -fPIC -DPIC -c -o Scrt1_c.o ${CSUDIR}/crt1_c.c
+Scrt1_c.s: crt1_c.c
+ ${CC} ${CFLAGS} -fPIC -DPIC -S -o ${.TARGET} ${CSUDIR}/crt1_c.c
+ sed -i "" -e '/\.note\.ABI-tag/s/progbits/note/' ${.TARGET}
+
+Scrt1_c.o: Scrt1_c.s
+ ${CC} ${CFLAGS} -c -o ${.TARGET} Scrt1_c.s
-Scrt1.o: Scrt1_c.o crt1_s.o
+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
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
- * $FreeBSD: src/lib/csi/i386-elf/crt1_s.S, svn 217383 2011/01/19 kib $
+ * $FreeBSD: src/lib/csi/i386-elf/crt1_s.S, svn 217383 2011/01/13 kib $
*/
.text
int3
.cfi_endproc
.size _start, . - _start
+
+ .section .note.GNU-stack,"",%progbits
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
- * $FreeBSD: src/lib/csu/i386-elf/crti.S,v 1.2.2.2 2000/10/30 20:32:25 obrien Exp $
- * $DragonFly: src/lib/csu/i386/crti.S,v 1.1 2004/06/15 08:53:09 joerg Exp $
+ * $FreeBSD: src/lib/csu/i386-elf/crti.S SVN 217105 2011/01/07 kib $
*/
.section .init,"ax",@progbits
.globl _init
.type _init,@function
_init:
+ sub $12,%esp /* re-align stack pointer */
.section .fini,"ax",@progbits
.align 4
.globl _fini
.type _fini,@function
_fini:
+ sub $12,%esp /* re-align stack pointer */
+
+ .section .note.GNU-stack,"",%progbits
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
- * $FreeBSD: src/lib/csu/i386-elf/crtn.S,v 1.2.2.2 2000/10/30 20:32:25 obrien Exp $
- * $DragonFly: src/lib/csu/i386/crtn.S,v 1.1 2004/06/15 08:53:09 joerg Exp $
+ * $FreeBSD: src/lib/csu/i386-elf/crtn.S SVN 217105 2011/01/07 kib $
*/
.section .init,"ax",@progbits
+ add $12,%esp
ret
.section .fini,"ax",@progbits
+ add $12,%esp
ret
+
+ .section .note.GNU-stack,"",%progbits
-# $FreeBSD: src/lib/csu/amd64/Makefile,v 1.18 2003/06/30 12:53:39 ru Exp $
+# $FreeBSD: src/lib/csu/amd64/Makefile SVN 217375 2011/01/13 dim $
-SRCS+= crt1.c crti.S crtn.S
+SRCS= crt1.c crti.S crtn.S
OBJS+= Scrt1.o gcrt1.o
-INSTALLOBJS+= crt1.o crti.o crtn.o gcrt1.o
-CLEANFILES+= crt1.o crti.o crtn.o gcrt1.o
+INSTALLOBJS+= crt1.o crti.o crtn.o Scrt1.o gcrt1.o
+CLEANFILES= crt1.s gcrt1.s Scrt1.s
+CLEANFILES+= crt1.o crti.o crtn.o Scrt1.o gcrt1.o
WARNS?= 2
CFLAGS+= -I${CSUDIR}/../common \
.PATH: ${CSUDIR} ${CSUDIR}/../common
-gcrt1.o: crt1.c
- ${CC} ${CFLAGS} -DGCRT -c -o gcrt1.o ${CSUDIR}/crt1.c
+# See the comment in lib/csu/common/crtbrand.c for the reason crt1.c is not
+# directly compiled to .o files.
-Scrt1.o: crt1.c
- ${CC} ${CFLAGS} -fPIC -DPIC -c -o Scrt1.o ${CSUDIR}/crt1.c
+crt1.s: crt1.c
+ ${CC} ${CFLAGS} -S -o ${.TARGET} ${CSUDIR}/crt1.c
+ sed -i "" -e '/\.note\.ABI-tag/s/progbits/note/' ${.TARGET}
+
+crt1.o: crt1.s
+ ${CC} ${CFLAGS} -c -o ${.TARGET} crt1.s
+
+gcrt1.s: crt1.c
+ ${CC} ${CFLAGS} -DGCRT -S -o ${.TARGET} ${CSUDIR}/crt1.c
+ sed -i "" -e '/\.note\.ABI-tag/s/progbits/note/' ${.TARGET}
+
+gcrt1.o: gcrt1.s
+ ${CC} ${CFLAGS} -c -o ${.TARGET} gcrt1.s
+
+Scrt1.s: crt1.c
+ ${CC} ${CFLAGS} -fPIC -DPIC -S -o ${.TARGET} ${CSUDIR}/crt1.c
+ sed -i "" -e '/\.note\.ABI-tag/s/progbits/note/' ${.TARGET}
+
+Scrt1.o: Scrt1.s
+ ${CC} ${CFLAGS} -c -o ${.TARGET} Scrt1.s
.globl _init
.type _init,@function
_init:
- subq $8,%rsp
+ subq $8,%rsp
.section .fini,"ax",@progbits
.align 4
.globl _fini
.type _fini,@function
_fini:
- subq $8,%rsp
+ subq $8,%rsp
- .section .rodata
+ .section .note.GNU-stack,"",%progbits
*/
.section .init,"ax",@progbits
- addq $8,%rsp
+ addq $8,%rsp
ret
.section .fini,"ax",@progbits
- addq $8,%rsp
+ addq $8,%rsp
ret
- .section .rodata
+ .section .note.GNU-stack,"",%progbits