literal.c revision 1.1.1.1
1193323Sed/* literal.c - GAS literal pool management. 2193323Sed Copyright 1994, 2000, 2005 Free Software Foundation, Inc. 3193323Sed Written by Ken Raeburn (raeburn@cygnus.com). 4193323Sed 5193323Sed This file is part of GAS, the GNU Assembler. 6193323Sed 7193323Sed GAS is free software; you can redistribute it and/or modify 8193323Sed it under the terms of the GNU General Public License as published by 9193323Sed the Free Software Foundation; either version 2, or (at your option) 10193323Sed any later version. 11193323Sed 12193323Sed GAS is distributed in the hope that it will be useful, 13193323Sed but WITHOUT ANY WARRANTY; without even the implied warranty of 14193323Sed MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15193323Sed GNU General Public License for more details. 16193323Sed 17193323Sed You should have received a copy of the GNU General Public License 18234353Sdim along with GAS; see the file COPYING. If not, write to 19193323Sed the Free Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ 20193323Sed 21212904Sdim/* This isn't quite a "constant" pool. Some of the values may get 22212904Sdim adjusted at run time, e.g., for symbolic relocations when shared 23193323Sed libraries are in use. It's more of a "literal" pool. 24193323Sed 25193323Sed On the Alpha, this should be used for .lita and .lit8. (Is there 26193323Sed ever a .lit4?) On the MIPS, it could be used for .lit4 as well. 27193323Sed 28193323Sed The expressions passed here should contain either constants or symbols, 29193323Sed not a combination of both. Typically, the constant pool is accessed 30193323Sed with some sort of GP register, so the size of the pool must be kept down 31193323Sed if possible. The exception is section offsets -- if you're storing a 32193323Sed pointer to the start of .data, for example, and your machine provides 33193323Sed for 16-bit signed addends, you might want to store .data+32K, so that 34193323Sed you can access all of the first 64K of .data with the one pointer. 35193323Sed 36193323Sed This isn't a requirement, just a guideline that can help keep .o file 37193323Sed size down. */ 38218893Sdim 39218893Sdim#include "as.h" 40218893Sdim#include "subsegs.h" 41218893Sdim 42193323Sed#ifdef NEED_LITERAL_POOL 43193323Sed 44239462SdimvalueT 45239462Sdimadd_to_literal_pool (sym, addend, sec, size) 46239462Sdim symbolS *sym; 47193323Sed valueT addend; 48193323Sed segT sec; 49193323Sed int size; 50193323Sed{ 51193323Sed segT current_section = now_seg; 52193323Sed int current_subsec = now_subseg; 53198090Srdivacky valueT offset; 54193323Sed bfd_reloc_code_real_type reloc_type; 55193323Sed char *p; 56193323Sed segment_info_type *seginfo = seg_info (sec); 57193323Sed fixS *fixp; 58193323Sed 59239462Sdim offset = 0; 60195340Sed /* @@ This assumes all entries in a given section will be of the same 61193323Sed size... Probably correct, but unwise to rely on. */ 62193323Sed /* This must always be called with the same subsegment. */ 63193323Sed if (seginfo->frchainP) 64234353Sdim for (fixp = seginfo->frchainP->fix_root; 65193323Sed fixp != (fixS *) NULL; 66193323Sed fixp = fixp->fx_next, offset += size) 67210299Sed { 68210299Sed if (fixp->fx_addsy == sym && fixp->fx_offset == addend) 69202878Srdivacky return offset; 70202878Srdivacky } 71193323Sed 72193323Sed subseg_set (sec, 0); 73193323Sed p = frag_more (size); 74193323Sed memset (p, 0, size); 75193323Sed 76193323Sed switch (size) 77193323Sed { 78193323Sed case 4: 79193323Sed reloc_type = BFD_RELOC_32; 80226633Sdim break; 81226633Sdim case 8: 82226633Sdim reloc_type = BFD_RELOC_64; 83226633Sdim break; 84226633Sdim default: 85199481Srdivacky abort (); 86199481Srdivacky } 87193323Sed fix_new (frag_now, p - frag_now->fr_literal, size, sym, addend, 0, 88218893Sdim reloc_type); 89218893Sdim 90193323Sed subseg_set (current_section, current_subsec); 91210299Sed offset = seginfo->literal_pool_size; 92210299Sed seginfo->literal_pool_size += size; 93194710Sed return offset; 94194710Sed} 95198090Srdivacky#endif 96198090Srdivacky