From nobody@FreeBSD.org  Mon Jan 23 22:17:12 2012
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 6CA8F106566B
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 23 Jan 2012 22:17:12 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22])
	by mx1.freebsd.org (Postfix) with ESMTP id 5C2688FC14
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 23 Jan 2012 22:17:12 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.4/8.14.4) with ESMTP id q0NMHBTt093955
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 23 Jan 2012 22:17:11 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.4/8.14.4/Submit) id q0NMHBcK093954;
	Mon, 23 Jan 2012 22:17:11 GMT
	(envelope-from nobody)
Message-Id: <201201232217.q0NMHBcK093954@red.freebsd.org>
Date: Mon, 23 Jan 2012 22:17:11 GMT
From: "C. Jullien" <jullien@eligis.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: stat function doesn't 32bit mode on amd64
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         164425
>Category:       kern
>Synopsis:       [libc] stat(2) doesn't work in 32bit mode on amd64
>Confidential:   no
>Severity:       serious
>Priority:       low
>Responsible:    freebsd-bugs
>State:          suspended
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Jan 23 22:20:03 UTC 2012
>Closed-Date:    
>Last-Modified:  Wed Jan 25 19:50:22 UTC 2012
>Originator:     C. Jullien
>Release:        8.1 and 9.0
>Organization:
Eligis
>Environment:
FreeBSD freebsd.eligis.com 9.0-RELEASE FreeBSD 9.0-RELEASE #0: Tue Jan  3 07:46:
30 UTC 2012     root@farrell.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC  amd64
>Description:
A friend of mine also confirmed this issue I discovered at least on 8.1 and is still present on 9.0-RELEASE.

The problem is that, when compiled on amd64 but for i686 target, stat function hangs with a core dump.

$ gcc -m32 -DCOMPAT_32BIT -L/usr/lib32 -B/usr/lib32

I don't see where I'm wrong but can't imagine I'm the only one having this issue.

Christian
>How-To-Repeat:
#include <stdio.h>
#include <sys/stat.h>

void
main()
{
  // char dummy[16]; // uncomment dummy to let it work!!!
  struct stat buf;
  stat("foo.c", &buf );
  printf("%x\n, but.st_mode);
}

# tested on the recent 9.0
$ gcc -m32 -DCOMPAT_32BIT -L/usr/lib32 -B/usr/lib32 foo && ./foo

>Fix:


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-amd64->freebsd-bugs 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Tue Jan 24 04:07:15 UTC 2012 
Responsible-Changed-Why:  
reclassify. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=164425 
State-Changed-From-To: open->suspended 
State-Changed-By: kib 
State-Changed-When: Tue Jan 24 12:12:45 UTC 2012 
State-Changed-Why:  
cc -m32 does not work for many reasons. One is the machine/ includes 
being for the wrong architecture (amd64, while -m32 implies i386). 
Another is that many system types are not ABI-invariant. In case 
of struct stat, at least struct timespec uses longs. 

Since changes are intrusive and nobody works on the issue right now, 
postpone the PR. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=164425 

From: John Baldwin <jhb@freebsd.org>
To: freebsd-amd64@freebsd.org
Cc: "C. Jullien" <jullien@eligis.com>,
 freebsd-gnats-submit@freebsd.org
Subject: Re: amd64/164425: stat function doesn't 32bit mode on amd64
Date: Wed, 25 Jan 2012 08:36:37 -0500

 > I don't see where I'm wrong but can't imagine I'm the only one having this 
 issue.
 
 Yes, -m32 doesn't work currently as it uses the wrong set of headers 
 (/usr/include/machine references amd64 headers, not i386 headers).
 
 -- 
 John Baldwin

From: "Christian Jullien" <eligis@orange.fr>
To: "'John Baldwin'" <jhb@freebsd.org>,
	<freebsd-amd64@freebsd.org>
Cc: "'C. Jullien'" <jullien@eligis.com>,
	<freebsd-gnats-submit@freebsd.org>
Subject: RE: amd64/164425: stat function doesn't 32bit mode on amd64
Date: Wed, 25 Jan 2012 16:40:09 +0100

 Thanks for the reply.
 In that case, you must admit it is strange that gcc on FreeBSD amd64 has
 a-m32 support which does not work!
 
 I see two options that work equally well for me:
 - remove -m32 option on gcc amd64, distro will reduce
 - add /usr/include32 which gcc will use instead of /usr/include in case -m32
 is passed (or something similar)
 
 NetBSD requires a 32bit OS version to compile and use 32bit programs. At
 least it is clear.
 
 Christian 
 
From: John Baldwin <jhb@freebsd.org>
To: "Christian Jullien" <eligis@orange.fr>
Cc: freebsd-amd64@freebsd.org,
 "'C. Jullien'" <jullien@eligis.com>,
 freebsd-gnats-submit@freebsd.org
Subject: Re: amd64/164425: stat function doesn't 32bit mode on amd64
Date: Wed, 25 Jan 2012 11:20:10 -0500

 On Wednesday, January 25, 2012 10:40:09 am Christian Jullien wrote:
 > Thanks for the reply.
 > In that case, you must admit it is strange that gcc on FreeBSD amd64 has
 > a-m32 support which does not work!
 > 
 > I see two options that work equally well for me:
 > - remove -m32 option on gcc amd64, distro will reduce
 > - add /usr/include32 which gcc will use instead of /usr/include in case -m32
 > is passed (or something similar)
 > 
 > NetBSD requires a 32bit OS version to compile and use 32bit programs. At
 > least it is clear.
 
 There are several various WIP's to fix -m32 (and probably several existing bug 
 reports, just do a search for 'freebsd "-m32"' and look at the first batch of 
 results).
 
 -- 
 John Baldwin
>Unformatted:
