elf-dsbt.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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, write to the Free Software Foundation, Inc., 675 Mass Ave,
  24. Cambridge, MA 02139, USA. */
  25. #ifndef _BITS_ELF_DSBT_H
  26. #define _BITS_ELF_DSBT_H
  27. /* These data structures are described in the DSBT ABI.
  28. The kernel passes a process a memory map of logical
  29. load segments. For PIC code to work, all code segments
  30. must be combined into a single mapping while maintaining
  31. their relationship to one another. The same is true for
  32. RW data segments.
  33. Furthermore,
  34. segment there is an elf32_dsbt_loadseg entry. A pointer to an
  35. elf32_dsbt_loadmap is passed in GR8 at start-up, and a pointer to
  36. an additional such map is passed in GR9 for the interpreter, when
  37. there is one. */
  38. #include <elf.h>
  39. /* This data structure represents a PT_LOAD segment. */
  40. struct elf32_dsbt_loadseg
  41. {
  42. /* Core address to which the segment is mapped. */
  43. Elf32_Addr addr;
  44. /* VMA recorded in the program header. */
  45. Elf32_Addr p_vaddr;
  46. /* Size of this segment in memory. */
  47. Elf32_Word p_memsz;
  48. };
  49. struct elf32_dsbt_loadmap {
  50. /* Protocol version number, must be zero. */
  51. Elf32_Word version;
  52. /* Pointer to DSBT */
  53. unsigned *dsbt_table;
  54. unsigned dsbt_size;
  55. unsigned dsbt_index;
  56. /* number of segments */
  57. Elf32_Word nsegs;
  58. /* The actual memory map. */
  59. struct elf32_dsbt_loadseg segs[0];
  60. };
  61. struct elf32_dsbt_loadaddr {
  62. struct elf32_dsbt_loadmap *map;
  63. };
  64. /* Map a pointer's VMA to its corresponding address according to the
  65. load map. */
  66. static __always_inline void *
  67. __reloc_pointer (void *p,
  68. const struct elf32_dsbt_loadmap *map)
  69. {
  70. int c;
  71. #if 0
  72. if (map->version != 0)
  73. /* Crash. */
  74. ((void(*)())0)();
  75. #endif
  76. /* No special provision is made for NULL. We don't want NULL
  77. addresses to go through relocation, so they shouldn't be in
  78. .rofixup sections, and, if they're present in dynamic
  79. relocations, they shall be mapped to the NULL address without
  80. undergoing relocations. */
  81. for (c = 0; c < map->nsegs; c++)
  82. {
  83. unsigned long offset = p - (void*)map->segs[c].p_vaddr;
  84. /* We only check for one-past-the-end for the second segment,
  85. assumed to be the data segment, because other cases are
  86. ambiguous in the absence of padding between segments, and
  87. rofixup already serves as padding between text and data.
  88. Unfortunately, unless we special-case the second segment,
  89. we fail to relocate the _end symbol. */
  90. if (offset < map->segs[c].p_memsz
  91. || (offset == map->segs[c].p_memsz && c == 1))
  92. return (char*)map->segs[c].addr + offset;
  93. }
  94. /* We might want to crash instead. */
  95. return (void*)-1;
  96. }
  97. # define __RELOC_POINTER(ptr, loadaddr) \
  98. (__reloc_pointer ((void*)(ptr), \
  99. (loadaddr).map))
  100. #endif /* _BITS_ELF_DSBT_H */