Overview
- GCC 4.3 will be the first release where libgcc is not built from inside the GCC subdirectory. Instead, it is built from the libgcc subdirectory. The libgcc build system lives in this directory; but most of the source files and machine-specific configuration still come from gcc. Here's how you can help improve that. What's the point? Well, when libgcc no longer requires configuration data recorded during the gcc build process, it will be possible to build it separately from gcc. That's convenient especially during system bringup.
Migrating Startfiles
- The first step in fixing this problem is to migrate configuration information to the libgcc directory, one target or small group of targets at a time. This focuses on which startfiles (crtbegin.o, et cetera) will be built and how they will be built. Some targets have already been migrated. Configuration information comes from two places: gcc/config.gcc and the makefile fragments specified in gcc/config.gcc. As long as there is no information about startfiles in libgcc for the current target, the information in the gcc subdirectory will be used. If there is any information in libgcc at all, though, the information in gcc will not be used - it will only be compared to the information in libgcc as a safety check. So all startfiles for a target must switch to being built in the libgcc directory at once. To migrate a target's startfiles to the libgcc subdirectory, add an appropriate setting of extra_parts to libgcc/config.host. This should generally go under the target, but for widely ported OS's, it is better to add it under the OS pattern in the previous case statement. Note that this requires migrating all targets using that OS at once, as a group! Then, any rules for building custom startfiles must be moved to makefile fragments in libgcc. The rules can usually be simplified when doing this - for instance they only need to use $(crt_compile) in many cases. And most dependencies are no longer needed because libgcc has automatic dependency generation. If the source files are staying in gcc/config, be sure to use $(gcc_srcdir) instead of $(srcdir). When this is done, the custom rules can be deleted from the GCC subdirectory. A patch for this is almost ready (2011-08-11). It moves
- CRTSTUFF_CFLAGS, CRTSTUFF_T_CFLAGS, CRTSTUFF_T_CFLAGS_S make variables
- gcc/crtstuff.c and related make rules
- all files referenced in config.gcc extra_parts and gcc/config t-* EXTRA_PARTS
- and MULTILIB_EXTRA_PARTS
Target Macros
- The machine-specific configuration headers in gcc define several macros that are also used in libgcc. These macros must be made available during the compilation of libgcc (by having the compiler define them) or by moving their definitions into headers residing in libgcc.
A hopefully complete (as of 2011-04-02, but not including macros that are tested in libgcc code but have no non-default definitions for any target) list of relevant macros which remain to be addressed in libgcc (libgcc2.c, crtstuff.c etc.) follows.
- definable by the compiler in some fashion
MIN_UNITS_PER_WORD
BITS_PER_UNIT
UNITS_PER_WORD (config/fixed-bit.c, config/stormy16/stormy16-lib2.c)
LIBGCC2_UNITS_PER_WORD
LONG_LONG_TYPE_SIZE (config/fixed-bit.h, config/stormy16/stormy16-lib2.c, gcov-io.h)
LONG_DOUBLE_TYPE_SIZE
LIBGCC2_LONG_DOUBLE_TYPE_SIZE
WIDEST_HARDWARE_FP_SIZE
LIBGCC2_TF_CEXT
many macros indicating that extra floating-point functions should be used (LIBGCC2_HAS_DF_MODE, LIBGCC2_HAS_TF_MODE, LIBGCC2_HAS_XF_MODE, TF_SIZE, XF_SIZE)
GTHREAD_USE_WEAK
SUPPORTS_WEAK
TARGET_ATTRIBUTE_WEAK
- movable to libgcc headers
CTOR_LISTS_DEFINED_EXTERNALLY
DO_GLOBAL_CTORS_BODY
DO_GLOBAL_DTORS_BODY
TRANSFER_FROM_TRAMPOLINE
FINI_SECTION_ASM_OP
FINI_ARRAY_SECTION_ASM_OP
CTOR_LIST_BEGIN
CTOR_LIST_END
DTOR_LIST_BEGIN
DTOR_LIST_END
FORCE_CODE_SECTION_ALIGN
CRT_GET_RFIB_DATA
CRT_CALL_STATIC_FUNCTION
DWARF_REG_TO_UNWIND_COLUMN
DWARF_ZERO_REG
PRE_GCC3_DWARF_FRAME_REGISTERS
LIBGCC2_UNWIND_ATTRIBUTE
LIBGCC_SONAME (in config/i386/cygming-crtbegin.c)
LIBGCJ_SONAME (in config/i386/cygming-crtbegin.c)
OBJECT_FORMAT_FLAT
TARGET_LIBGCC_SDATA_SECTION
TARGET_POSIX_IO
USE_INITFINI_ARRAY
- used only by fp-bit, so movable to libgcc headers
LARGEST_EXPONENT_IS_NORMAL (no valid non-default definitions, remove?)
ROUND_TOWARDS_ZERO (no non-default definitions, remove?)
__make_dp (defined only for CRIS)
- used by the compiler itself and libgcc (probably predefine macros if -fbuilding-libgcc in most cases, unless predefined macros considered more generally useful)
INIT_SECTION_ASM_OP
INIT_ARRAY_SECTION_ASM_OP
TARGET_ASM_CONSTRUCTOR
HAS_INIT_SECTION
INVOKE__main
NAME__MAIN (appears to be removable from target code, default definition in libgcc2.c not actually used)
SYMBOL__MAIN
OBJECT_FORMAT_ELF
EH_FRAME_SECTION_NAME
CLEAR_INSN_CACHE
CTORS_SECTION_ASM_OP
DTORS_SECTION_ASM_OP
JCR_SECTION_NAME
DONT_USE_BUILTIN_SETJMP
DWARF_FRAME_REGISTERS
EH_RETURN_STACKADJ_RTX
EH_TABLES_CAN_BE_READ_ONLY
FIRST_PSEUDO_REGISTER
JMP_BUF_SIZE
STACK_GROWS_DOWNWARD
DEFAULT_USE_CXA_ATEXIT (in config/i386/cygming-crtend.c)
DWARF2_UNWIND_INFO (in config/i386/cygming-crtbegin.c and config/i386/cygming-crtend.c)
TARGET_ABI_OPEN_VMS (in config/ia64/unwind-ia64.c)
TARGET_EXECUTABLE_SUFFIX (in ada/targext.c)
TARGET_OBJECT_SUFFIX (in ada/targext.c)
TARGET_USE_JCR_SECTION (in config/i386/cygming-crtbegin.c and config/i386/cygming-crtend.c)
TARGET_VTABLE_USES_DESCRIPTORS
TEXT_SECTION_ASM_OP
ARG_POINTER_REGNUM (in libgcc/config/rs6000/linux-unwind.h)
DWARF_ALT_FRAME_RETURN_COLUMN (in various libgcc/config/*/*-unwind.h files)
STACK_POINTER_OFFSET (in libgcc/config/s390/tpf-unwind.h)
STACK_POINTER_REGNUM (in libgcc/config/mips/linux-unwind.h and libgcc/config/rs6000/linux-unwind.h)
TARGET_64BIT (in libgcc/config/pa/hpux-unwind.h)
- Various target macros are used by target library sources outside the gcc directory.
- used in libgcc/config/libbid
LIBGCC2_HAS_TF_MODE
BITS_PER_UNIT
LIBGCC2_HAS_XF_MODE
LIBGCC2_LONG_DOUBLE_TYPE_SIZE
LONG_DOUBLE_TYPE_SIZE
- used in libgcc/generic-morestack.c
STACK_GROWS_DOWNWARD
- used in libobjc (see PR 24775)
ADJUST_FIELD_ALIGN
BIGGEST_FIELD_ALIGNMENT
BITS_PER_UNIT
PCC_BITFIELD_TYPE_MATTERS
ROUND_TYPE_ALIGN
ROUND_TYPE_SIZE (removed from targets in 2003 but still used in libobjc)
STRUCT_VALUE
- libobjc/thr.c includes tm.h but only uses target macros via their use in gthr.h
Source Files
- Source files still live usually in the GCC subdirectory. It's easy to migrate them to libgcc once all references are in libgcc; just update references in the libgcc configure fragments to use $(srcdir) instead of $(gcc_srcdir). This is currently (2011-08-11) being worked in in multiple stages:
Shared libgcc_s build
Already posted CFT: [build] Move shlib support to toplevel libgcc. Further cleanup is possible by
- eliminating @shlib_base_name@ and related substitutions,
- doing away with gcc/config/t-slibgcc,
- centralizing sjlj exception handling tests in toplevel config
libgcc assembler sources
- A patch for this is almost ready (2011-08-11). It moves
- LIB1ASMFUNCS, LIB1ASMSRC macros and related files
- removes LIBGCC1, CROSS_LIBGCC1, LIBGCC1_TEST, all unused
Centralize PICFLAG for non-libtool shared libraries
A preliminary patch has been posted RFC: [build, ada] Centralize PICFLAG configuration. Work is underway to complete it. This is necessary for the next step.
libgcc C sources
- A patch for this is almost ready (2011-08-11). It moves
- {, HOST_, TARGET_}LIBGCC2_CFLAGS,
- LIBGCC2_DEBUG_CFLAGS,LIBGCC2_INCLUDES, LIB2_SIDITI_CONV_FUNCS, LIB2_DIVMOD_FUNCS, LIB2FUNCS_EXCLUDE, LIB2FUNCS_ST, LIB2ADD, LIB2ADD_ST, LIB2FUNCS_EXTRA, LIB2FUNCS_STATIC_EXTRA macros and related files
libgcc_tm_file
- A patch is almost ready (2011-08-11). It moves
- libgcc_tm_file from gcc/config.gcc to tm_file (libgcc/config.host).
- changes all libgcc sources that currently include tm.h to also include libgcc_tm.h.
gthr files
A patch has been posted [build] Move gthr to toplevel libgcc. Further cleanup is possible:
- Adapt guards from GCC_GTHR_* to LIBGCC_GTHR_*.
- Autoconf SUPPORTS_WEAK and move/autoconf GTHREAD_USE_WEAK.
- Substitute the result into gthr.h and simplify users to not
- determine the values themselves.
target headers
- Need to move:
- gcc/ginclude
- gcc/config.gcc (extra_headers)
- gcc/config t-* EXTRA_HEADERS and referenced files