Commit | Line | Data |
---|---|---|
acf6404e KR |
1 | /* as.c - GAS literal pool management. |
2 | Copyright (C) 1994 Free Software Foundation, Inc. | |
19302e44 | 3 | Written by Ken Raeburn (raeburn@cygnus.com). |
acf6404e KR |
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 2, 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, 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
20 | ||
21 | /* This isn't quite a "constant" pool. Some of the values may get | |
22 | adjusted at run time, e.g., for symbolic relocations when shared | |
23 | libraries are in use. It's more of a "literal" pool. | |
24 | ||
25 | On the Alpha, this should be used for .lita and .lit8. (Is there | |
26 | ever a .lit4?) On the MIPS, it could be used for .lit4 as well. | |
27 | ||
28 | The expressions passed here should contain either constants or symbols, | |
29 | *not* a combination of both. Typically, the constant pool is accessed | |
30 | with some sort of GP register, so the size of the pool must be kept down | |
31 | if possible. The exception is section offsets -- if you're storing a | |
32 | pointer to the start of .data, for example, and your machine provides | |
33 | for 16-bit signed addends, you might want to store .data+32K, so that | |
34 | you can access all of the first 64K of .data with the one pointer... */ | |
35 | ||
36 | #include "as.h" | |
37 | #include "subsegs.h" | |
38 | ||
39 | #if defined (BFD_ASSEMBLER) && defined (NEED_LITERAL_POOL) | |
40 | ||
41 | valueT | |
42 | add_to_literal_pool (sym, addend, sec, size) | |
43 | symbolS *sym; | |
44 | valueT addend; | |
45 | segT sec; | |
46 | 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; | |
19302e44 KR |
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 | for (fixp = seginfo->fix_root; fixp; fixp = fixp->fx_next, offset += size) | |
60 | { | |
61 | if (fixp->fx_addsy == sym && fixp->fx_offset == addend) | |
62 | return offset; | |
63 | } | |
acf6404e KR |
64 | |
65 | subseg_set (sec, 0); | |
66 | p = frag_more (size); | |
67 | memset (p, 0, size); | |
68 | ||
69 | switch (size) | |
70 | { | |
71 | case 4: | |
72 | reloc_type = BFD_RELOC_32; | |
73 | break; | |
74 | case 8: | |
75 | reloc_type = BFD_RELOC_64; | |
76 | break; | |
77 | default: | |
78 | abort (); | |
79 | } | |
80 | fix_new (frag_now, p - frag_now->fr_literal, size, sym, addend, 0, | |
81 | reloc_type); | |
82 | ||
83 | subseg_set (current_section, current_subsec); | |
84 | ||
19302e44 KR |
85 | offset = seginfo->literal_pool_size; |
86 | seginfo->literal_pool_size += size; | |
acf6404e KR |
87 | |
88 | return offset; | |
89 | } | |
90 | #endif /* BFD_ASSEMBLER */ |