sshd broken on arm?
Willem Jan Withagen
wjw at digiware.nl
Thu Jan 24 15:23:59 PST 2008
M. Warner Losh wrote:
> In message: <864pd386mj.fsf at ds4.des.no>
> Dag-Erling_Smørgrav <des at des.no> writes:
> : "M. Warner Losh" <imp at 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
More information about the freebsd-arm
mailing list