Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 13 Jan 2011 20:44:32 +0000 (UTC)
From:      Dimitry Andric <dim@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r217375 - in head/lib/csu: amd64 arm common i386-elf ia64 mips powerpc powerpc64
Message-ID:  <201101132044.p0DKiWjq062979@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: dim
Date: Thu Jan 13 20:44:31 2011
New Revision: 217375
URL: http://svn.freebsd.org/changeset/base/217375

Log:
  Apply a workaround for a binutils issue with the .note.ABI-tag section
  generated from lib/csu/common/crtbrand.c (which ultimately ends up in
  executables and shared libraries, via crt1.o, gcrt1.o or Scrt1.o).
  
  For all arches except sparc, gcc emits the section directive for the
  abitag struct in crtbrand.c 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 crtbrand.c (or the C files that include 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 invididual Makefiles for each applicable arch.
  
  Reviewed by:	kib

Modified:
  head/lib/csu/amd64/Makefile
  head/lib/csu/arm/Makefile
  head/lib/csu/common/crtbrand.c
  head/lib/csu/i386-elf/Makefile
  head/lib/csu/ia64/Makefile
  head/lib/csu/mips/Makefile
  head/lib/csu/powerpc/Makefile
  head/lib/csu/powerpc64/Makefile

Modified: head/lib/csu/amd64/Makefile
==============================================================================
--- head/lib/csu/amd64/Makefile	Thu Jan 13 20:03:55 2011	(r217374)
+++ head/lib/csu/amd64/Makefile	Thu Jan 13 20:44:31 2011	(r217375)
@@ -12,12 +12,31 @@ CFLAGS+=	-fno-omit-frame-pointer
 all: ${OBJS}
 
 CLEANFILES=	${OBJS}
+CLEANFILES+=	crt1.s gcrt1.s Scrt1.s
 
-gcrt1.o: crt1.c
-	${CC} ${CFLAGS} -DGCRT -c -o gcrt1.o ${.CURDIR}/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 ${.CURDIR}/crt1.c
+crt1.s: crt1.c
+	${CC} ${CFLAGS} -S -o ${.TARGET} ${.CURDIR}/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} ${.CURDIR}/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} ${.CURDIR}/crt1.c
+	sed -i "" -e '/\.note\.ABI-tag/s/progbits/note/' ${.TARGET}
+
+Scrt1.o: Scrt1.s
+	${CC} ${CFLAGS} -c -o ${.TARGET} Scrt1.s
 
 realinstall:
 	${INSTALL} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \

Modified: head/lib/csu/arm/Makefile
==============================================================================
--- head/lib/csu/arm/Makefile	Thu Jan 13 20:03:55 2011	(r217374)
+++ head/lib/csu/arm/Makefile	Thu Jan 13 20:44:31 2011	(r217375)
@@ -11,12 +11,31 @@ CFLAGS+=	-I${.CURDIR}/../common \
 all: ${OBJS}
 
 CLEANFILES=	${OBJS}
+CLEANFILES+=	crt1.s gcrt1.s Scrt1.s
 
-gcrt1.o: crt1.c
-	${CC} ${CFLAGS} -DGCRT -c -o gcrt1.o ${.ALLSRC}
+# 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 ${.ALLSRC}
+crt1.s: crt1.c
+	${CC} ${CFLAGS} -S -o ${.TARGET} ${.CURDIR}/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} ${.CURDIR}/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} ${.CURDIR}/crt1.c
+	sed -i "" -e '/\.note\.ABI-tag/s/progbits/note/' ${.TARGET}
+
+Scrt1.o: Scrt1.s
+	${CC} ${CFLAGS} -c -o ${.TARGET} Scrt1.s
 
 realinstall:
 	${INSTALL} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \

