NetBSD Problem Report #27036

Received: (qmail 542 invoked by uid 605); 25 Sep 2004 21:52:57 -0000
Message-Id: <200409252117.i8PLHcuj006121@aquila.local>
Date: Sat, 25 Sep 2004 23:17:38 +0200 (CEST)
From: spz@serpens.de
Sender: gnats-bugs-owner@NetBSD.org
Reply-To: spz@serpens.de
To: gnats-bugs@gnats.NetBSD.org
Subject: elf2bb is not sparc64 host compatible
X-Send-Pr-Version: 3.95

>Number:         27036
>Category:       port-amiga
>Synopsis:       elf2bb is not sparc64 host compatible
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    port-amiga-maintainer
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Sep 25 21:53:00 +0000 2004
>Closed-Date:    Sat Dec 04 16:24:41 +0000 2004
>Last-Modified:  Sat Dec 04 16:24:41 +0000 2004
>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:

From: Martin Husemann <martin@duskware.de>
To: spz@serpens.de
Cc: gnats-bugs@gnats.NetBSD.org
Subject: Re: port-amiga/27036: elf2bb is not sparc64 host compatible
Date: Mon, 27 Sep 2004 11:04:14 +0200

 On Sat, Sep 25, 2004 at 11:17:38PM +0200, spz@serpens.de wrote:
 > +#ifdef __sparc64__
 > +				*((char *)(base + htobe32(ra->r_offset))) = 
 > +				    (char) ((htobe32(value) & 0xff000000) >> 24);

 I'd prefer to 

  - not have a #ifdef __sparc64__ here
  - build the 32bit result in a local variable and then use
    memcpy() to write it to the destination address

 Martin

From: "S.P.Zeidler" <spz@serpens.de>
To: gnats-bugs@gnats.NetBSD.org
Cc:  
Subject: Re: port-amiga/27036: elf2bb is not sparc64 host compatible
Date: Sat, 23 Oct 2004 18:39:37 +0200

 Hi,

 eh, I didn't write it was the best of all possible fixes, just that it
 fixed it (for that one case) :-) 
 I did a patch that uses Christos' suggestion:

 --- elf2bb.c	2004-03-06 18:22:30.000000000 +0100
 +++ elf2bb.c.fixed	2004-10-23 18:24:40.000000000 +0200
 @@ -105,6 +105,8 @@
  	u_int32_t oldaddr, addrdiff;
  	u_int32_t tsz, dsz, bsz, trsz, drsz, entry, relver;
  	u_int32_t pcrelsz, r32sz;
 +	u_int32_t tmp32;
 +	u_int16_t tmp16;
  	int sumsize = 16;
  	int c;
  	u_int32_t *sect_offset;
 @@ -312,14 +314,16 @@
  			    htobe32(ra->r_addend), value));
  			switch (ELF32_R_TYPE(htobe32(ra->r_info))) {
  			case R_68K_32:
 -				*((u_int32_t *)(base + htobe32(ra->r_offset))) =
 -				    htobe32(value);
 +				tmp32 = htobe32(value);
 +				(void)memcpy(base + htobe32(ra->r_offset), 
 +				    &tmp32, sizeof(tmp32));
  				relbuf[r32sz++] = (base - buffer) + htobe32(ra->r_offset);
  				break;
  			case R_68K_PC32:
  				++pcrelsz;
 -				*((int32_t *)(base + htobe32(ra->r_offset))) =
 -				    htobe32(value - htobe32(ra->r_offset));
 +				tmp32 = htobe32(value - htobe32(ra->r_offset));
 +				(void)memcpy(base + htobe32(ra->r_offset), 
 +				    &tmp32, sizeof(tmp32));
  				break;
  			case R_68K_PC16:
  				++pcrelsz;
 @@ -327,8 +331,9 @@
  				if (value < -0x8000 || value > 0x7fff)
  					errx(1,  "PC-relative offset out of range: %x\n",
  					    value);
 -				*((int16_t *)(base + htobe32(ra->r_offset))) =
 -				    htobe16(value);
 +				tmp16 = htobe16(value);
 +				(void)memcpy(base + htobe32(ra->r_offset), 
 +				    &tmp16, sizeof(tmp16));
  				break;
  			default:
  				errx(1, "Relocation type %d not supported",

 Is that nice enough (tm) to use?

 kind regards,
 	spz
 -- 
 spz@serpens.de (S.P.Zeidler)
State-Changed-From-To: open->closed
State-Changed-By: chs@netbsd.org
State-Changed-When: Sat, 04 Dec 2004 16:24:41 +0000
State-Changed-Why:
fixed by rev. 1.10 of elf2bb.c


>Unformatted:
 >Quarter:
 >Keywords:
 >Date-Required:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2007 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.