dont-guess-section-alignment.patch 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. From: Sylvain Gault <sylvain.gault at gmail.com>
  2. For the compression / decompression to succeed, the sections layout must
  3. be the same between the virtual memory and load memory. The section
  4. alignment was kept in sync by introducing aligment that should be
  5. greater or equal to the actual section alignment.
  6. This patch compute the load memory addresses of the sections so that
  7. the layout is the same as the virtual memory addresses.
  8. Signed-off-by: Sylvain Gault <sylvain.gault at gmail.com>
  9. ---
  10. core/i386/syslinux.ld | 63 ++++++++++---------------------------------------
  11. core/x86_64/syslinux.ld | 63 ++++++++++---------------------------------------
  12. 2 files changed, 24 insertions(+), 102 deletions(-)
  13. diff --git a/core/i386/syslinux.ld b/core/i386/syslinux.ld
  14. index 7390451..92b75b1 100644
  15. --- a/core/i386/syslinux.ld
  16. +++ b/core/i386/syslinux.ld
  17. @@ -255,10 +255,9 @@ SECTIONS
  18. . = 0x100000;
  19. __pm_code_start = .;
  20. + __vma_to_lma = __pm_code_lma - __pm_code_start;
  21. - __text_vma = .;
  22. - __text_lma = __pm_code_lma;
  23. - .text : AT(__text_lma) {
  24. + .text : AT(ADDR(.text) + __vma_to_lma) {
  25. FILL(0x90909090)
  26. __text_start = .;
  27. *(.text)
  28. @@ -266,106 +265,68 @@ SECTIONS
  29. __text_end = .;
  30. }
  31. - . = ALIGN(32);
  32. -
  33. - __rodata_vma = .;
  34. - __rodata_lma = __rodata_vma + __text_lma - __text_vma;
  35. - .rodata : AT(__rodata_lma) {
  36. + .rodata : AT(ADDR(.rodata) + __vma_to_lma) {
  37. __rodata_start = .;
  38. *(.rodata)
  39. *(.rodata.*)
  40. __rodata_end = .;
  41. }
  42. - . = ALIGN(4);
  43. -
  44. - __ctors_vma = .;
  45. - __ctors_lma = __ctors_vma + __text_lma - __text_vma;
  46. - .ctors : AT(__ctors_lma) {
  47. + .ctors : AT(ADDR(.ctors) + __vma_to_lma) {
  48. __ctors_start = .;
  49. KEEP (*(SORT(.ctors.*)))
  50. KEEP (*(.ctors))
  51. __ctors_end = .;
  52. }
  53. - __dtors_vma = .;
  54. - __dtors_lma = __dtors_vma + __text_lma - __text_vma;
  55. - .dtors : AT(__dtors_lma) {
  56. + .dtors : AT(ADDR(.dtors) + __vma_to_lma) {
  57. __dtors_start = .;
  58. KEEP (*(SORT(.dtors.*)))
  59. KEEP (*(.dtors))
  60. __dtors_end = .;
  61. }
  62. - . = ALIGN(4);
  63. -
  64. - __dynsym_vma = .;
  65. - __dynsym_lma = __dynsym_vma + __text_lma - __text_vma;
  66. - .dynsym : AT(__dynsym_lma) {
  67. + .dynsym : AT(ADDR(.dynsym) + __vma_to_lma) {
  68. __dynsym_start = .;
  69. *(.dynsym)
  70. __dynsym_end = .;
  71. }
  72. __dynsym_len = __dynsym_end - __dynsym_start;
  73. - . = ALIGN(4);
  74. -
  75. - __dynstr_vma = .;
  76. - __dynstr_lma = __dynstr_vma + __text_lma - __text_vma;
  77. - .dynstr : AT(__dynstr_lma) {
  78. + .dynstr : AT(ADDR(.dynstr) + __vma_to_lma) {
  79. __dynstr_start = .;
  80. *(.dynstr)
  81. __dynstr_end = .;
  82. }
  83. __dynstr_len = __dynstr_end - __dynstr_start;
  84. - . = ALIGN(4);
  85. -
  86. - __gnu_hash_vma = .;
  87. - __gnu_hash_lma = __gnu_hash_vma + __text_lma - __text_vma;
  88. - .gnu.hash : AT(__gnu_hash_lma) {
  89. + .gnu.hash : AT(ADDR(.gnu.hash) + __vma_to_lma) {
  90. __gnu_hash_start = .;
  91. *(.gnu.hash)
  92. __gnu_hash_end = .;
  93. }
  94. - . = ALIGN(4);
  95. -
  96. - __dynlink_vma = .;
  97. - __dynlink_lma = __dynlink_vma + __text_lma - __text_vma;
  98. - .dynlink : AT(__dynlink_lma) {
  99. + .dynlink : AT(ADDR(.dynlink) + __vma_to_lma) {
  100. __dynlink_start = .;
  101. *(.dynlink)
  102. __dynlink_end = .;
  103. }
  104. - . = ALIGN(4);
  105. -
  106. - __got_vma = .;
  107. - __got_lma = __got_vma + __text_lma - __text_vma;
  108. - .got : AT(__got_lma) {
  109. + .got : AT(ADDR(.got) + __vma_to_lma) {
  110. __got_start = .;
  111. KEEP (*(.got.plt))
  112. KEEP (*(.got))
  113. __got_end = .;
  114. }
  115. - . = ALIGN(4);
  116. -
  117. - __dynamic_vma = .;
  118. - __dynamic_lma = __dynamic_vma + __text_lma - __text_vma;
  119. - .dynamic : AT(__dynamic_lma) {
  120. + .dynamic : AT(ADDR(.dynamic) + __vma_to_lma) {
  121. __dynamic_start = .;
  122. *(.dynamic)
  123. __dynamic_end = .;
  124. }
  125. - . = ALIGN(32);
  126. -
  127. - __data_vma = .;
  128. - __data_lma = __data_vma + __text_lma - __text_vma;
  129. - .data : AT(__data_lma) {
  130. + .data : AT(ADDR(.data) + __vma_to_lma) {
  131. __data_start = .;
  132. *(.data)
  133. *(.data.*)
  134. diff --git a/core/x86_64/syslinux.ld b/core/x86_64/syslinux.ld
  135. index bf815c4..70c6e00 100644
  136. --- a/core/x86_64/syslinux.ld
  137. +++ b/core/x86_64/syslinux.ld
  138. @@ -255,10 +255,9 @@ SECTIONS
  139. . = 0x100000;
  140. __pm_code_start = .;
  141. + __vma_to_lma = __pm_code_lma - __pm_code_start;
  142. - __text_vma = .;
  143. - __text_lma = __pm_code_lma;
  144. - .text : AT(__text_lma) {
  145. + .text : AT(ADDR(.text) + __vma_to_lma) {
  146. FILL(0x90909090)
  147. __text_start = .;
  148. *(.text)
  149. @@ -266,106 +265,68 @@ SECTIONS
  150. __text_end = .;
  151. }
  152. - . = ALIGN(32);
  153. -
  154. - __rodata_vma = .;
  155. - __rodata_lma = __rodata_vma + __text_lma - __text_vma;
  156. - .rodata : AT(__rodata_lma) {
  157. + .rodata : AT(ADDR(.rodata) + __vma_to_lma) {
  158. __rodata_start = .;
  159. *(.rodata)
  160. *(.rodata.*)
  161. __rodata_end = .;
  162. }
  163. - . = ALIGN(4);
  164. -
  165. - __ctors_vma = .;
  166. - __ctors_lma = __ctors_vma + __text_lma - __text_vma;
  167. - .ctors : AT(__ctors_lma) {
  168. + .ctors : AT(ADDR(.ctors) + __vma_to_lma) {
  169. __ctors_start = .;
  170. KEEP (*(SORT(.ctors.*)))
  171. KEEP (*(.ctors))
  172. __ctors_end = .;
  173. }
  174. - __dtors_vma = .;
  175. - __dtors_lma = __dtors_vma + __text_lma - __text_vma;
  176. - .dtors : AT(__dtors_lma) {
  177. + .dtors : AT(ADDR(.dtors) + __vma_to_lma) {
  178. __dtors_start = .;
  179. KEEP (*(SORT(.dtors.*)))
  180. KEEP (*(.dtors))
  181. __dtors_end = .;
  182. }
  183. - . = ALIGN(4);
  184. -
  185. - __dynsym_vma = .;
  186. - __dynsym_lma = __dynsym_vma + __text_lma - __text_vma;
  187. - .dynsym : AT(__dynsym_lma) {
  188. + .dynsym : AT(ADDR(.dynsym) + __vma_to_lma) {
  189. __dynsym_start = .;
  190. *(.dynsym)
  191. __dynsym_end = .;
  192. }
  193. __dynsym_len = __dynsym_end - __dynsym_start;
  194. - . = ALIGN(4);
  195. -
  196. - __dynstr_vma = .;
  197. - __dynstr_lma = __dynstr_vma + __text_lma - __text_vma;
  198. - .dynstr : AT(__dynstr_lma) {
  199. + .dynstr : AT(ADDR(.dynstr) + __vma_to_lma) {
  200. __dynstr_start = .;
  201. *(.dynstr)
  202. __dynstr_end = .;
  203. }
  204. __dynstr_len = __dynstr_end - __dynstr_start;
  205. - . = ALIGN(4);
  206. -
  207. - __gnu_hash_vma = .;
  208. - __gnu_hash_lma = __gnu_hash_vma + __text_lma - __text_vma;
  209. - .gnu.hash : AT(__gnu_hash_lma) {
  210. + .gnu.hash : AT(ADDR(.gnu.hash) + __vma_to_lma) {
  211. __gnu_hash_start = .;
  212. *(.gnu.hash)
  213. __gnu_hash_end = .;
  214. }
  215. - . = ALIGN(4);
  216. -
  217. - __dynlink_vma = .;
  218. - __dynlink_lma = __dynlink_vma + __text_lma - __text_vma;
  219. - .dynlink : AT(__dynlink_lma) {
  220. + .dynlink : AT(ADDR(.dynlink) + __vma_to_lma) {
  221. __dynlink_start = .;
  222. *(.dynlink)
  223. __dynlink_end = .;
  224. }
  225. - . = ALIGN(4);
  226. -
  227. - __got_vma = .;
  228. - __got_lma = __got_vma + __text_lma - __text_vma;
  229. - .got : AT(__got_lma) {
  230. + .got : AT(ADDR(.got) + __vma_to_lma) {
  231. __got_start = .;
  232. KEEP (*(.got.plt))
  233. KEEP (*(.got))
  234. __got_end = .;
  235. }
  236. - . = ALIGN(4);
  237. -
  238. - __dynamic_vma = .;
  239. - __dynamic_lma = __dynamic_vma + __text_lma - __text_vma;
  240. - .dynamic : AT(__dynamic_lma) {
  241. + .dynamic : AT(ADDR(.dynamic) + __vma_to_lma) {
  242. __dynamic_start = .;
  243. *(.dynamic)
  244. __dynamic_end = .;
  245. }
  246. - . = ALIGN(32);
  247. -
  248. - __data_vma = .;
  249. - __data_lma = __data_vma + __text_lma - __text_vma;
  250. - .data : AT(__data_lma) {
  251. + .data : AT(ADDR(.data) + __vma_to_lma) {
  252. __data_start = .;
  253. *(.data)
  254. *(.data.*)
  255. --
  256. 2.5.3