(root)/
binutils-2.41/
gas/
literal.c
       1  /* literal.c - GAS literal pool management.
       2     Copyright (C) 1994-2023 Free Software Foundation, Inc.
       3     Written by Ken Raeburn (raeburn@cygnus.com).
       4  
       5     This file is part of GAS, the GNU Assembler.
       6  
       7     GAS is free software; you can redistribute it and/or modify
       8     it under the terms of the GNU General Public License as published by
       9     the Free Software Foundation; either version 3, or (at your option)
      10     any later version.
      11  
      12     GAS is distributed in the hope that it will be useful,
      13     but WITHOUT ANY WARRANTY; without even the implied warranty of
      14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      15     GNU General Public License for more details.
      16  
      17     You should have received a copy of the GNU General Public License
      18     along with GAS; see the file COPYING.  If not, write to
      19     the Free Software Foundation, 51 Franklin Street - Fifth Floor,
      20     Boston, MA 02110-1301, USA.  */
      21  
      22  /* This isn't quite a "constant" pool.  Some of the values may get
      23     adjusted at run time, e.g., for symbolic relocations when shared
      24     libraries are in use.  It's more of a "literal" pool.
      25  
      26     On the Alpha, this should be used for .lita and .lit8.  (Is there
      27     ever a .lit4?)  On the MIPS, it could be used for .lit4 as well.
      28  
      29     The expressions passed here should contain either constants or symbols,
      30     not a combination of both.  Typically, the constant pool is accessed
      31     with some sort of GP register, so the size of the pool must be kept down
      32     if possible.  The exception is section offsets -- if you're storing a
      33     pointer to the start of .data, for example, and your machine provides
      34     for 16-bit signed addends, you might want to store .data+32K, so that
      35     you can access all of the first 64K of .data with the one pointer.
      36  
      37     This isn't a requirement, just a guideline that can help keep .o file
      38     size down.  */
      39  
      40  #include "as.h"
      41  #include "subsegs.h"
      42  
      43  #ifdef NEED_LITERAL_POOL
      44  
      45  valueT
      46  add_to_literal_pool (symbolS *sym, valueT addend, segT sec, int size)
      47  {
      48    segT current_section = now_seg;
      49    int current_subsec = now_subseg;
      50    valueT offset;
      51    bfd_reloc_code_real_type reloc_type;
      52    char *p;
      53    segment_info_type *seginfo = seg_info (sec);
      54    fixS *fixp;
      55  
      56    offset = 0;
      57    /* @@ This assumes all entries in a given section will be of the same
      58       size...  Probably correct, but unwise to rely on.  */
      59    /* This must always be called with the same subsegment.  */
      60    if (seginfo->frchainP)
      61      for (fixp = seginfo->frchainP->fix_root;
      62  	 fixp != (fixS *) NULL;
      63  	 fixp = fixp->fx_next, offset += size)
      64        {
      65  	if (fixp->fx_addsy == sym && fixp->fx_offset == addend)
      66  	  return offset;
      67        }
      68  
      69    subseg_set (sec, 0);
      70    p = frag_more (size);
      71    memset (p, 0, size);
      72  
      73    switch (size)
      74      {
      75      case 4:
      76        reloc_type = BFD_RELOC_32;
      77        break;
      78      case 8:
      79        reloc_type = BFD_RELOC_64;
      80        break;
      81      default:
      82        abort ();
      83      }
      84    fix_new (frag_now, p - frag_now->fr_literal, size, sym, addend, 0,
      85  	   reloc_type);
      86  
      87    subseg_set (current_section, current_subsec);
      88    offset = seginfo->literal_pool_size;
      89    seginfo->literal_pool_size += size;
      90    return offset;
      91  }
      92  #endif