From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111c93,97d3ded662883f7c X-Google-Attributes: gid111c93,public X-Google-ArrivalTime: 2001-01-11 10:28:03 PST Path: supernews.google.com!sn-xit-03!supernews.com!news-feed.riddles.org.uk!newsfeed.direct.ca!look.ca!newsfeed.mathworks.com!solaris.cc.vt.edu!news.vt.edu!not-for-mail From: "T. Daniel Crawford" Newsgroups: comp.os.linux.alpha Subject: Re: weird behavior of malloc() Date: Thu, 11 Jan 2001 13:25:59 -0500 Organization: Virginia Tech, Blacksburg, Virginia, USA Message-ID: <3A5DFAB7.BB3CF56F@vt.edu> References: <93iohn$m3c$1@nnrp1.deja.com> NNTP-Posting-Host: orion.chem.vt.edu MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: solaris.cc.vt.edu 979237561 19548 128.173.180.103 (11 Jan 2001 18:26:01 GMT) X-Complaints-To: abuse@vt.edu NNTP-Posting-Date: 11 Jan 2001 18:26:01 GMT X-Mailer: Mozilla 4.76 [en] (X11; U; Linux 2.2.16-22smp i686) X-Accept-Language: en Xref: supernews.google.com comp.os.linux.alpha:1856 rwgk@my-deja.com wrote: > System: > Red Hat Linux release 6.2 (Zoot) > Kernel 2.2.14-6.0smp on a 2-processor alpha > > On this system, malloc() returns pointers to places in memory that > are very far apart. For example, one call returns 0x125f77510, > and the next one 0x20000002010 (the first call only allocates > 16 bytes or so, the second one about 160000 bytes). > > Unfortunately, this behavior is causing us problems. For use in > a Fortran program, we compute the difference between the pointers > returned by malloc() and a pointer to a Fortran reference array. > The difference is divided by the size of Fortran INTEGER, and > that result passed back from C to Fortran as a Fortran INTEGER. > If the difference is too large for INTEGER, our program crashes. > > Our program is very large (>100000 lines) and it is practically > impossible to find and replace all INTEGER that store offsets for > dynamic memory allocation. Also, the program is running fine > on another 64-bit architecture (IRIX64). Why does malloc() on > the Alpha return pointers to places in memory that are so far > apart? Could this be changed? > > Thanks for any comments, > Ralf > > Sent via Deja.com > http://www.deja.com/ I asked a nearly identical question on the axp-list just last week. The very helpful folks on that list informed me that answer is the -taso (Truncated Address Space Option) flag. This flag will make sure that all addresses returned by malloc() routines will fall below the 2^31 threshold, and you will then be able to store adress differences in a 32-bit integer. If you are using the Compaq Fortran compiler, you'll need to add the flag "-Wl,-taso" to the linker flags so that the -taso option will be passed to the GNU linker. Make certain you have a recent version of the GNU binutils. Good luck! -Daniel -- T. Daniel Crawford Department of Chemistry crawdad@vt.edu Virginia Tech www.chem.vt.edu/chem-dept/crawford Voice: 540-231-7760 FAX: 540-231-3255