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