[patch] moving macro definitions to defaults.h
David Malcolm
dmalcolm@redhat.com
Mon Sep 22 16:51:00 GMT 2014
On Mon, 2014-09-22 at 12:26 -0400, Andrew MacLeod wrote:
> After being reminded of the tm.h issues brought up last november (here:
> https://gcc.gnu.org/ml/gcc-patches/2013-11/msg01731.html ), I started
> looking back into it.
>
> The general summary is the any header file which has a conditional on a
> target macro could be affected by include file reordering... ie, if a
> header file has
> #ifdef BLAH
> <whatever>
>
> and we move the header files around a bit, it wouldn't be immediately
> obvious if the order where changes and BLAH was define later in the
> include structure. The results for this header files would be different
> because <whatever> would no longer be in the preprocess source, and it
> may take a long time to discover the difference.
>
> Josephs solution was to identify these and instead put a default
> definition in default.h ... then change all the uses to #if instead.. ie,
> #if BLAH
>
> This way we can ensure that the definition has been seen and it will be
> a compile error if not.
>
>
> I looked at all the target macros listed by Joseph, and decide to start
> with the ones which are used *only* in an "if defined" situation in a .h
> files of some sort.
> ie
> #ifdef
> #ifndef
> or #if define()
>
> If this happens in a .c file, then changing the order of .h's shouldn't
> matter. (Unless the .c file is doing something really screwy. So for
> the moment, ignoring that.)
There appears to be a particular implicit order in which headers must be
included. I notice that e.g. tm.h has:
#ifndef GCC_TM_H
#define GCC_TM_H
so if we're going with this "no header file includes any other header
file" model, would it make sense to add something like:
#ifndef GCC_TM_H
#error tm.h must have been included by this point
/* We need tm.h here so that we can see: BAR, BAZ, QUUX,
etc. */
#endif
to header files needing it, thus expressing the expected dependencies
explicitly?
> So looking at only .h files, I found a number of default definitions in
> rtl.h, which this patch moves to defaults.h. I was going to #error if
> defaults.h wasn't included, but found that to be unnecessary since it
> uses some of those macros and would cause a compile failure anyway if it
> wasn't included. All the other uses of these particular macros use the
> #if model, so no further adjustment is required for them.
>
> This patch bootstraps on x86_64-unknown-linux-gnu, and regressions are
> running. Assuming no issues show up, OK for mainline?
>
> The remaining macros I will have a closer look at and most will likely
> need the full treatment moving from #ifdef to the #if model. I plan to
> do these next. The macros which fit this category for potential header
> trouble (along with their usage count) are:
>
> 2 USE_COLLECT2
> 3 TARGET_TERMINATE_DW2_EH_FRAME_INFO
> 3 TARGET_HAVE_CTORS_DTORS
> 3 REGMODE_NATURAL_SIZE
> 4 CC_STATUS_MDEP_INIT
> 4 CC_STATUS_MDEP_INIT
> 4 MODE_BASE_REG_REG_CLASS
> 4 REGNO_MODE_OK_FOR_REG_BASE_P
> 5 MODE_BASE_REG_CLASS
> 5 XCOFF_DEBUGGING_INFO
> 6 VMS_DEBUGGING_INFO
> 6 TARGET_ASM_OUTPUT_ANCHOR
> 6 EH_FRAME_SECTION_NAME
> 8 MODE_CODE_BASE_REG_CLASS
> 9 HARD_REGNO_CALLER_SAVE_MODE
> 9 HARD_REGNO_CALL_PART_CLOBBERED
> 9 SDB_DEBUGGING_INFO
> 9 CC_STATUS_MDEP
> 9 REGNO_MODE_CODE_OK_FOR_BASE_P
> 10 SECONDARY_RELOAD_CLASS
> 10 TARGET_VXWORKS_RTP
> 14 NO_DOT_IN_LABEL
> 14 REGNO_MODE_OK_FOR_BASE_P
> 17 STACK_REGS
> 19 TARGET_ASM_DESTRUCTOR
> 20 OBJECT_FORMAT_ELF
> 20 TARGET_ASM_CONSTRUCTOR
> 24 NO_DOLLAR_IN_LABEL
> 26 DBX_DEBUGGING_INFO
> 30 CPLUSPLUS_CPP_SPEC
> 42 ASM_OUTPUT_DEF
>
>
>
>
More information about the Gcc-patches
mailing list