summary refs log tree commit diff
path: root/csu
diff options
context:
space:
mode:
Diffstat (limited to 'csu')
-rw-r--r--csu/Makefile36
-rw-r--r--csu/abi-note.S69
2 files changed, 87 insertions, 18 deletions
diff --git a/csu/Makefile b/csu/Makefile
index cba8a4a5f5..9664821ec4 100644
--- a/csu/Makefile
+++ b/csu/Makefile
@@ -36,25 +36,12 @@ omit-deps = $(patsubst %.o,%,$(start-installed-name) g$(start-installed-name) \
 		             $(csu-dummies))
 install-lib = $(start-installed-name) g$(start-installed-name) \
 	      $(csu-dummies)
-distribute = initfini.c gmon-start.c start.c defs.awk
+distribute = initfini.c gmon-start.c start.c defs.awk abi-note.S abi-tag.h
 
 all: # Make this the default target; it will be defined in Rules.
 
 include ../Makeconfig
 
-ifneq ($(elf),yes)
-
-# When not using ELF, there is just one startfile, called crt0.o.
-start-installed-name = crt0.o
-
-else
-
-# In the ELF universe, crt0.o is called crt1.o, and there are
-# some additional bizarre files.
-start-installed-name = crt1.o
-have-initfini = yes
-
-endif
 
 ifeq ($(have-initfini),yes)
 
@@ -75,7 +62,8 @@ $(objpfx)crt%.o: $(objpfx)crt%.S $(objpfx)defs.h
 	$(CC) -c -fPIC -g0 -I$(..) -I$(common-objpfx) -DASSEMBLER $< -o $@
 
 $(objpfx)initfini.s: initfini.c
-	$(CC) -S -fPIC -finhibit-size-directive $(no-exceptions) $< -o $@
+	$(CC) $(CPPFLAGS) $(CFLAGS) -g0 -S -fPIC -finhibit-size-directive \
+              $(no-exceptions) $< -o $@
 
 $(objpfx)crti.S: $(objpfx)initfini.s
 	sed -n -e '1,/@HEADER_ENDS/p' \
@@ -95,19 +83,31 @@ endif
 
 include ../Rules
 
+define link-relocatable
+$(CC) -nostdlib -nostartfiles -r -o $@ $^
+endef
+
 ifndef start-installed-name-rule
+ifeq (yes,$(elf))
+# We link the ELF startfile along with a SHT_NOTE section indicating
+# the the kernel ABI the binaries linked with this library will require.
+$(objpfx)$(start-installed-name): $(objpfx)start.o $(objpfx)abi-note.o
+	$(link-relocatable)
+else
 # The startfile is installed under different names, so we just call our
 # source file `start.c' and copy to the installed name after compiling.
 $(objpfx)$(start-installed-name): $(objpfx)start.o
-	-rm -f $@
+	rm -f $@
 	ln $< $@
 endif
+endif
 
 # The profiling startfile is made by linking together the normal
 # startfile with gmon-start.o, which defines a constructor function
 # to turn on profiling code at startup.
-$(objpfx)g$(start-installed-name): $(objpfx)start.o $(objpfx)gmon-start.o
-	$(CC) -nostdlib -nostartfiles -r -o $@ $^
+$(objpfx)g$(start-installed-name): $(objpfx)$(start-installed-name) \
+				   $(objpfx)gmon-start.o
+	$(link-relocatable)
 
 # These extra files are sometimes expected by system standard linking
 # procedures, but we have nothing for them to do.  So compile empty files.
diff --git a/csu/abi-note.S b/csu/abi-note.S
new file mode 100644
index 0000000000..baa409de4d
--- /dev/null
+++ b/csu/abi-note.S
@@ -0,0 +1,69 @@
+/* Special .init and .fini section support.
+   Copyright (C) 1997 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it
+   and/or modify it under the terms of the GNU Library General Public
+   License as published by the Free Software Foundation; either
+   version 2 of the License, or (at your option) any later version.
+
+   In addition to the permissions in the GNU Library General Public
+   License, the Free Software Foundation gives you unlimited
+   permission to link the compiled version of this file with other
+   programs, and to distribute those programs without any restriction
+   coming from the use of this file.  (The Library General Public
+   License restrictions do apply in other respects; for example, they
+   cover modification of the file, and distribution when not linked
+   into another program.)
+
+   The GNU C Library is distributed in the hope that it will be
+   useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+   of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with the GNU C Library; see the file COPYING.LIB.  If not,
+   write to the Free Software Foundation, 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.  */
+
+#include <sysdep.h>
+
+/* The basic layout of note sections is specified by the ELF format.  */
+
+#define ELF_NOTE_BEGIN(sectname, sectflags, type, name)			      \
+	.section sectname, sectflags;					      \
+	.align ALIGNARG(2);	/* Notes are 4-byte aligned.  */	      \
+	.long 1f - 0f;		/* 32-bit word: length of name field */	      \
+	.long 3f - 2f;		/* 32-bit word: length of desc field */	      \
+	.long (type);		/* 32-bit word: vendor-defined type field */  \
+0:	.asciz name;		/* null-terminated string, any length: name */\
+1:	.align ALIGNARG(2);	/* Name data padded to 4-byte alignment.  */  \
+2:	/* Here follows the "note descriptor" data, whose format	      \
+	   is not specified by ELF.  The vendor name and type field	      \
+	   indicate what sort of data is found here.  */
+
+#define ELF_NOTE_END							      \
+3:	.align ALIGNARG(2)	/* Pad to 4-byte align the next note.  */
+
+
+/* The linker (GNU ld 2.8 and later) recognize an allocated section whose
+   name begins with `.note' and creates a PT_NOTE program header entry
+   pointing at it.
+
+   Such a program header is the canonical way (at least in the free OS
+   community) to identify the OS environment ABI that the executable was
+   created for.  The ELF note information identifies a particular OS or
+   coordinated development effort within which the ELF header's e_machine
+   value plus (for dynamically linked programs) the PT_INTERP dynamic
+   linker name and DT_NEEDED shared library names fully identify the
+   runtime environment required by an executable.
+
+   The GNU project and cooperating development efforts (including the Linux
+   community) use a vendor name string of "GNU", and a note type field with
+   value 1 for a note descriptor that indicates ABI requirements.  */
+
+#include <abi-tag.h>		/* OS-specific ABI tag value */
+
+ELF_NOTE_BEGIN(".note.ABI-tag", "a", 1, "GNU")
+	.long ABI_TAG
+ELF_NOTE_END