subsegs.h revision 60484
133965Sjdp/* subsegs.h -> subsegs.c
260484Sobrien   Copyright (C) 1987, 92, 93, 94, 95, 96, 1998 Free Software Foundation, Inc.
333965Sjdp
433965Sjdp   This file is part of GAS, the GNU Assembler.
533965Sjdp
633965Sjdp   GAS is free software; you can redistribute it and/or modify
733965Sjdp   it under the terms of the GNU General Public License as published by
833965Sjdp   the Free Software Foundation; either version 2, or (at your option)
933965Sjdp   any later version.
1033965Sjdp
1133965Sjdp   GAS is distributed in the hope that it will be useful,
1233965Sjdp   but WITHOUT ANY WARRANTY; without even the implied warranty of
1333965Sjdp   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1433965Sjdp   GNU General Public License for more details.
1533965Sjdp
1633965Sjdp   You should have received a copy of the GNU General Public License
1760484Sobrien   along with GAS; see the file COPYING.  If not, write to the Free
1860484Sobrien   Software Foundation, 59 Temple Place - Suite 330, Boston, MA
1960484Sobrien   02111-1307, USA.  */
2033965Sjdp
2133965Sjdp/*
2233965Sjdp * For every sub-segment the user mentions in the ASsembler program,
2333965Sjdp * we make one struct frchain. Each sub-segment has exactly one struct frchain
2433965Sjdp * and vice versa.
2533965Sjdp *
2633965Sjdp * Struct frchain's are forward chained (in ascending order of sub-segment
2733965Sjdp * code number). The chain runs through frch_next of each subsegment.
2833965Sjdp * This makes it hard to find a subsegment's frags
2933965Sjdp * if programmer uses a lot of them. Most programs only use text0 and
3033965Sjdp * data0, so they don't suffer. At least this way:
3133965Sjdp * (1)	There are no "arbitrary" restrictions on how many subsegments
3233965Sjdp *	can be programmed;
3333965Sjdp * (2)	Subsegments' frchain-s are (later) chained together in the order in
3433965Sjdp *	which they are emitted for object file viz text then data.
3533965Sjdp *
3633965Sjdp * From each struct frchain dangles a chain of struct frags. The frags
3733965Sjdp * represent code fragments, for that sub-segment, forward chained.
3833965Sjdp */
3933965Sjdp
4033965Sjdp#include "obstack.h"
4133965Sjdp
4233965Sjdpstruct frchain			/* control building of a frag chain */
4333965Sjdp{				/* FRCH = FRagment CHain control */
4433965Sjdp  struct frag *frch_root;	/* 1st struct frag in chain, or NULL */
4533965Sjdp  struct frag *frch_last;	/* last struct frag in chain, or NULL */
4633965Sjdp  struct frchain *frch_next;	/* next in chain of struct frchain-s */
4733965Sjdp  segT frch_seg;		/* SEG_TEXT or SEG_DATA. */
4833965Sjdp  subsegT frch_subseg;		/* subsegment number of this chain */
4933965Sjdp#ifdef BFD_ASSEMBLER
5033965Sjdp  fixS *fix_root;		/* Root of fixups for this subsegment.  */
5133965Sjdp  fixS *fix_tail;		/* Last fixup for this subsegment.  */
5233965Sjdp#endif
5333965Sjdp  struct obstack frch_obstack;	/* for objects in this frag chain */
5433965Sjdp  fragS *frch_frag_now;		/* frag_now for this subsegment */
5533965Sjdp};
5633965Sjdp
5733965Sjdptypedef struct frchain frchainS;
5833965Sjdp
5933965Sjdp/* All subsegments' chains hang off here.  NULL means no frchains yet.  */
6033965Sjdpextern frchainS *frchain_root;
6133965Sjdp
6233965Sjdp/* Frchain we are assembling into now.  That is, the current segment's
6333965Sjdp   frag chain, even if it contains no (complete) frags. */
6433965Sjdpextern frchainS *frchain_now;
6533965Sjdp
6633965Sjdp
6760484Sobrientypedef struct segment_info_struct
6833965Sjdp{
6933965Sjdp  frchainS *frchainP;
7033965Sjdp  unsigned int hadone : 1;
7133965Sjdp
7233965Sjdp  /* This field is set if this is a .bss section which does not really
7333965Sjdp     have any contents.  Once upon a time a .bss section did not have
7433965Sjdp     any frags, but that is no longer true.  This field prevent the
7533965Sjdp     SEC_HAS_CONTENTS flag from being set for the section even if
7633965Sjdp     there are frags.  */
7733965Sjdp  unsigned int bss : 1;
7833965Sjdp
7933965Sjdp  int user_stuff;
8033965Sjdp
8133965Sjdp  /* Fixups for this segment.  If BFD_ASSEMBLER, this is only valid
8233965Sjdp     after the frchains are run together.  */
8333965Sjdp  fixS *fix_root;
8433965Sjdp  fixS *fix_tail;
8533965Sjdp
8633965Sjdp#if defined (MANY_SEGMENTS) && !defined (BFD_ASSEMBLER)
8733965Sjdp  struct internal_scnhdr scnhdr;
8833965Sjdp  enum linkonce_type linkonce;
8933965Sjdp  const char *name;
9033965Sjdp#endif
9133965Sjdp
9233965Sjdp  symbolS *dot;
9333965Sjdp
9433965Sjdp  struct lineno_list *lineno_list_head;
9533965Sjdp  struct lineno_list *lineno_list_tail;
9633965Sjdp
9733965Sjdp#ifdef BFD_ASSEMBLER
9833965Sjdp  /* Which BFD section does this gas segment correspond to?  */
9933965Sjdp  asection *bfd_section;
10033965Sjdp
10133965Sjdp  /* NULL, or pointer to the gas symbol that is the section symbol for
10233965Sjdp     this section.  sym->bsym and bfd_section->symbol should be the same.  */
10333965Sjdp  symbolS *sym;
10433965Sjdp#endif
10533965Sjdp
10633965Sjdp  union
10733965Sjdp    {
10833965Sjdp      /* Current size of section holding stabs strings.  */
10933965Sjdp      unsigned long stab_string_size;
11033965Sjdp      /* Initial frag for ELF.  */
11133965Sjdp      char *p;
11233965Sjdp    }
11333965Sjdp  stabu;
11433965Sjdp
11533965Sjdp#ifdef NEED_LITERAL_POOL
11633965Sjdp  unsigned long literal_pool_size;
11733965Sjdp#endif
11833965Sjdp
11933965Sjdp#ifdef TC_SEGMENT_INFO_TYPE
12033965Sjdp  TC_SEGMENT_INFO_TYPE tc_segment_info_data;
12133965Sjdp#endif
12233965Sjdp} segment_info_type;
12333965Sjdp
12433965Sjdp#ifdef BFD_ASSEMBLER
12533965Sjdp
12633965Sjdpextern segment_info_type *seg_info PARAMS ((segT));
12733965Sjdpextern symbolS *section_symbol PARAMS ((segT));
12833965Sjdp
12933965Sjdp#else /* ! BFD_ASSEMBLER */
13033965Sjdp
13133965Sjdp#ifdef MANY_SEGMENTS
13233965Sjdp
13333965Sjdpextern segment_info_type segment_info[];
13433965Sjdp
13533965Sjdp#define seg_info(SEC)	(&segment_info[SEC])
13633965Sjdp
13733965Sjdp#else
13833965Sjdp
13933965Sjdp/* Sentinel for frchain crawling.  Points to the 1st data-segment
14033965Sjdp   frchain.  (Which is pointed to by the last text-segment frchain.) */
14133965Sjdpextern frchainS *data0_frchainP;
14233965Sjdpextern frchainS *bss0_frchainP;
14333965Sjdp
14433965Sjdp/* Dummy so stuff can compile.  Should never be used.  */
14533965Sjdpstruct seg_info_trash {
14633965Sjdp  struct {
14733965Sjdp    unsigned stab_string_size : 1;
14833965Sjdp  } stabu;
14933965Sjdp  unsigned hadone : 1;
15033965Sjdp};
15133965Sjdp#define seg_info(S)	(abort (), (struct seg_info_trash *) 0)
15233965Sjdp
15333965Sjdp#endif
15433965Sjdp
15533965Sjdp#endif /* ! BFD_ASSEMBLER */
15633965Sjdp
15733965Sjdpextern void subsegs_print_statistics PARAMS ((FILE *));
15833965Sjdp
15933965Sjdp/* end of subsegs.h */
160