Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 25 Jan 2008 00:23:52 +0100
From:      Willem Jan Withagen <wjw@digiware.nl>
To:        "M. Warner Losh" <imp@bsdimp.com>
Cc:        des@des.no, freebsd-arm@freebsd.org
Subject:   Re: sshd broken on arm?
Message-ID:  <47991E08.6070609@digiware.nl>
In-Reply-To: <20080124.110954.179240992.imp@bsdimp.com>
References:  <479880A7.1030107@digiware.nl>	<20080124.084828.1608359032.imp@bsdimp.com>	<864pd386mj.fsf@ds4.des.no> <20080124.110954.179240992.imp@bsdimp.com>

next in thread | previous in thread | raw e-mail | index | archive | help
M. Warner Losh wrote:
> In message: <864pd386mj.fsf@ds4.des.no>
>             Dag-Erling_Smørgrav <des@des.no> writes:
> : "M. Warner Losh" <imp@bsdimp.com> writes:
> : > Actually, the above fix *IS* the correct fix for arm given the ABI
> : > that we're using...
> : 
> : No.  The correct fix is one that will be acceptable to the upstream
> : vendor, who has a different perspective on things than we do.
> 
> The problem is that the char array isn't guaranteed to be aligned in
> any way.  The fix posted is correct.
> 
> There may be other fixes too, such as using a union to force
> alignment.

Well I'm sort of puzzled right now since after preprocessing the 
variable allocation part boils down to:
=====
  struct msghdr msg;
  struct iovec vec;
  char ch = '\0';
  ssize_t n;

  char tmp[((((unsigned)(sizeof(struct cmsghdr)) + (sizeof(int) - 1)) & 
~(sizeof(int) - 1)) + (((unsigned)(sizeof(int)) + (sizeof(int
) - 1)) & ~(sizeof(int) - 1)))];
  struct cmsghdr *cmsg;
=====
So as far as I can see is char tmp[] included between 2 4-byte items and 
  allocation should be "automagically" 4-byte aligned.

Now adding simple code like tmp[0] = 50, the first part of the assembly 
is: (Comments are mine for as far as I can grasp them)
====
mm_send_fd:
         @ args = 0, pretend = 0, frame = 72
         @ frame_needed = 1, current_function_anonymous_args = 0
// entry code
         mov     ip, sp
         stmfd   sp!, {fp, ip, lr, pc}
         sub     fp, ip, #4
// allocate stack space
         sub     sp, sp, #72
         str     r0, [fp, #-16]
         str     r1, [fp, #-20]
// ch = '\0'
         mov     r3, #0
         mov     r2, r3
         strb    r2, [fp, #-57]
// tmp[0] = 50
         mov     r3, #50
         mov     r2, r3
         strb    r2, [fp, #-80]
// msg = &tmp
         sub     r3, fp, #80
         str     r3, [fp, #-32]
//
====

So it seems that with this compiler tmp is correctly aligned.
What I used for this is the arm-elf-gcc-295 from ports, not doing any 
optimisation. Optimisation eliminates just about everything in my simple 
test. Trying it on the full code, I still don't see an unaligned 
reference to &tmp

But then that might vary with the compiler.

But I cannot follow the suggestions at the freebsd/arm pages. I do not 
have a -CURRENT system, and trying it on 7.0 starts to complain right 
away on the first file to compile. Su suggestions there are welcome.

--WjW





Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?47991E08.6070609>