summaryrefslogtreecommitdiffstats
path: root/lib/csu
diff options
context:
space:
mode:
Diffstat (limited to 'lib/csu')
-rw-r--r--lib/csu/amd64/Makefile27
-rw-r--r--lib/csu/arm/Makefile27
-rw-r--r--lib/csu/common/crtbrand.c17
-rw-r--r--lib/csu/i386-elf/Makefile27
-rw-r--r--lib/csu/ia64/Makefile28
-rw-r--r--lib/csu/mips/Makefile27
-rw-r--r--lib/csu/powerpc/Makefile27
-rw-r--r--lib/csu/powerpc64/Makefile19
8 files changed, 171 insertions, 28 deletions
diff --git a/lib/csu/amd64/Makefile b/lib/csu/amd64/Makefile
index 1a74efc..aac0c64 100644
--- a/lib/csu/amd64/Makefile
+++ b/lib/csu/amd64/Makefile
@@ -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} \
diff --git a/lib/csu/arm/Makefile b/lib/csu/arm/Makefile
index c018284..095a9ad 100644
--- a/lib/csu/arm/Makefile
+++ b/lib/csu/arm/Makefile
@@ -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} \
diff --git a/lib/csu/common/crtbrand.c b/lib/csu/common/crtbrand.c
index 684a48e..444d7f1 100644
--- a/lib/csu/common/crtbrand.c
+++ b/lib/csu/common/crtbrand.c
@@ -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;
diff --git a/lib/csu/i386-elf/Makefile b/lib/csu/i386-elf/Makefile
index b4d78c2..b100d7a 100644
--- a/lib/csu/i386-elf/Makefile
+++ b/lib/csu/i386-elf/Makefile
@@ -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
diff --git a/lib/csu/ia64/Makefile b/lib/csu/ia64/Makefile
index 0aca844..41d2b9c 100644
--- a/lib/csu/ia64/Makefile
+++ b/lib/csu/ia64/Makefile
@@ -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}
diff --git a/lib/csu/mips/Makefile b/lib/csu/mips/Makefile
index c018284..095a9ad 100644
--- a/lib/csu/mips/Makefile
+++ b/lib/csu/mips/Makefile
@@ -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} \
diff --git a/lib/csu/powerpc/Makefile b/lib/csu/powerpc/Makefile
index c018284..095a9ad 100644
--- a/lib/csu/powerpc/Makefile
+++ b/lib/csu/powerpc/Makefile
@@ -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} \
diff --git a/lib/csu/powerpc64/Makefile b/lib/csu/powerpc64/Makefile
index 23954e8..04926ad 100644
--- a/lib/csu/powerpc64/Makefile
+++ b/lib/csu/powerpc64/Makefile
@@ -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} \
OpenPOWER on IntegriCloud