1 | /* as.c - GAS literal pool management.
|
---|
2 | Copyright 1994, 2000 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 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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 | This isn't a requirement, just a guideline that can help keep .o file
|
---|
37 | size down. */
|
---|
38 |
|
---|
39 | #include "as.h"
|
---|
40 | #include "subsegs.h"
|
---|
41 |
|
---|
42 | #if defined (BFD_ASSEMBLER) && defined (NEED_LITERAL_POOL)
|
---|
43 |
|
---|
44 | valueT
|
---|
45 | add_to_literal_pool (sym, addend, sec, size)
|
---|
46 | symbolS *sym;
|
---|
47 | valueT addend;
|
---|
48 | segT sec;
|
---|
49 | int size;
|
---|
50 | {
|
---|
51 | segT current_section = now_seg;
|
---|
52 | int current_subsec = now_subseg;
|
---|
53 | valueT offset;
|
---|
54 | bfd_reloc_code_real_type reloc_type;
|
---|
55 | char *p;
|
---|
56 | segment_info_type *seginfo = seg_info (sec);
|
---|
57 | fixS *fixp;
|
---|
58 |
|
---|
59 | offset = 0;
|
---|
60 | /* @@ This assumes all entries in a given section will be of the same
|
---|
61 | size... Probably correct, but unwise to rely on. */
|
---|
62 | /* This must always be called with the same subsegment. */
|
---|
63 | if (seginfo->frchainP)
|
---|
64 | for (fixp = seginfo->frchainP->fix_root;
|
---|
65 | fixp != (fixS *) NULL;
|
---|
66 | fixp = fixp->fx_next, offset += size)
|
---|
67 | {
|
---|
68 | if (fixp->fx_addsy == sym && fixp->fx_offset == addend)
|
---|
69 | return offset;
|
---|
70 | }
|
---|
71 |
|
---|
72 | subseg_set (sec, 0);
|
---|
73 | p = frag_more (size);
|
---|
74 | memset (p, 0, size);
|
---|
75 |
|
---|
76 | switch (size)
|
---|
77 | {
|
---|
78 | case 4:
|
---|
79 | reloc_type = BFD_RELOC_32;
|
---|
80 | break;
|
---|
81 | case 8:
|
---|
82 | reloc_type = BFD_RELOC_64;
|
---|
83 | break;
|
---|
84 | default:
|
---|
85 | abort ();
|
---|
86 | }
|
---|
87 | fix_new (frag_now, p - frag_now->fr_literal, size, sym, addend, 0,
|
---|
88 | reloc_type);
|
---|
89 |
|
---|
90 | subseg_set (current_section, current_subsec);
|
---|
91 | offset = seginfo->literal_pool_size;
|
---|
92 | seginfo->literal_pool_size += size;
|
---|
93 | return offset;
|
---|
94 | }
|
---|
95 | #endif /* BFD_ASSEMBLER */
|
---|