Modified: head/lib/csu/common/crtbrand.c
==============================================================================
--- head/lib/csu/common/crtbrand.c	Thu Jan 13 20:03:55 2011	(r217374)
+++ head/lib/csu/common/crtbrand.c	Thu Jan 13 20:44:31 2011	(r217375)
@@ -36,6 +36,23 @@ __FBSDID("$FreeBSD$");
  * 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 invididual Makefiles for each applicable arch.
  */
 static const struct {
     int32_t	namesz;

Modified: head/lib/csu/i386-elf/Makefile
==============================================================================
--- head/lib/csu/i386-elf/Makefile	Thu Jan 13 20:03:55 2011	(r217374)
+++ head/lib/csu/i386-elf/Makefile	Thu Jan 13 20:44:31 2011	(r217375)
@@ -11,19 +11,38 @@ FILESDIR=	${LIBDIR}
 CFLAGS+=	-I${.CURDIR}/../common \
 		-I${.CURDIR}/../../libc/include
 CLEANFILES=	${FILES} crt1_c.o crt1_s.o gcrt1_c.o Scrt1_c.o
+CLEANFILES+=	crt1_c.s gcrt1_c.s Scrt1_c.s
 
-gcrt1_c.o: crt1_c.c
-	${CC} ${CFLAGS} -DGCRT -c -o gcrt1_c.o ${.CURDIR}/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_c.s: crt1_c.c
+	${CC} ${CFLAGS} -DGCRT -S -o ${.TARGET} ${.CURDIR}/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_c.s: crt1_c.c
+	${CC} ${CFLAGS} -S -o ${.TARGET} ${.CURDIR}/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 ${.CURDIR}/crt1_c.c
+Scrt1_c.s: crt1_c.c
+	${CC} ${CFLAGS} -fPIC -DPIC -S -o ${.TARGET} ${.CURDIR}/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
 	${LD} ${LDFLAGS} -o Scrt1.o -r crt1_s.o Scrt1_c.o

Modified: head/lib/csu/ia64/Makefile
==============================================================================
--- head/lib/csu/ia64/Makefile	Thu Jan 13 20:03:55 2011	(r217374)
+++ head/lib/csu/ia64/Makefile	Thu Jan 13 20:44:31 2011	(r217375)
@@ -11,12 +11,20 @@ all: ${OBJS}
 CLEANFILES=	${OBJS}
 CLEANFILES+=	crt1_.o gcrt1_.o Scrt1_.o
 CLEANFILES+=	crtbrand.o gcrtbrand.o Scrtbrand.o
+CLEANFILES+=	crtbrand.s gcrtbrand.s Scrtbrand.s
 
 crt1_.o: crt1.S
 	${CC} ${CFLAGS} -c -o ${.TARGET} ${.ALLSRC}
 
-crtbrand.o: crtbrand.c
-	${CC} ${CFLAGS} -c -o ${.TARGET} ${.ALLSRC}
+# See the comment in lib/csu/common/crtbrand.c for the reason crtbrand.c is not
+# directly compiled to .o files.
+
+crtbrand.s: crtbrand.c
+	${CC} ${CFLAGS} -S -o ${.TARGET} ${.ALLSRC}
+	sed -i "" -e '/\.note\.ABI-tag/s/progbits/note/' ${.TARGET}
+
+crtbrand.o: crtbrand.s
+	${CC} ${CFLAGS} -c -o ${.TARGET} crtbrand.s
 
 crt1.o: crt1_.o crtbrand.o
 	${LD} ${LDFLAGS} -r -o ${.TARGET} crt1_.o crtbrand.o
@@ -24,8 +32,12 @@ crt1.o: crt1_.o crtbrand.o
 gcrt1_.o: crt1.S
 	${CC} ${CFLAGS} -DGCRT -c -o ${.TARGET} ${.ALLSRC}
 
-gcrtbrand.o: crtbrand.c
-	${CC} ${CFLAGS} -DGCRT -c -o ${.TARGET} ${.ALLSRC}
+gcrtbrand.s: crtbrand.c
+	${CC} ${CFLAGS} -DGCRT -S -o ${.TARGET} ${.ALLSRC}
+	sed -i "" -e '/\.note\.ABI-tag/s/progbits/note/' ${.TARGET}
+
+gcrtbrand.o: gcrtbrand.s
+	${CC} ${CFLAGS} -c -o ${.TARGET} gcrtbrand.s
 
 gcrt1.o: gcrt1_.o gcrtbrand.o
 	${LD} ${LDFLAGS} -r -o ${.TARGET} ${.ALLSRC}
@@ -33,8 +45,12 @@ gcrt1.o: gcrt1_.o gcrtbrand.o
 Scrt1_.o: crt1.S
 	${CC} ${CFLAGS} -fPIC -DPIC -c -o ${.TARGET} ${.ALLSRC}
 
-Scrtbrand.o: crtbrand.c
-	${CC} ${CFLAGS} -fPIC -DPIC -c -o ${.TARGET} ${.ALLSRC}
+Scrtbrand.s: crtbrand.c
+	${CC} ${CFLAGS} -fPIC -DPIC -S -o ${.TARGET} ${.ALLSRC}
+	sed -i "" -e '/\.note\.ABI-tag/s/progbits/note/' ${.TARGET}
+
+Scrtbrand.o: Scrtbrand.s
+	${CC} ${CFLAGS} -c -o ${.TARGET} Scrtbrand.s
 
 Scrt1.o: Scrt1_.o Scrtbrand.o
 	${LD} ${LDFLAGS} -r -o ${.TARGET} ${.ALLSRC}

Modified: head/lib/csu/mips/Makefile
==============================================================================
--- head/lib/csu/mips/Makefile	Thu Jan 13 20:03:55 2011	(r217374)
+++ head/lib/csu/mips/Makefile	Thu Jan 13 20:44:31 2011	(r217375)
@@ -11,12 +11,31 @@ CFLAGS+=	-I${.CURDIR}/../common \
 all: ${OBJS}
 
 CLEANFILES=	${OBJS}
+CLEANFILES+=	crt1.s gcrt1.s Scrt1.s
 
-gcrt1.o: crt1.c
-	${CC} ${CFLAGS} -DGCRT -c -o gcrt1.o ${.ALLSRC}
+# 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 ${.ALLSRC}
+crt1.s: crt1.c
+	${CC} ${CFLAGS} -S -o ${.TARGET} ${.CURDIR}/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} ${.CURDIR}/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} ${.CURDIR}/crt1.c
+	sed -i "" -e '/\.note\.ABI-tag/s/progbits/note/' ${.TARGET}
+
+Scrt1.o: Scrt1.s
+	${CC} ${CFLAGS} -c -o ${.TARGET} Scrt1.s
 
 realinstall:
 	${INSTALL} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \

