elf-dsbt.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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_Half version;
  52. /* number of segments */
  53. Elf32_Half nsegs;
  54. /* The actual memory map. */
  55. struct elf32_dsbt_loadseg segs[0];
  56. };
  57. struct elf32_dsbt_loadaddr {
  58. struct elf32_dsbt_loadmap *map;
  59. };
  60. /* Map a pointer's VMA to its corresponding address according to the
  61. load map. */
  62. static __always_inline void *
  63. __reloc_pointer (void *p,
  64. const struct elf32_dsbt_loadmap *map)
  65. {
  66. int c;
  67. #if 0
  68. if (map->version != 0)
  69. /* Crash. */
  70. ((void(*)())0)();
  71. #endif
  72. /* No special provision is made for NULL. We don't want NULL
  73. addresses to go through relocation, so they shouldn't be in
  74. .rofixup sections, and, if they're present in dynamic
  75. relocations, they shall be mapped to the NULL address without
  76. undergoing relocations. */
  77. for (c = 0; c < map->nsegs; c++)
  78. {
  79. unsigned long offset = p - (void*)map->segs[c].p_vaddr;
  80. /* We only check for one-past-the-end for the second segment,
  81. assumed to be the data segment, because other cases are
  82. ambiguous in the absence of padding between segments, and
  83. rofixup already serves as padding between text and data.
  84. Unfortunately, unless we special-case the second segment,
  85. we fail to relocate the _end symbol. */
  86. if (offset < map->segs[c].p_memsz
  87. || (offset == map->segs[c].p_memsz && c == 1))
  88. return (char*)map->segs[c].addr + offset;
  89. }
  90. /* We might want to crash instead. */
  91. return (void*)-1;
  92. }
  93. # define __RELOC_POINTER(ptr, loadaddr) \
  94. (__reloc_pointer ((void*)(ptr), \
  95. (loadaddr).map))
  96. #endif /* _BITS_ELF_DSBT_H */