Usenet comp.unix.tru64 (2000-2013)
 help / color / mirror / Atom feed
* Compiler Qusetion, -taso flag
@ 2003-06-17  1:22 Grant
  2003-06-17 17:00 ` Joe Mario
  0 siblings, 1 reply; 2+ messages in thread
From: Grant @ 2003-06-17  1:22 UTC (permalink / raw)


I'm searching for a place that might help with this. This is basically a 
Digital(Compaq/HP?) compiler problem we are having when compiling on of 
our apps on Tru64(4.0f and up). If anyone knows of a better list than 
this for more Digital Compiler related quesitons please let me know.


OS: Compaq's Unix Tru64 4.0f
Compiler: DIGITAL C++ V6.1-029 on DIGITAL UNIX V4.0 (Rev. 1229)



Problem:
         We have an application that must be linked with the -taso flag.
Which forces pointers to only use the lower 31 bits of address space. 
This
is mainly because a product we need that we link it requires it. We can't
fix that.



But, when I build anything and link it with the -taso option. malloc 
fails
once I have allocated about 300 megs of RAM(malloc returns 0)



We really need this app to be able to get upwards of 300 megs. I just 
don't
understand why forcing the 31 bit address space would limit us to only 
300
megs.



I'm hoping there is some other flag or somethign can may address this.
Anyone have a clue?



I made a small test app that just mallocs until it fails.  It was built
with the following flags. This will fail at around 300 megs.


Compile line: cxx -taso -c -o test3.o test3.cxx
Link line   : cxx -taso -o test3 test3.o





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

* Re: Compiler Qusetion, -taso flag
  2003-06-17  1:22 Compiler Qusetion, -taso flag Grant
@ 2003-06-17 17:00 ` Joe Mario
  0 siblings, 0 replies; 2+ messages in thread
From: Joe Mario @ 2003-06-17 17:00 UTC (permalink / raw)


Grant wrote:
> ... 
> But, when I build anything and link it with the -taso option. malloc
> fails once I have allocated about 300 megs of RAM(malloc returns 0)

Grant:
  Here is some information we had lying around to address your
  problem.  The two easiest for you might be to set the
  __sbrk_override malloc tuning variable, or to set the 
  -reserve_taso_heap loader flag.  See the malloc manpage for the
  former, and see the loader manpage for the latter.
  Linking -non_shared will also solve your problem.

  I've appended some other notes that might be of help.

Joe Mario

-----------------------------------------------------------------------

A good description of the taso programming environment is contained 
in the "Programmer's Guide", appendix A2. 

Background

Applications linked -taso are limited to a 31 bit address space (2GB). 
We require the high bit to be zero to avoid having sign extension 
corrupt a pointer when assigning a taso pointer stored in 32 bits 
into a 64 bit variable. A default taso link places the main object's 
text at 12000000 (all addresses in this note are in hex), and its data
segment is at 14000000, immediately followed by the bss segment.  
The stack is immediately below main object's text (always--this will 
become important below), and the heap is immediately above its bss.
The heap is the portion of the program address space from which
malloc traditionally allocates memory. 

In a program linked with -taso and with shared libraries, the run-time
loader maps the shared
library text starting at 0x10000000 bytes above the start of the main
object's data start address
(by default 14000000). This implies that the heap for a program linked
with shared libraries is
limited to 268,435,456 (256 x 1024 x 1024 or 0x10000000) bytes minus the
size of the main
object's data and bss segments.  This offset is a constant in the
loader, and not under user control.

The preferred remedy: link non_shared

The most effective solution for large allocations in taso applications
is to link the application
without shared libraries, i.e., -taso -non_shared.  This may not be
possible due to the
unavailability of some library used by the application in archive (.a)
form.  If it is possible to
link -non_shared, then the program can allocate from the end of bss
through 7fffffff,
assuming the program code does not use the mmap() system call to
allocate memory somewhere
in that range. 

If that's not possible

The malloc routine (by which I mean malloc, calloc, realloc, valloc)
normally allocates memory
from the kernel via the sbrk() system call.  Allocations using sbrk will
fail if the requested
memory allocation would conflict with another allocated region, for
instance a region allocated
via mmap, as in the previous paragraph, or the text segment of a shared
library.  However,
because the heap in a taso application is limited to 250 MB, malloc has
a tuning variable which
allows it to continue allocating memory above the shared libraries.  The
malloc man page has a
full description of malloc tuning variables.  The one that is useful
here is __sbrk_override.  If
the libc global read-only "long" variable __sbrk_override is prempted by
an application
declaration with a static initialization of 1, instead of its default,
zero, then when malloc detects
a failed call to sbrk it will switch over to using mmap, which will skip
over the libraries and
allocate memory in the upper portion of the address space.  This allows
much larger allocations,
still within the 2 GB limit imposed by a 31 bit address space. 

I should note here that Appendix A2 in the Programmer's Guide is
slightly inaccurate in its
description of using malloc in a taso application.  If the libc global
read-only "unsigned long"
variable __taso_mode is preempted by an application declaration of that
variable with a static
initialization of 1, the malloc routine will know that it is running in
a taso address space, and
check that the chunk it is returning is below the 31 bit cut-off point. 
Therefore, the test
described in the manual does not have to be performed if __taso_mode is
preempted. 

Tuning with the linker's -T and -D switches

There is another way of tuning a taso address space: the -T and -D link
switches, which control
the starting text and data addresses for the main object, respectively. 
If the program's stack
requirement is known to be less than 0x11FF0000 (0x12000000 - 0x10000,
the bottom limit of
accessible memory unless explicitly enabled) then the text address can
be lowered to a point just
large enough for the stack with the -T switch.  Remember that the stack
always starts
immediately below the program's text segment.  Also, remember that a
program's stack
requirements can change when a new shared library is installed, for
instance during an operating
system upgrade; lowering the text address aggressively can be perilous. 

Similarly, it is unlikely that the text size takes all 0x02000000 bytes
allocated for it by default.
It is possible to lower the data starting address to leave less wasted
space by using the -D
switch.  Remember that moving the main object's data address will also
move the shared
libraries down by the same amount.  It will NOT affect the amount of
standard heap available to
the application, unless the application is linked -non_shared. 


About the 31 bit taso address space limitation

A final note about the 31 bit limitation of taso space, compared with
the traditional UNIX 32 bit
range.  The taso mode is intended primarily as a porting aid for
applications which have
intermixed "int" and pointer variables.  It is not an area in which we
are investing new
development.  Changing to a 32 bit range would require massive changes
throughout the
development environment which we will not be doing.


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

end of thread, other threads:[~2003-06-17 17:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-06-17  1:22 Compiler Qusetion, -taso flag Grant
2003-06-17 17:00 ` Joe Mario

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