Modified: head/lib/csu/powerpc/Makefile
==============================================================================
--- head/lib/csu/powerpc/Makefile	Thu Jan 13 20:03:55 2011	(r217374)
+++ head/lib/csu/powerpc/Makefile	Thu Jan 13 20:44:31 2011	(r217375)
@@ -11,12 +11,31 @@ CFLAGS+=	-I${.CURDIR}/../common \
 all: ${OBJS}
 
 CLEANFILES=	${OBJS}
+CLEANFILES+=	crt1.s gcrt1.s Scrt1.s
 
-gcrt1.o: crt1.c
-	${CC} ${CFLAGS} -DGCRT -c -o gcrt1.o ${.ALLSRC}
+# 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 ${.ALLSRC}
+crt1.s: crt1.c
+	${CC} ${CFLAGS} -S -o ${.TARGET} ${.CURDIR}/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} ${.CURDIR}/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} ${.CURDIR}/crt1.c
+	sed -i "" -e '/\.note\.ABI-tag/s/progbits/note/' ${.TARGET}
+
+Scrt1.o: Scrt1.s
+	${CC} ${CFLAGS} -c -o ${.TARGET} Scrt1.s
 
 realinstall:
 	${INSTALL} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \

Modified: head/lib/csu/powerpc64/Makefile
==============================================================================
--- head/lib/csu/powerpc64/Makefile	Thu Jan 13 20:03:55 2011	(r217374)
+++ head/lib/csu/powerpc64/Makefile	Thu Jan 13 20:44:31 2011	(r217375)
@@ -12,9 +12,24 @@ CFLAGS+=	-Wall -Wno-unused \
 all: ${OBJS}
 
 CLEANFILES=	${OBJS}
+CLEANFILES+=	crt1.s gcrt1.s
 
-gcrt1.o: crt1.c
-	${CC} ${CFLAGS} -DGCRT -c -o gcrt1.o ${.ALLSRC}
+# See the comment in lib/csu/common/crtbrand.c for the reason crt1.c is not
+# directly compiled to .o files.
+
+crt1.s: crt1.c
+	${CC} ${CFLAGS} -S -o ${.TARGET} ${.CURDIR}/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} ${.CURDIR}/crt1.c
+	sed -i "" -e '/\.note\.ABI-tag/s/progbits/note/' ${.TARGET}
+
+gcrt1.o: gcrt1.s
+	${CC} ${CFLAGS} -c -o ${.TARGET} gcrt1.s
 
 realinstall:
 	${INSTALL} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201101132044.p0DKiWjq062979>