Subject: port-amiga/27036: elf2bb is not sparc64 host compatible
To: None <gnats-bugs@gnats.NetBSD.org>
From: None <spz@serpens.de>
List: netbsd-bugs
Date: 09/25/2004 23:17:38
>Number:         27036
>Category:       port-amiga
>Synopsis:       elf2bb is not sparc64 host compatible
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    port-amiga-maintainer
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Sep 25 21:53:00 UTC 2004
>Closed-Date:
>Last-Modified:
>Originator:     S.P.Zeidler
>Release:        NetBSD 2.0_RC1 24 Sept 2004
>Organization:
	dis-
>Environment:
System: NetBSD aquila 2.0G NetBSD 2.0G (AQUILA) #1: Sat Aug 7 11:44:23 MEST 2004 mlelstv@pepew:/home/mlelstv/NetBSD-current/obj.sparc64/sys/arch/sparc64/compile/AQUILA sparc64
Architecture: sparc64
Machine: sparc64
>Description:
	trying to cross-build an Amiga release on the above system, I tripped
	over a bus error of elf2bb. Basically Sparc64 is picky about
	alignment and doesn't like some of the assignments made.
>How-To-Repeat:
	try to compile and use elf2bb on sparc64
>Fix:
--- 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;
 			default:
 				errx(1, "Relocation type %d not supported",
>Release-Note:
>Audit-Trail:
>Unformatted: