Red Hat axp-list: Linux on Alpha (1995-2022)
 help / color / mirror / Atom feed
* malloc oddity?
@ 1998-06-29 19:32 Mike Tripicco
  1998-06-29 20:10 ` Jim Paradis
  0 siblings, 1 reply; 5+ messages in thread
From: Mike Tripicco @ 1998-06-29 19:32 UTC (permalink / raw)
  To: axp-list


I've run into something odd and hoped someone here might be able to help.
I've got a PC164 and am still running RedHat v4.1 because just about
everything works OK and, given the discussion on this list (which I've
been following for about six months) I'm afraid that an upgrade to 5.1
would cost me more downtime (and lost hair) than I can afford right now. 

Anyway, my problem is related to the fact that when I malloc anything more
than 128kb the allocated memory suddenly jumps to a very high address:

# testalloc 131048
allocating 131048 bytes
address is 0x150000250

# testalloc 131049
allocating 131049 bytes
address is 0x15555568010

Running the same test program on an Alpha running OSF/1 v3.2 shows no such
behavior.  Is this related to the same bugs in the linker and/or assembler
which cause the infamous "relocation truncated to fit" errors discussed
back in April of 1997? 

I'm running binutils-2.7.0.2-4 and glibc-0.961212-4 (from rpms) along with
gcc 2.8.1 compiled from source. Attempts to update the binutils and/or
glibc rpms have always failed due to dependency clashes. Short of a full
upgrade to RH5.1 is there any way to fix this odd behavior from malloc?
I've tried compiling the GNU binutils from source and swapping in those
versions of ld and as, but that led to completely inoperable executables. 
Any advice would be appreciated.

Thanks!

   Mike



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: malloc oddity?
  1998-06-29 19:32 malloc oddity? Mike Tripicco
@ 1998-06-29 20:10 ` Jim Paradis
  1998-06-29 21:39   ` Mike Tripicco
  0 siblings, 1 reply; 5+ messages in thread
From: Jim Paradis @ 1998-06-29 20:10 UTC (permalink / raw)
  To: axp-list

> Anyway, my problem is related to the fact that when I malloc anything more
> than 128kb the allocated memory suddenly jumps to a very high address:
> 
> # testalloc 131048
> allocating 131048 bytes
> address is 0x150000250
> 
> # testalloc 131049
> allocating 131049 bytes
> address is 0x15555568010

I'm just curious; why is this a problem?  Surely you're not assuming
that malloc'ed memory is contiguous?!  Malloc can return you a pointer
anywhere it pleases 8-)

Seriously; what you see is normal malloc behavior.  The smaller malloc's
are being done as an sbrk() off the end of the program's data
segment, whereas the larger ones are being done as anonymous
mmap's().  In the case of 64-bit Alpha processes, mmap() starts
searching for free memory at 0x15555560000  (TASK_SIZE / 3, rounded
up to a page boundary).

> Running the same test program on an Alpha running OSF/1 v3.2 shows no such
> behavior.  Is this related to the same bugs in the linker and/or assembler
> which cause the infamous "relocation truncated to fit" errors discussed
> back in April of 1997? 

No relation whatsoever, just different mmap behavior.

--
Jim Paradis (paradis@linux01.hlo.dec.com)     "The early bird gets the worm.
Digital Equipment Corporation		       If you want something else for
(508)841-3243				       breakfast, get up later."
http://www.tiac.net/users/jrp/index.html


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: malloc oddity?
  1998-06-29 20:10 ` Jim Paradis
@ 1998-06-29 21:39   ` Mike Tripicco
  1998-06-29 22:20     ` Richard Henderson
  0 siblings, 1 reply; 5+ messages in thread
From: Mike Tripicco @ 1998-06-29 21:39 UTC (permalink / raw)
  To: axp-list


On Mon, 29 Jun 1998, Jim Paradis wrote:

> I'm just curious; why is this a problem?  Surely you're not assuming
> that malloc'ed memory is contiguous?!  Malloc can return you a pointer
> anywhere it pleases 8-)

The problem relates to some legacy Fortran code I've inherited which
allows Fortran to do dynamic memory allocation. The trick involves Fortran
handling the offset between the location of a common block set by the
Fortran code and the location of the malloc'd memory. That offset is used
by Fortran and thus must fit in a 4-byte integer. In this case that's
impossible. 

