Port-amiga archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

elf2bb is not sparc64 host compatible (yet)



Hi,

sparc64 is picky about the locations it accepts write to, so three places
in elf2bb main give bus errors. The attached patch takes care of that.

There is another consideration regarding the code that strikes me as
un-pretty, even though it's not effecting anything:
I think the '*((u_int32_t *)(base + htobe32(ra->r_offset))) =' should
read '((u_int32_t *)(base + betoh32(ra->r_offset))) =' seeing that we
likely transfer a amiga-elf (and thus itself already big-endian) value
into a host pointer increment. Of course the point is entirely cosmetic 
as the two macros do exactly the same. :-) 

---- begin patch ----
--- elf2bb.c    2004-09-25 14:26:44.000000000 +0200
+++ elf2bb.c-fixed      2004-09-25 14:21:22.000000000 +0200
@@ -312,14 +312,36 @@
                            htobe32(ra->r_addend), value));
                        switch (ELF32_R_TYPE(htobe32(ra->r_info))) {
                        case R_68K_32:
+#ifdef __sparc64__
+                               *((char *)(base + htobe32(ra->r_offset))) =
+                                   (char) ((htobe32(value) & 0xff000000) >> 
24);
+                               *((char *)(base + htobe32(ra->r_offset)) + 1) =
+                                   (char) ((htobe32(value) & 0x00ff0000) >> 
16);
+                               *((char *)(base + htobe32(ra->r_offset)) + 2) =
+                                   (char) ((htobe32(value) & 0x0000ff00) >> 8);
+                               *((char *)(base + htobe32(ra->r_offset)) + 3) =
+                                   (char) ((htobe32(value) & 0x000000ff));
+#else
                                *((u_int32_t *)(base + htobe32(ra->r_offset))) =
                                    htobe32(value);
+#endif
                                relbuf[r32sz++] = (base - buffer) + 
htobe32(ra->r_offset);
                                break;
                        case R_68K_PC32:
                                ++pcrelsz;
+#ifdef __sparc64__     
+                               *((char *)(base + htobe32(ra->r_offset))) =
+                                   (char) ((htobe32(value - 
htobe32(ra->r_offset)) & 0xff000000) >> 24);
+                               *((char *)(base + htobe32(ra->r_offset)) + 1) =
+                                   (char) ((htobe32(value - 
htobe32(ra->r_offset)) & 0x00ff0000) >> 16);
+                               *((char *)(base + htobe32(ra->r_offset)) + 2) =
+                                   (char) ((htobe32(value - 
htobe32(ra->r_offset)) & 0x0000ff00) >> 8);
+                               *((char *)(base + htobe32(ra->r_offset)) + 3) =
+                                   (char) ((htobe32(value - 
htobe32(ra->r_offset)) & 0x000000ff));
+#else
                                *((int32_t *)(base + htobe32(ra->r_offset))) =
                                    htobe32(value - htobe32(ra->r_offset));
+#endif
                                break;
                        case R_68K_PC16:
                                ++pcrelsz;
@@ -327,8 +349,19 @@            
                                if (value < -0x8000 || value > 0x7fff)
                                        errx(1,  "PC-relative offset out of 
range: %x\n",                           
                                            value);
+#ifdef __sparc64__
+                               *((char *)(base + htobe32(ra->r_offset))) =
+                                   (char) 0;
+                               *((char *)(base + htobe32(ra->r_offset)) + 1) =
+                                   (char) 0;
+                               *((char *)(base + htobe32(ra->r_offset)) + 2) =
+                                   (char) ((htobe16(value) & 0x0000ff00) >> 8);
+                               *((char *)(base + htobe32(ra->r_offset)) + 3) = 
+                                   (char) ((htobe16(value) & 0x000000ff));
+#else
                                *((int16_t *)(base + htobe32(ra->r_offset))) =
                                    htobe16(value); 
+#endif
                                break;
---- end patch ----

regards,
        spz
-- 
spz%serpens.de@localhost (S.P.Zeidler)



Home | Main Index | Thread Index | Old Index