mirror of the now-defunct rocklinux.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

263 lines
6.7 KiB

  1. Patch adapted to rocklinux patching 2006-12-12 sk / ripclaw
  2. Submitted By: Jim Gifford (patches at jg555 dot com)
  3. Date: 2006-01-03
  4. Initial Package Version: 2.3
  5. Origin: Dave Miller
  6. Upstream Status: Unknown
  7. Description: Fixes 64 Bit Issues with Elftoaout
  8. http://marc.theaimsgroup.com/?l=linux-sparc&m=113617505627794&w=2
  9. diff -Naur elftoaout-2.3.orig/elftoaout.c elftoaout-2.3/elftoaout.c
  10. --- ./elftoaout.c.orig 2000-06-03 20:20:12.000000000 +0000
  11. +++ ./elftoaout.c 2006-01-03 22:33:28.000000000 +0000
  12. @@ -20,16 +20,36 @@
  13. */
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16. -#ifdef linux
  17. #include <linux/elf.h>
  18. -#define ELFDATA2MSB 2
  19. -#else
  20. -#include <sys/elf.h>
  21. -#endif
  22. -
  23. -#define swab16(x) (((x)<<8&0xFF00)|((x)>>8&0x00FF))
  24. -#define swab32(x) (((x)<<24&0xFF000000)|((x)<<8&0x00FF0000)|((x)>>24&0x000000FF)|((x)>>8&0x0000FF00))
  25. -#define swab64(x) ((((unsigned long long)(swab32((unsigned int)x))) << 32) | (swab32(((unsigned long long)x)>>32)))
  26. +#include <sys/types.h>
  27. +
  28. +static inline u_int16_t swab16(u_int16_t x)
  29. +{
  30. + return (((x << 8) & 0xFF00) |
  31. + ((x >> 8) & 0x00FF));
  32. +}
  33. +
  34. +static inline u_int32_t swab32(u_int32_t x)
  35. +{
  36. + return (((x << 24) & 0xFF000000) |
  37. + ((x << 8) & 0x00FF0000) |
  38. + ((x >> 24) & 0x000000FF) |
  39. + ((x >> 8) & 0x0000FF00));
  40. +}
  41. +
  42. +static inline u_int64_t swab64(u_int64_t x)
  43. +{
  44. + return ((u_int64_t)
  45. + ((u_int64_t)(((u_int64_t)x & (u_int64_t)0x00000000000000ffULL) << 56) |
  46. + (u_int64_t)(((u_int64_t)x & (u_int64_t)0x000000000000ff00ULL) << 40) |
  47. + (u_int64_t)(((u_int64_t)x & (u_int64_t)0x0000000000ff0000ULL) << 24) |
  48. + (u_int64_t)(((u_int64_t)x & (u_int64_t)0x00000000ff000000ULL) << 8) |
  49. + (u_int64_t)(((u_int64_t)x & (u_int64_t)0x000000ff00000000ULL) >> 8) |
  50. + (u_int64_t)(((u_int64_t)x & (u_int64_t)0x0000ff0000000000ULL) >> 24) |
  51. + (u_int64_t)(((u_int64_t)x & (u_int64_t)0x00ff000000000000ULL) >> 40) |
  52. + (u_int64_t)(((u_int64_t)x & (u_int64_t)0xff00000000000000ULL) >> 56)));
  53. +}
  54. +
  55. /* We carry a.out header here in order to compile the thing on Solaris */
  56. @@ -37,14 +57,14 @@
  57. #define CMAGIC 0x01030108
  58. typedef struct {
  59. - unsigned long a_magic; /* magic number */
  60. - unsigned long a_text; /* size of text segment */
  61. - unsigned long a_data; /* size of initialized data */
  62. - unsigned long a_bss; /* size of uninitialized data */
  63. - unsigned long a_syms; /* size of symbol table || checksum */
  64. - unsigned long a_entry; /* entry point */
  65. - unsigned long a_trsize; /* size of text relocation */
  66. - unsigned long a_drsize; /* size of data relocation */
  67. + u_int32_t a_magic; /* magic number */
  68. + u_int32_t a_text; /* size of text segment */
  69. + u_int32_t a_data; /* size of initialized data */
  70. + u_int32_t a_bss; /* size of uninitialized data */
  71. + u_int32_t a_syms; /* size of symbol table || checksum */
  72. + u_int32_t a_entry; /* entry point */
  73. + u_int32_t a_trsize; /* size of text relocation */
  74. + u_int32_t a_drsize; /* size of data relocation */
  75. } Exec;
  76. @@ -56,17 +76,16 @@
  77. int swab;
  78. int sparc64;
  79. int csum;
  80. - /* friend void Usage(void); */
  81. } Application;
  82. typedef struct {
  83. Elf32_Phdr *tab;
  84. - unsigned len;
  85. + unsigned int len;
  86. } ProgTable;
  87. typedef struct {
  88. Elf64_Phdr *tab;
  89. - unsigned len;
  90. + unsigned int len;
  91. } ProgTable64;
  92. void get_ptab(ProgTable *t, FILE *inp, const Elf32_Ehdr *h);
  93. @@ -75,9 +94,9 @@
  94. void print_ptab64(ProgTable64 *t);
  95. typedef struct {
  96. - char *buf; /* Image data */
  97. - unsigned len; /* Length of buffer */
  98. - unsigned bss; /* Length of extra data */
  99. + unsigned char *buf; /* Image data */
  100. + unsigned int len; /* Length of buffer */
  101. + unsigned int bss; /* Length of extra data */
  102. } Segment;
  103. void load_image(Segment *t, const ProgTable *h, FILE *inp);
  104. @@ -105,7 +124,8 @@
  105. parse_args(&prog, argc, argv);
  106. - if (prog.version) Version();
  107. + if (prog.version)
  108. + Version();
  109. if (freopen(prog.iname, "r", stdin) == NULL) {
  110. fprintf(stderr, "Cannot open \"%s\"\n", prog.iname);
  111. @@ -141,7 +161,8 @@
  112. exit(0);
  113. }
  114. -void parse_args( Application *t, unsigned argc, const char **argv ){
  115. +void parse_args( Application *t, unsigned argc, const char **argv )
  116. +{
  117. const char *arg;
  118. union {
  119. char c[4];
  120. @@ -185,8 +206,8 @@
  121. if (t->csum && t->sun4_mode) Usage (); /* Checksum lives in header. */
  122. }
  123. -void get_header(Elf32_Ehdr *t, FILE *inp) {
  124. -
  125. +void get_header(Elf32_Ehdr *t, FILE *inp)
  126. +{
  127. if (fread((void*) t, sizeof(Elf64_Ehdr), 1, inp) != 1) {
  128. fprintf(stderr, "Read error on header\n");
  129. exit(1);
  130. @@ -249,8 +270,9 @@
  131. }
  132. }
  133. -void get_ptab(ProgTable *t, FILE *inp, const Elf32_Ehdr *h) {
  134. - unsigned x;
  135. +void get_ptab(ProgTable *t, FILE *inp, const Elf32_Ehdr *h)
  136. +{
  137. + unsigned int x;
  138. /** fprintf(stderr, "Program header table off = 0x%x\n",
  139. (unsigned) h->e_phoff); **/
  140. @@ -294,8 +316,9 @@
  141. }
  142. }
  143. -void get_ptab64(ProgTable64 *t, FILE *inp, const Elf64_Ehdr *h) {
  144. - unsigned x;
  145. +void get_ptab64(ProgTable64 *t, FILE *inp, const Elf64_Ehdr *h)
  146. +{
  147. + unsigned int x;
  148. if (h->e_phoff == 0) {
  149. fprintf(stderr, "No Program Header Table\n");
  150. @@ -332,8 +355,9 @@
  151. }
  152. }
  153. -void print_ptab(ProgTable *t) {
  154. - unsigned x;
  155. +void print_ptab(ProgTable *t)
  156. +{
  157. + unsigned int x;
  158. const Elf32_Phdr *p;
  159. for (x = 0; x < t->len; x++) {
  160. @@ -374,8 +398,9 @@
  161. }
  162. }
  163. -void print_ptab64(ProgTable64 *t) {
  164. - unsigned x;
  165. +void print_ptab64(ProgTable64 *t)
  166. +{
  167. + unsigned int x;
  168. const Elf64_Phdr *p;
  169. for (x = 0; x < t->len; x++) {
  170. @@ -387,8 +412,11 @@
  171. break;
  172. case PT_LOAD:
  173. printf("Loadable to 0x%Lx[0x%Lx] from 0x%Lx[0x%Lx] align 0x%Lx",
  174. - p->p_vaddr, p->p_memsz, p->p_offset, p->p_filesz,
  175. - p->p_align);
  176. + (unsigned long long) p->p_vaddr,
  177. + (unsigned long long) p->p_memsz,
  178. + (unsigned long long) p->p_offset,
  179. + (unsigned long long) p->p_filesz,
  180. + (unsigned long long) p->p_align);
  181. break;
  182. case PT_DYNAMIC:
  183. printf("Dynamic");
  184. @@ -416,9 +444,10 @@
  185. }
  186. }
  187. -void load_image(Segment *t, const ProgTable *tp, FILE *inp) {
  188. +void load_image(Segment *t, const ProgTable *tp, FILE *inp)
  189. +{
  190. Elf32_Phdr *p, *q;
  191. - unsigned x;
  192. + unsigned int x;
  193. unsigned long off, len;
  194. p = 0;
  195. @@ -484,9 +513,10 @@
  196. }
  197. }
  198. -void load_image64(Segment *t, const ProgTable64 *tp, FILE *inp) {
  199. +void load_image64(Segment *t, const ProgTable64 *tp, FILE *inp)
  200. +{
  201. Elf64_Phdr *p, *q;
  202. - unsigned x;
  203. + unsigned int x;
  204. unsigned long long off, len;
  205. p = 0;
  206. @@ -547,7 +577,8 @@
  207. }
  208. }
  209. -void store_image(Segment *t, FILE *out) {
  210. +void store_image(Segment *t, FILE *out)
  211. +{
  212. Exec ohdb;
  213. if (prog.swab) {
  214. @@ -585,13 +616,15 @@
  215. return;
  216. }
  217. -void Usage(){
  218. +void Usage()
  219. +{
  220. if (prog.version) Version();
  221. fprintf(stderr, "Usage: elftoaout [-o output] [-c|-b] [-V] input\n");
  222. exit(1);
  223. }
  224. -void Version(){
  225. +void Version()
  226. +{
  227. printf("elftoaout 2.3: ELF to a.out convertor for SPARC and SPARC64 bootstraps\n");
  228. }