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