develooper Front page | perl.perl5.porters | Postings from March 2019

[perl #133965] pod/perlhacktips.pod: misleading instructions forAddressSanitizer

From:
James E Keenan
Date:
March 29, 2019 21:44
Subject:
[perl #133965] pod/perlhacktips.pod: misleading instructions forAddressSanitizer
Message ID:
rt-4.0.24-18736-1553895862-407.133965-75-0@perl.org
# New Ticket Created by  James E Keenan 
# Please include the string:  [perl #133965]
# in the subject line of all future correspondence about this issue. 
# <URL: https://rt.perl.org/Ticket/Display.html?id=133965 >


Today Karl Williamson and I were discussing some as yet inexplicable 
smoke-test results in FreeBSD-13.  He advised me to build with 
AddressSanitizer 
(https://github.com/google/sanitizers/wiki/AddressSanitizer) and pointed 
to pod/perlhacktips.pod for guidance.  The relevant section of the 
documentation is:

#####
  AddressSanitizer
   AddressSanitizer is a clang and gcc extension, included in
   clang since v3.1 and gcc since v4.8. It checks illegal
   heap pointers, global pointers, stack pointers and use
   after free errors, and is fast enough that you can easily
   compile your debugging or optimized perl with it. It does
   not check memory leaks though. AddressSanitizer is
   available for Linux, Mac OS X and soon on Windows.

   To build perl with AddressSanitizer, your Configure
   invocation should look like:

       sh Configure -des -Dcc=clang \
          -Accflags=-faddress-sanitizer -Aldflags=-faddress-sanitizer \
          -Alddlflags=-shared\ -faddress-sanitizer

   where these arguments mean:

   *   -Dcc=clang

       This should be replaced by the full path to your clang
       executable if it is not in your path.

   *   -Accflags=-faddress-sanitizer

       Compile perl and extensions sources with
       AddressSanitizer.

   *   -Aldflags=-faddress-sanitizer

       Link the perl executable with AddressSanitizer.

   *   -Alddlflags=-shared\ -faddress-sanitizer

       Link dynamic extensions with AddressSanitizer. You
       must manually specify "-shared" because using
       "-Alddlflags=-shared" will prevent Configure from
       setting a default value for "lddlflags", which usually
       contains "-shared" (at least on Linux).
#####

Note the repeated use of the string 'address-sanitizer'.  Based on that, 
I invoked Configure as follows:

#####
sh ./Configure -des -Dusedevel -Duseithreads -Dcc=clang \
        -Accflags=-faddress-sanitizer -Aldflags=-faddress-sanitizer \
        -Alddlflags=-shared\ -faddress-sanitizer
#####

./Configure quickly failed.

#####
First let's make sure your kit is complete.  Checking...

[snip unproblematic output]

Operating system name? [freebsd]
Operating system version? [13.0-current]
Installation prefix to use? (~name ok) [/usr/local]
AFS does not seem to be running...
What installation prefix should I use for installing files? (~name ok)
[/usr/local]
Getting the current patchlevel...
Build a threading Perl? [y]
Use which C compiler? [clang]
clang: error: unknown argument: '-faddress-sanitizer'
clang: error: unknown argument: '-faddress-sanitizer'
Uh-oh, the C compiler 'clang' doesn't seem to be working.
./trygcc: gcc: not found
clang: error: unknown argument: '-faddress-sanitizer'
clang: error: unknown argument: '-faddress-sanitizer'
Uh-oh, the C compiler 'clang' doesn't seem to be working.
You need to find a working C compiler.
Either (purchase and) install the C compiler supplied by your OS vendor,
or for a free C compiler try http://gcc.gnu.org/
I cannot continue any further, aborting.
#####

I consulted the AddressSanitizer github page cited above as well as some 
code Karl had sent me which he uses to build perl with AddressSanitizer. 
  On that basis I next called:

#####
sh ./Configure -des -Dusedevel -Duseithreads -Dcc=clang \
        -Accflags=-fsanitize=address -Aldflags=-fsanitize=address \
        -Alddlflags=-shared\ -fsanitize=address
#####

Note that the string used in 3 places is now: '-fsanitize=address'.  The 
two words are reversed and are joined with an '=' sign rather than a 
hyphen.  Using this syntax, ./Configure completed, as did 'make'.

The documentation in pod/perlhacktips.pod was written in 2012.  It is 
misleading and needs to be reviewed.

Thank you very much.
Jim Keenan

perl perl perl




nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About