Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pod/perlhacktips.pod: misleading instructions for AddressSanitizer #16910

Closed
p5pRT opened this issue Mar 29, 2019 · 7 comments
Closed

pod/perlhacktips.pod: misleading instructions for AddressSanitizer #16910

p5pRT opened this issue Mar 29, 2019 · 7 comments
Labels
Closable? We might be able to close this ticket, but we need to check with the reporter distro-All documentation

Comments

@p5pRT
Copy link

p5pRT commented Mar 29, 2019

Migrated from rt.perl.org#133965 (status was 'open')

Searchable as RT133965$

@p5pRT
Copy link
Author

p5pRT commented Mar 29, 2019

From @jkeenan

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

@p5pRT
Copy link
Author

p5pRT commented Oct 13, 2019

From @jkeenan

On Fri, 29 Mar 2019 21​:44​:22 GMT, jkeenan@​pobox.com wrote​:

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.

Is there anyone familiar with address-sanitizer who could confirm my evaluation of our documentation above?

Thank you very much.

--
James E Keenan (jkeenan@​cpan.org)

@p5pRT
Copy link
Author

p5pRT commented Oct 13, 2019

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Oct 15, 2019

From @iabyn

On Sun, Oct 13, 2019 at 11​:10​:04AM -0700, James E Keenan via RT wrote​:

Is there anyone familiar with address-sanitizer who could confirm my
evaluation of our documentation above?

It should indeed be -fsanitize=address

--
31 Dec 1661​: "I have newly taken a solemne oath about abstaining from plays".
1 Jan 1662​: "And after ... we went by coach to the play".
  -- The Diary of Samuel Pepys

richardleach added a commit to richardleach/perl5 that referenced this issue Jun 2, 2020
Addresses Perl#16910 plus other minor updates.
khwilliamson pushed a commit that referenced this issue Jun 2, 2020
Addresses #16910 plus other minor updates.
@richardleach richardleach added the Closable? We might be able to close this ticket, but we need to check with the reporter label Jun 2, 2020
@richardleach
Copy link
Contributor

@jkeenan does #17834 cover all the points you wanted addressing in this issue or is anything still outstanding?

@jkeenan
Copy link
Contributor

jkeenan commented Jun 3, 2020

Yes, as long as the code examples are correct, then my immediate concerns are satisfied.

I have just now built perl with AddressSanitizer in the same FreeBSD-13 VM from which I submitted my original report.

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

We could, of course, mention that AddressSanitizer is also available on FreeBSD, as documented here and shown by the fact that I just build with it there.

@xsawyerx
Copy link
Member

xsawyerx commented Jun 3, 2020

Clang website shows the supported OS:

https://clang.llvm.org/docs/AddressSanitizer.html#supported-platforms

OpenBSD is not one, but FreeBSD and NetBSD are supported, as well as Android ARM. What I want to avoid is having to play "catch-up" with the documentation on what's supported with the risk of being obsolete. (If OpenBSD introduces it prior to 5.32.1, we need to chase it down with the documentation.

I would much rather have the docs saying "ASan is supported on several major operating system. Please review the list provided by compilers, such as Clang (link)." There also seems to be the official documentation (including supported OS) here: https://github.com/google/sanitizers/wiki/AddressSanitizer so that's probably better to point to. (Hopefully, it's maintained.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Closable? We might be able to close this ticket, but we need to check with the reporter distro-All documentation
Projects
None yet
Development

No branches or pull requests

4 participants