From: Michael Meissner Date: Wed, 13 Mar 1996 17:12:13 +0000 (+0000) Subject: Add static constructor/destructor support to Windows NT X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=2aa35c631298dc5e870cf7d44b069b4fc02b6dd3;p=gcc.git Add static constructor/destructor support to Windows NT From-SVN: r11524 --- diff --git a/gcc/config/rs6000/cygwin32.h b/gcc/config/rs6000/cygwin32.h index 2230848a333..adca36d4fd7 100644 --- a/gcc/config/rs6000/cygwin32.h +++ b/gcc/config/rs6000/cygwin32.h @@ -50,15 +50,16 @@ Boston, MA 02111-1307, USA. */ #undef STARTFILE_SPEC -#define STARTFILE_SPEC "%{!:crt0%O%s}" +#define STARTFILE_SPEC "crti%O%s %{!:crt0%O%s}" + +#undef ENDFILE_SPEC +#define ENDFILE_SPEC "crtn%O%s" #define PTRDIFF_TYPE "int" #define WCHAR_UNSIGNED 1 #define WCHAR_TYPE_SIZE 16 #define WCHAR_TYPE "short unsigned int" -/* XXX set up stack probing */ - #define DBX_DEBUGGING_INFO #undef SDB_DEBUGGING_INFO #define PREFERRED_DEBUGGING_TYPE DBX_DEBUG diff --git a/gcc/config/rs6000/nt-ci.asm b/gcc/config/rs6000/nt-ci.asm new file mode 100644 index 00000000000..67ca9564abf --- /dev/null +++ b/gcc/config/rs6000/nt-ci.asm @@ -0,0 +1,48 @@ +# crti.s for Windows NT + +# Copyright (C) 1996 Free Software Foundation, Inc. +# Written By Michael Meissner +# +# This file is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation; either version 2, or (at your option) any +# later version. +# +# In addition to the permissions in the GNU 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 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.) +# +# This file 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 +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; see the file COPYING. If not, write to +# the Free Software Foundation, 59 Temple Place - Suite 330, +# Boston, MA 02111-1307, USA. +# +# As a special exception, if you link this library with files +# compiled with GCC to produce an executable, this does not cause +# the resulting executable to be covered by the GNU General Public License. +# This exception does not however invalidate any other reasons why +# the executable file might be covered by the GNU General Public License. +# + +# This file just supplies labeled starting points for the static constructors +# and destructors. It is linked in first before other modules. + + .file "crti.s" + .ident "GNU C crti.s" + + .section .ctors,"w" + .globl __CTOR_LIST__ +__CTOR_LIST__: + + .section .dtors,"w" + .globl __DTOR_LIST__ +__DTOR_LIST__: diff --git a/gcc/config/rs6000/nt-cn.asm b/gcc/config/rs6000/nt-cn.asm new file mode 100644 index 00000000000..dd6daf29b2e --- /dev/null +++ b/gcc/config/rs6000/nt-cn.asm @@ -0,0 +1,48 @@ +# crtn.s for Windows NT + +# Copyright (C) 1996 Free Software Foundation, Inc. +# Written By Michael Meissner +# +# This file is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation; either version 2, or (at your option) any +# later version. +# +# In addition to the permissions in the GNU 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 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.) +# +# This file 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 +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; see the file COPYING. If not, write to +# the Free Software Foundation, 59 Temple Place - Suite 330, +# Boston, MA 02111-1307, USA. +# +# As a special exception, if you link this library with files +# compiled with GCC to produce an executable, this does not cause +# the resulting executable to be covered by the GNU General Public License. +# This exception does not however invalidate any other reasons why +# the executable file might be covered by the GNU General Public License. +# + +# This file just supplies labeled ending points for the static constructors +# and destructors. It is linked in last after other modules. + + .file "crtn.s" + .ident "GNU C crtn.s" + + .section .ctors,"w" + .globl __CTOR_END__ +__CTOR_END__: + + .section .dtors,"w" + .globl __DTOR_END__ +__DTOR_END__: diff --git a/gcc/config/rs6000/t-winnt b/gcc/config/rs6000/t-winnt index 847e6ac376a..d87f090ab22 100644 --- a/gcc/config/rs6000/t-winnt +++ b/gcc/config/rs6000/t-winnt @@ -1,15 +1,13 @@ # Do not build libgcc1. -LIBGCC1 = +LIBGCC = stmp-crt +INSTALL_LIBGCC = install-crt CROSS_LIBGCC1 = EXTRA_HEADERS = $(srcdir)/ginclude/ppc-asm.h -# At present, we don't have a cross linker, so turn this off -LIBGCC1_TEST = - # These are really part of libgcc1, but this will cause them to be # built correctly, so... [taken from t-sparclite] -LIB2FUNCS_EXTRA = fp-bit.c dp-bit.c ntstack.s +LIB2FUNCS_EXTRA = fp-bit.c dp-bit.c ntstack.S dp-bit.c: $(srcdir)/config/fp-bit.c cat $(srcdir)/config/fp-bit.c > dp-bit.c @@ -18,5 +16,41 @@ fp-bit.c: $(srcdir)/config/fp-bit.c echo '#define FLOAT' > fp-bit.c cat $(srcdir)/config/fp-bit.c >> fp-bit.c -ntstack.s: $(srcdir)/config/rs6000/ntstack.asm - cat $(srcdir)/config/rs6000/ntstack.asm > ntstack.s +ntstack.S: $(srcdir)/config/rs6000/ntstack.asm + cat $(srcdir)/config/rs6000/ntstack.asm > ntstack.S + +# For NT we build crti.o and crtn.o which serve to add begin and +# end labels for the static constructors and destructors. + +# Assemble startup files. +crti.s: $(srcdir)/config/rs6000/nt-ci.asm + cat $(srcdir)/config/rs6000/nt-ci.asm >crti.s + +crtn.s: $(srcdir)/config/rs6000/nt-cn.asm + cat $(srcdir)/config/rs6000/nt-cn.asm >crtn.s + +# Build multiple copies of crt{i,n}.o, one for each target switch. +stmp-crt: crti.s crtn.s $(GCC_PASSES) stmp-multilib config.status + for i in `$(GCC_FOR_TARGET) --print-multi-lib`; do \ + dir=`echo $$i | sed -e 's/;.*$$//'`; \ + flags=`echo $$i | sed -e 's/^[^;]*;//' -e 's/@/ -/g'`; \ + $(MAKE) GCC_FOR_TARGET="$(GCC_FOR_TARGET)" \ + LIBGCC2_CFLAGS="$(LIBGCC2_CFLAGS) $${flags}" \ + dir="$${dir}" stmp-crt-sub; \ + if [ $$? -eq 0 ] ; then true; else exit 1; fi; \ + done + touch stmp-crt + +# Subroutine of stmp-crt so make -n works. +stmp-crt-sub: + $(GCC_FOR_TARGET) $(LIBGCC2_CFLAGS) -c -o $(dir)/crti.o crti.s + $(GCC_FOR_TARGET) $(LIBGCC2_CFLAGS) -c -o $(dir)/crtn.o crtn.s + +# Install multiple versions of crt[in].o +install-crt: stmp-crt install-dir install-multilib + for i in `$(GCC_FOR_TARGET) --print-multi-lib`; do \ + dir=`echo $$i | sed -e 's/;.*$$//'`; \ + rm -f $(libsubdir)/$${dir}/crt[in].o; \ + $(INSTALL_DATA) $${dir}/crti.o $(libsubdir)/$${dir}/crti.o; \ + $(INSTALL_DATA) $${dir}/crtn.o $(libsubdir)/$${dir}/crtn.o; \ + done diff --git a/gcc/config/rs6000/win-nt.h b/gcc/config/rs6000/win-nt.h index c8356343df5..1d3d473dd04 100644 --- a/gcc/config/rs6000/win-nt.h +++ b/gcc/config/rs6000/win-nt.h @@ -128,32 +128,6 @@ Boston, MA 02111-1307, USA. */ output_file_directive (FILE, main_input_filename); \ } -/* Define the extra sections we need. We define three: one is the read-only - data section which is used for constants. This is a csect whose name is - derived from the name of the input file. The second is for initialized - global variables. This is a csect whose name is that of the variable. - The third is the TOC. */ - -#undef SELECT_SECTION - -#undef READONLY_DATA_SECTION -#undef EXTRA_SECTIONS -#define EXTRA_SECTIONS toc - -/* Define the routines to implement these extra sections. */ - -#undef EXTRA_SECTION_FUNCTIONS -#define EXTRA_SECTION_FUNCTIONS \ - \ -void \ -toc_section () \ -{ \ -} - - -#undef SELECT_RTX_SECTION -#undef ASM_DECLARE_FUNCTION_NAME - /* This says how to output an assembler line to define a global common symbol. */ @@ -250,6 +224,7 @@ do { \ } +#undef ASM_DECLARE_FUNCTION_NAME #define ASM_DECLARE_FUNCTION_NAME(FILE,NAME,DECL) \ { \ if (TREE_PUBLIC (DECL)) \ @@ -339,6 +314,81 @@ do { \ #undef BSS_SECTION_ASM_OP #define BSS_SECTION_ASM_OP "\t.section .bss" +/* Define the extra sections we need. We define a dummy TOC section, + plus sections to hold the list of static constructors (.ctors) and + destructors (.dtors). */ + +#undef READONLY_DATA_SECTION +#undef EXTRA_SECTIONS +#define EXTRA_SECTIONS in_toc, in_ctors, in_dtors + +/* Define the routines to implement these extra sections. */ + +#undef EXTRA_SECTION_FUNCTIONS +#define EXTRA_SECTION_FUNCTIONS \ + CTORS_SECTION_FUNCTION \ + DTORS_SECTION_FUNCTION \ + TOC_SECTION_FUNCTION \ + +#define TOC_SECTION_FUNCTION \ +void \ +toc_section () \ +{ \ +} + +#define CTORS_SECTION_ASM_OP ".section\t.ctors" +#define CTORS_SECTION_FUNCTION \ +void \ +ctors_section () \ +{ \ + if (in_section != in_ctors) \ + { \ + fprintf (asm_out_file, "%s\n", CTORS_SECTION_ASM_OP); \ + in_section = in_ctors; \ + } \ +} + +#define DTORS_SECTION_ASM_OP ".section\t.dtors" +#define DTORS_SECTION_FUNCTION \ +void \ +dtors_section () \ +{ \ + if (in_section != in_dtors) \ + { \ + fprintf (asm_out_file, "%s\n", DTORS_SECTION_ASM_OP); \ + in_section = in_dtors; \ + } \ +} + +#undef SELECT_SECTION +#undef SELECT_RTX_SECTION + +/* Make sure __main gets called */ +#define INVOKE__main 1 + +/* A C statement (sans semicolon) to output an element in the table of + global constructors. */ +#undef ASM_OUTPUT_CONSTRUCTOR +#define ASM_OUTPUT_CONSTRUCTOR(FILE,NAME) \ + do { \ + ctors_section (); \ + fprintf (FILE, "\t.ualong "); \ + assemble_name (FILE, NAME); \ + fprintf (FILE, "\n"); \ + } while (0) + +/* A C statement (sans semicolon) to output an element in the table of + global destructors. */ +#undef ASM_OUTPUT_DESTRUCTOR +#define ASM_OUTPUT_DESTRUCTOR(FILE,NAME) \ + do { \ + dtors_section (); \ + fprintf (FILE, "\t.ualong "); \ + assemble_name (FILE, NAME); \ + fprintf (FILE, "\n"); \ + } while (0) + + /* Text to write out after a CALL that may be replaced by glue code by the loader. The motorola asm demands that, for dll support, a .znop be issued after a bl instruction, and the symbol on the .znop is the