However, it looks to me like if the GNU linker had an option equivalent to
Digital's "-taso" I'd be able to avoid the problem:

 -taso
   This option tells the linker that the executable should be
   loaded in the lower 31-bit addressable virtual address range.
   The -T and -D options to the ld(1) command can also be
   used to ensure that the text and data segments addresses,
   respectively, are loaded into low memory.  The -taso option,
   however, in addition to setting default addresses for text and
   data segments, also causes shared libraries linked outside
   the 31-bit address space to be appropriately relocated by
   the loader.  If you specify -taso and also specify text and
   data segment addresses with -T and -D, those addresses override
   the -taso default addresses.  The -taso option is useful for
   porting 32-bit programs to the Digital UNIX operating system.

I'm not trying to argue whether it's legal for malloc to do this or not. 
But I do think it's unfortunate (and odd) that it operates this way using
Alpha Linux and nowhere else, including x86 Linux or Alphas running
Digital Unix... 

Thanks,

  Mike



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: malloc oddity?
  1998-06-29 21:39   ` Mike Tripicco
@ 1998-06-29 22:20     ` Richard Henderson
  0 siblings, 0 replies; 5+ messages in thread
From: Richard Henderson @ 1998-06-29 22:20 UTC (permalink / raw)
  To: axp-list

On Mon, Jun 29, 1998 at 05:39:48PM -0400, Mike Tripicco wrote:
> The problem relates to some legacy Fortran code I've inherited which
> allows Fortran to do dynamic memory allocation. The trick involves Fortran
> handling the offset between the location of a common block set by the
> Fortran code and the location of the malloc'd memory. That offset is used
> by Fortran and thus must fit in a 4-byte integer. In this case that's
> impossible. 

Ah hah.  You can disable this ordinarily quite useful feature
of malloc by calling

	mallopt(M_MMAP_MAX, 0);

in your startup code.  See <malloc.h>.

> However, it looks to me like if the GNU linker had an option equivalent to
> Digital's "-taso" I'd be able to avoid the problem:

Yes, well, no one has had the incentive to work on that.  It 
would probably take about 2 months of work.


r~


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: malloc oddity?
@ 1998-06-30 21:23 Larry Zimmerman
  0 siblings, 0 replies; 5+ messages in thread
From: Larry Zimmerman @ 1998-06-30 21:23 UTC (permalink / raw)
  To: axp-list



Mike,
Sorry for the private mail, I meant to post to the list.
I'm posting part of your reply to me, with my comments.

On Tue, 30 Jun 1998  Mike Tripicco wrote:

> Larry,
> 
> We don't do the dynamic memory allocation in Fortran -- as far as I know
> that doesn't exist, and certainly not in the various Fortran compilers on

Dynamic memory allocation is available for SUN, VAX, HP Unix, MAC,
DOS (Lahey). The code I'm trying to port to Linux runs on all of these.

I think g77 supports %LOC and %VAL. %LOC could be used to get the address
of the start of the common block. I could add sub-array sizes to this
and then use %VAL to pass the address to a subroutine - but as you
said in an earlier post - that would require %LOC to return a 64-bit
integer and the addition would have to be done with 64-bits. %VAL
would have to be able to accept a 64-bit integer argument as well.

> which we support our code. What we do depends on Fortran setting up a
> common block and then calling a routine implemented in C which does the
> malloc calls and returns to Fortran the address of the malloc'd memory
> relative to the common block. I've put the C program which implements
> all of this (and which shows how one would call it from Fortran) at
> 
[stripped - ask Mike for location if you need it]
> Of course all the usual caveats about mixing C and Fortran apply...
> 
> Hope this helps,

I may try this - it looks easier than trying to figure out maximum
size required for arrays and declaring them as large static arrays

> 
> On Mon, 29 Jun 1998, Larry Zimmerman wrote:
> 
> > Did you dynamically allocate the common block? I tried to use malloc
> > with egcs/g77, but it doesn't find "malloc". Am I missing something?
> > I'm trying to port some FORTRASH^^N code, but it's tough without
> > structures and malloc. If there is a way to dynamically allocate memory,
> > it would really help!
> > 

Larry Z.



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~1998-06-30 21:30 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1998-06-29 19:32 malloc oddity? Mike Tripicco
1998-06-29 20:10 ` Jim Paradis
1998-06-29 21:39   ` Mike Tripicco
1998-06-29 22:20     ` Richard Henderson
  -- strict thread matches above, loose matches on Subject: below --
1998-06-30 21:23 Larry Zimmerman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox