From nobody@FreeBSD.org  Sat Dec  8 07:52:17 2012
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52])
	by hub.freebsd.org (Postfix) with ESMTP id 5119BF02
	for <freebsd-gnats-submit@FreeBSD.org>; Sat,  8 Dec 2012 07:52:17 +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 38B048FC0C
	for <freebsd-gnats-submit@FreeBSD.org>; Sat,  8 Dec 2012 07:52:17 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.5/8.14.5) with ESMTP id qB87qHNS093810
	for <freebsd-gnats-submit@FreeBSD.org>; Sat, 8 Dec 2012 07:52:17 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.5/8.14.5/Submit) id qB87qHNL093809;
	Sat, 8 Dec 2012 07:52:17 GMT
	(envelope-from nobody)
Message-Id: <201212080752.qB87qHNL093809@red.freebsd.org>
Date: Sat, 8 Dec 2012 07:52:17 GMT
From: Jerome St-Louis <jerstlouis@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: Segmentation Fault calling stat() from an application compiled as 32 bit on a 64 bit machine
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         174272
>Category:       kern
>Synopsis:       [libc] Segmentation Fault calling stat() from an application compiled as 32 bit on a 64 bit machine
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat Dec 08 08:00:02 UTC 2012
>Closed-Date:    
>Last-Modified:  Sun Dec 09 17:23:22 UTC 2012
>Originator:     Jerome St-Louis
>Release:        FreeBSD 9.0
>Organization:
Ecere Corporation
>Environment:
FreeBSD freebsd9-64 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:
As summarized, invoking the stat() function from an application compiled with gcc -m32 on an amd64 install of FreeBSD 9.0 gives a segmentation fault.

What is up with that? Am I doing something wrong? Does FreeBSD not support compiling and running 32 bit applications on a 64 bit installation? Invoking stat() seems pretty basic functionality...

This is most disappointing as it prevents users from running our software on 64 bit versions of FreeBSD until we port  it to 64 bit.


Valgrind gives a warning:

Warning: client switching stacks?  SP change 0xfeffcca8 --> 0x39848928

And then...

Invalid read of size 4
   at 0x8048491: main (in /root/sdk/a.out)
 Address 0x39848928 is on thread 1's stack

Invalid read of size 4
   at 0xFeFFCD94: ???
 Address 0x0 is not stack'd, malloc'd or (recently) free'd

..

Many thanks!

Best regards,

Jerome
>How-To-Repeat:
Paste the following into bla.c:

#include <sys/stat.h>

int main()
{
   struct stat s;
   stat(argv[1], &s);
   return 0;
}

Compile with:
gcc -m32 bla.c

Run with:
./a.out

Observe:
Segmentation fault: 11 (core dumped)
>Fix:


>Release-Note:
>Audit-Trail:

From: Jerome St-Louis <jerstlouis@gmail.com>
To: bug-followup@FreeBSD.org, jerstlouis@gmail.com
Cc:  
Subject: Re: misc/174272: Segmentation Fault calling stat() from an
 application compiled as 32 bit on a 64 bit machine
Date: Sat, 8 Dec 2012 03:05:49 -0500

 --0016e6dbde5edf0ed804d052cca5
 Content-Type: text/plain; charset=ISO-8859-1
 
 Sorry argv[1] in there should read "bla.c" ...
 I initially thought it was a problem related to arguments but it was not,
 and I missed that modification when updating the testing code.
 
 --0016e6dbde5edf0ed804d052cca5--
>Unformatted:
