Hi bulk 88,

thanks for your message. See below for my response.

On Thu, 23 Aug 2012 17:31:05 -0400
bulk 88 <bul...@hotmail.com> wrote:

> 
> 
> 
> ----------------------------------------
> > Date: Thu, 23 Aug 2012 20:33:53 +0300
> > From: shlo...@shlomifish.org
> > To: perl-xs@perl.org
> > Subject: How to have perl allocate pointers predictably.
> >
> > Hi all,
> >
> > with the included script below, Devel::Leak keeps outputting
> > different pointers each time for the leaked SVs. This makes
> > debugging harder. Can I have perl somehow allocate the same
> > pointers each time when an allocation is being requested? I don't
> > mind rebuilding a dedicated perl for that using perlbrew or
> > whatever. Note that this also happens if make_trouble() is as
> > simple as "my $x; $x = \$x;".
> On Windows XP I always get the same SV *s assuming all inputs to the
> process are the same on each run.
> ____________________________________________________ C:\Documents and
> Settings\Owner\Desktop>perl -e "print \\\"perl\"" SCALAR(0x8fe04c)
> C:\Documents and Settings\Owner\Desktop>perl -e "print \\\"perl\""
> SCALAR(0x8fe04c)
> C:\Documents and Settings\Owner\Desktop>perl -e "print \\\"perl\""
> SCALAR(0x8fe04c)
> C:\Documents and Settings\Owner\Desktop>perl -e "print \\\"perl\""
> SCALAR(0x8fe04c)
> C:\Documents and Settings\Owner\Desktop>perl -e "print \\\"perl\""
> SCALAR(0x8fe04c)
> C:\Documents and Settings\Owner\Desktop>perl -e "print \\\"perl\""
> SCALAR(0x8fe04c)
> C:\Documents and Settings\Owner\Desktop>
> ____________________________________________________
> C:\Documents and Settings\Owner\Desktop>perl -e "print unpack('J',
> pack('p', \"p erl\"))"
> 9468532
> C:\Documents and Settings\Owner\Desktop>perl -e "print unpack('J',
> pack('p', \"p erl\"))"
> 9468532
> C:\Documents and Settings\Owner\Desktop>perl -e "print unpack('J',
> pack('p', \"p erl\"))"
> 9468532
> C:\Documents and Settings\Owner\Desktop>perl -e "print unpack('J',
> pack('p', \"p erl\"))"
> 9468532
> C:\Documents and Settings\Owner\Desktop>perl -e "print unpack('J',
> pack('p', \"p erl\"))"
> 9468532
> C:\Documents and Settings\Owner\Desktop>
> ____________________________________________________
> Hash number randomization is irrelevant since the width of the hash
> array is determined by the number of keys/HEKs usually, not the hash
> number. So the memory allocation sizes and order of them to malloc
> are the same. Its it quite popular in "modern" OSes to randomize
> heaps/dlls/stacks/etc per boot or per process nowadays. That is
> probably what is happening in your case. 

Thanks for the lead. This seems to have been the case. After searching in
vein for "perl heap randomization" and stuff like that, I searched for
"linux heap randomization" and got to this page:

http://stackoverflow.com/questions/1455904/how-to-disable-address-space-randomization-for-a-binary-on-linux

This referred me to the setarch -R command and doing this:

$ ( PERL_HASH_SEED=0 setarch x86_64 -R perl libxml2.pl ) 2>&1

now gives me consistent results on each run. It may be enabled by default in 
gdb, though.

Regards,

        Shlomi Fish

-- 
-----------------------------------------------------------------
Shlomi Fish       http://www.shlomifish.org/
Free (Creative Commons) Music Downloads, Reviews and more - http://jamendo.com/

No self‐respecting tomboy would use Mandriva.

Please reply to list if it's a mailing list post - http://shlom.in/reply .

Reply via email to