elf-dsbt.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /* Copyright (C) 2010 Texas Instruments Incorporated
  2. Borrowed heavily from frv arch:
  3. Copyright 2003, 2004 Free Software Foundation, Inc.
  4. This file is part of the GNU C Library.
  5. The GNU C Library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public License as
  7. published by the Free Software Foundation; either version 2.1 of the
  8. License, or (at your option) any later version.
  9. In addition to the permissions in the GNU Lesser General Public
  10. License, the Free Software Foundation gives you unlimited
  11. permission to link the compiled version of this file with other
  12. programs, and to distribute those programs without any restriction
  13. coming from the use of this file. (The GNU Lesser General Public
  14. License restrictions do apply in other respects; for example, they
  15. cover modification of the file, and distribution when not linked
  16. into another program.)
  17. The GNU C Library is distributed in the hope that it will be useful,
  18. but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  20. Library General Public License for more details.
  21. You should have received a copy of the GNU Lesser General Public
  22. License along with the GNU C Library; see the file COPYING.LIB. If
  23. not, see <http://www.gnu.org/licenses/>. */
  24. #ifndef _BITS_ELF_DSBT_H
  25. #define _BITS_ELF_DSBT_H
  26. /* These data structures are described in the DSBT ABI.
  27. The kernel passes a process a memory map of logical
  28. load segments. For PIC code to work, all code segments
  29. must be combined into a single mapping while maintaining
  30. their relationship to one another. The same is true for
  31. RW data segments.
  32. Furthermore,
  33. segment there is an elf32_dsbt_loadseg entry. A pointer to an
  34. elf32_dsbt_loadmap is passed in GR8 at start-up, and a pointer to
  35. an additional such map is passed in GR9 for the interpreter, when
  36. there is one. */
  37. #include <elf.h>
  38. /* This data structure represents a PT_LOAD segment. */
  39. struct elf32_dsbt_loadseg
  40. {
  41. /* Core address to which the segment is mapped. */
  42. Elf32_Addr addr;
  43. /* VMA recorded in the program header. */
  44. Elf32_Addr p_vaddr;
  45. /* Size of this segment in memory. */
  46. Elf32_Word p_memsz;
  47. };
  48. struct elf32_dsbt_loadmap {
  49. /* Protocol version number, must be zero. */
  50. Elf32_Half version;
  51. /* number of segments */
  52. Elf32_Half nsegs;
  53. /* The actual memory map. */
  54. struct elf32_dsbt_loadseg segs[0];
  55. };
  56. struct elf32_dsbt_loadaddr {
  57. struct elf32_dsbt_loadmap *map;
  58. };
  59. /* Map a pointer's VMA to its corresponding address according to the
  60. load map. */
  61. static __always_inline void *
  62. __reloc_pointer (void *p,
  63. const struct elf32_dsbt_loadmap *map)
  64. {
  65. int c;
  66. #if 0
  67. if (map->version != 0)
  68. /* Crash. */
  69. ((void(*)())0)();
  70. #endif
  71. /* No special provision is made for NULL. We don't want NULL
  72. addresses to go through relocation, so they shouldn't be in
  73. .rofixup sections, and, if they're present in dynamic
  74. relocations, they shall be mapped to the NULL address without
  75. undergoing relocations. */
  76. for (c = 0; c < map->nsegs; c++)
  77. {
  78. unsigned long offset = (char*)p - (char*)map->segs[c].p_vaddr;
  79. /* We only check for one-past-the-end for the second segment,
  80. assumed to be the data segment, because other cases are
  81. ambiguous in the absence of padding between segments, and
  82. rofixup already serves as padding between text and data.
  83. Unfortunately, unless we special-case the second segment,
  84. we fail to relocate the _end symbol. */
  85. if (offset < map->segs[c].p_memsz
  86. || (offset == map->segs[c].p_memsz && c == 1))
  87. return (char*)map->segs[c].addr + offset;
  88. }
  89. /* We might want to crash instead. */
  90. return (void*)-1;
  91. }
  92. # define __RELOC_POINTER(ptr, loadaddr) \
  93. (__reloc_pointer ((void*)(ptr), \
  94. (loadaddr).map))
  95. #endif /* _BITS_ELF_DSBT_H */