Back to index

cell-binutils  2.17cvs20070401
literal.c
Go to the documentation of this file.
00001 /* literal.c - GAS literal pool management.
00002    Copyright 1994, 2000, 2005 Free Software Foundation, Inc.
00003    Written by Ken Raeburn (raeburn@cygnus.com).
00004 
00005    This file is part of GAS, the GNU Assembler.
00006 
00007    GAS is free software; you can redistribute it and/or modify
00008    it under the terms of the GNU General Public License as published by
00009    the Free Software Foundation; either version 2, or (at your option)
00010    any later version.
00011 
00012    GAS is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015    GNU General Public License for more details.
00016 
00017    You should have received a copy of the GNU General Public License
00018    along with GAS; see the file COPYING.  If not, write to
00019    the Free Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */
00020 
00021 /* This isn't quite a "constant" pool.  Some of the values may get
00022    adjusted at run time, e.g., for symbolic relocations when shared
00023    libraries are in use.  It's more of a "literal" pool.
00024 
00025    On the Alpha, this should be used for .lita and .lit8.  (Is there
00026    ever a .lit4?)  On the MIPS, it could be used for .lit4 as well.
00027 
00028    The expressions passed here should contain either constants or symbols,
00029    not a combination of both.  Typically, the constant pool is accessed
00030    with some sort of GP register, so the size of the pool must be kept down
00031    if possible.  The exception is section offsets -- if you're storing a
00032    pointer to the start of .data, for example, and your machine provides
00033    for 16-bit signed addends, you might want to store .data+32K, so that
00034    you can access all of the first 64K of .data with the one pointer.
00035 
00036    This isn't a requirement, just a guideline that can help keep .o file
00037    size down.  */
00038 
00039 #include "as.h"
00040 #include "subsegs.h"
00041 
00042 #ifdef NEED_LITERAL_POOL
00043 
00044 valueT
00045 add_to_literal_pool (sym, addend, sec, size)
00046      symbolS *sym;
00047      valueT addend;
00048      segT sec;
00049      int size;
00050 {
00051   segT current_section = now_seg;
00052   int current_subsec = now_subseg;
00053   valueT offset;
00054   bfd_reloc_code_real_type reloc_type;
00055   char *p;
00056   segment_info_type *seginfo = seg_info (sec);
00057   fixS *fixp;
00058 
00059   offset = 0;
00060   /* @@ This assumes all entries in a given section will be of the same
00061      size...  Probably correct, but unwise to rely on.  */
00062   /* This must always be called with the same subsegment.  */
00063   if (seginfo->frchainP)
00064     for (fixp = seginfo->frchainP->fix_root;
00065         fixp != (fixS *) NULL;
00066         fixp = fixp->fx_next, offset += size)
00067       {
00068        if (fixp->fx_addsy == sym && fixp->fx_offset == addend)
00069          return offset;
00070       }
00071 
00072   subseg_set (sec, 0);
00073   p = frag_more (size);
00074   memset (p, 0, size);
00075 
00076   switch (size)
00077     {
00078     case 4:
00079       reloc_type = BFD_RELOC_32;
00080       break;
00081     case 8:
00082       reloc_type = BFD_RELOC_64;
00083       break;
00084     default:
00085       abort ();
00086     }
00087   fix_new (frag_now, p - frag_now->fr_literal, size, sym, addend, 0,
00088           reloc_type);
00089 
00090   subseg_set (current_section, current_subsec);
00091   offset = seginfo->literal_pool_size;
00092   seginfo->literal_pool_size += size;
00093   return offset;
00094 }
00095 #endif