literal.c 3.0 KB

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