From owner-freebsd-hackers@FreeBSD.ORG Sun Dec 30 13:11:02 2007 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 9AA2F16A419; Sun, 30 Dec 2007 13:11:02 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from relay02.kiev.sovam.com (relay02.kiev.sovam.com [62.64.120.197]) by mx1.freebsd.org (Postfix) with ESMTP id 4206313C4F2; Sun, 30 Dec 2007 13:11:02 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from [212.82.216.226] (helo=deviant.kiev.zoral.com.ua) by relay02.kiev.sovam.com with esmtps (TLSv1:AES256-SHA:256) (Exim 4.67) (envelope-from ) id 1J8xwQ-0000g3-Eh; Sun, 30 Dec 2007 15:11:01 +0200 Received: from deviant.kiev.zoral.com.ua (kostik@localhost [127.0.0.1]) by deviant.kiev.zoral.com.ua (8.14.2/8.14.2) with ESMTP id lBUDAvPc022796; Sun, 30 Dec 2007 15:10:57 +0200 (EET) (envelope-from kostikbel@gmail.com) Received: (from kostik@localhost) by deviant.kiev.zoral.com.ua (8.14.2/8.14.2/Submit) id lBUDAuNh022795; Sun, 30 Dec 2007 15:10:56 +0200 (EET) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: deviant.kiev.zoral.com.ua: kostik set sender to kostikbel@gmail.com using -f Date: Sun, 30 Dec 2007 15:10:56 +0200 From: Kostik Belousov To: Kostik Belousov Message-ID: <20071230131056.GG57756@deviant.kiev.zoral.com.ua> References: <47760132.5040306@pacific.net.sg> <20071229111204.GX57756@deviant.kiev.zoral.com.ua> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="y3pDWE12QfphwjBl" Content-Disposition: inline In-Reply-To: <20071229111204.GX57756@deviant.kiev.zoral.com.ua> User-Agent: Mutt/1.4.2.3i X-Scanner-Signature: 33ca3efb02d57e4381ef3dfbedf9ea6a X-DrWeb-checked: yes X-SpamTest-Envelope-From: kostikbel@gmail.com X-SpamTest-Group-ID: 00000000 X-SpamTest-Info: Profiles 1976 [Dec 29 2007] X-SpamTest-Info: helo_type=3 X-SpamTest-Info: {received from trusted relay: not dialup} X-SpamTest-Method: none X-SpamTest-Method: Local Lists X-SpamTest-Rate: 0 X-SpamTest-Status: Not detected X-SpamTest-Status-Extended: not_detected X-SpamTest-Version: SMTP-Filter Version 3.0.0 [0255], KAS30/Release Cc: Kip Macy , Ivan Voras , freebsd-hackers@freebsd.org Subject: Re: Architectures with strict alignment? X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 30 Dec 2007 13:11:02 -0000 --y3pDWE12QfphwjBl Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sat, Dec 29, 2007 at 01:12:04PM +0200, Kostik Belousov wrote: > On Sat, Dec 29, 2007 at 12:14:11AM -0800, Kip Macy wrote: > > Isn't it everything except x86? > >=20 > > -Kip > x86 has the AC bit in the eflags. The AM bit in cr0 is enabled by the > kernel, and AC could be switched on by LD_PRELOADed shared object. >=20 > Last time I checked, our libc caused unaligned access in the locale > initialization code. Out of curiosity, I wrote the following simple LD_PRELOADable shared object. /* $Id: align.c,v 1.2 2007/12/30 13:06:32 kostik Exp $ */ #define AC "(1 << 18)" static void enable_AC() { __asm volatile("pushfl\n\t" "orl\t$" AC ", (%%esp)\n\t" "popfl\n" : : : "cc"); } static void disable_AC(void) { __asm volatile("pushfl\n\t" "andl\t$~" AC ", (%%esp)\n\t" "popfl\n" : : : "cc"); } static void set_AC(void) __attribute__ ((constructor)); void set_AC(void) { enable_AC(); } cc -O2 -shared -o align.so align.c=20 Doing LD_PRELOAD=3D./align.so /bin/ls results in the [1] 12032 bus error (core dumped) LD_PRELOAD=3D./align.so /bin/ls gdb session: Program terminated with signal 10, Bus error. #0 0x2816ee8d in __collate_load_tables (encoding=3D0x281c1280 "ru_RU.KOI8-= R") at /usr/home/kostik/work/MY/align/src/lib/libc/locale/collate.c:87 87 (void)strcat(buf, "/"); (gdb) disassemble 0x2816ee8d 0x2816ee8d+10 Dump of assembler code from 0x2816ee8d to 0x2816ee97: 0x2816ee8d <__collate_load_tables+205>: movw $0x2f,-0x1(%esi,%ecx,1) 0x2816ee94 <__collate_load_tables+212>: mov 0x8(%ebp),%eax (half-word)0x2f =3D=3D asciz '/' I.e., it seems that gcc does not feel too guilty generating unaligned half-word writes on i386. :( --y3pDWE12QfphwjBl Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.7 (FreeBSD) iD8DBQFHd5jfC3+MBN1Mb4gRAj1NAKDOZTEYMYTI92RbwFDNK9tAaLg0NQCg8JyO rDe05y4DpR/3m1fWVfoG7l4= =+P9Y -----END PGP SIGNATURE----- --y3pDWE12QfphwjBl--