Bug 215125 - clang: Turning on sanitizer options causes the test for non-existent function mallinfo() to pass
Summary: clang: Turning on sanitizer options causes the test for non-existent function...
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 11.0-STABLE
Hardware: Any Any
: --- Affects Only Me
Assignee: Dimitry Andric
URL:
Keywords:
Depends on:
Blocks: 215123
  Show dependency treegraph
 
Reported: 2016-12-07 19:21 UTC by Yuri Victorovich
Modified: 2017-02-13 18:40 UTC (History)
2 users (show)

See Also:


Attachments
C test program: conftest.c (5.14 KB, text/x-csrc)
2016-12-07 19:21 UTC, Yuri Victorovich
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Yuri Victorovich freebsd_committer 2016-12-07 19:21:29 UTC
Created attachment 177764 [details]
C test program: conftest.c

It fails without the sanitizer options:
> cc -o conftest -O2 -pipe -fno-omit-frame-pointer  -fstack-protector -fno-strict-aliasing -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -Qunused-arguments -fstack-protector-all -Wstack-protector -fwrapv --param ssp-buffer-size=1 -fPIE -fasynchronous-unwind-tables -fno-omit-frame-pointer -I${top_srcdir}/src/common  -Wl,-rpath,/usr/local/lib -fstack-protector -pie -Wl,-z,relro -Wl,-z,now -rdynamic conftest.c -lpthread -lexecinfo

It succeeds with the sanitizer options:
> cc -o conftest -O2 -pipe -fno-omit-frame-pointer  -fstack-protector -fno-strict-aliasing -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -Qunused-arguments -fstack-protector-all -Wstack-protector -fwrapv --param ssp-buffer-size=1 -fPIE -fsanitize=address -fsanitize=undefined -fno-omit-frame-pointer -fasynchronous-unwind-tables -fno-omit-frame-pointer -I${top_srcdir}/src/common  -Wl,-rpath,/usr/local/lib -fstack-protector -pie -Wl,-z,relro -Wl,-z,now -rdynamic conftest.c -lpthread -lexecinfo

I found this during security/tor build on FreeBSD 11 amd64.

Sanitizer options shouldn't make such difference, and the test should always fail because there is no such function.
Comment 1 Dimitry Andric freebsd_committer 2016-12-10 14:49:52 UTC
Interesting, this is because the sanitizers have several interceptors for Linux-specific functions and variables, and these cause the link to succeed.

I will check with upstream how we can best solve this. Most likely these interceptors should be disabled completely for FreeBSD.
Comment 2 commit-hook freebsd_committer 2017-02-01 20:41:59 UTC
A commit references this bug:

Author: dim
Date: Wed Feb  1 20:41:09 UTC 2017
New revision: 313052
URL: https://svnweb.freebsd.org/changeset/base/313052

Log:
  Pull in r293536 from upstream compiler-rt trunk:

    Recommit: Stop intercepting some malloc-related functions on FreeBSD
    and macOS

    Summary:
    In https://bugs.freebsd.org/215125 I was notified that some configure
    scripts attempt to test for the Linux-specific `mallinfo` and
    `mallopt` functions by compiling and linking small programs which
    references the functions, and observing whether that results in
    errors.

    FreeBSD and macOS do not have the `mallinfo` and `mallopt` functions,
    so normally these tests would fail, but when sanitizers are enabled,
    they incorrectly succeed, because the sanitizers define interceptors
    for these functions.  This also applies to some other malloc-related
    functions, such as `memalign`, `pvalloc` and `cfree`.

    Fix this by not intercepting `mallinfo`, `mallopt`, `memalign`,
    `pvalloc` and `cfree` for FreeBSD and macOS, in all sanitizers.

    Also delete the non-functional `cfree` wrapper for Windows, to fix the
    test cases on that platform.

    Reviewers: emaste, kcc, rnk

    Subscribers: timurrrr, eugenis, hans, joerg, llvm-commits, kubamracek

    Differential Revision: https://reviews.llvm.org/D27654

  This prevents autoconf scripts from incorrectly detecting that functions
  like mallinfo, mallopt, memalign, pvalloc and cfree are supported.

  PR:		215125, 215455
  MFC after:	1 week

Changes:
  head/contrib/compiler-rt/lib/asan/asan_malloc_linux.cc
  head/contrib/compiler-rt/lib/asan/asan_malloc_win.cc
  head/contrib/compiler-rt/lib/lsan/lsan_interceptors.cc
  head/contrib/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
Comment 3 commit-hook freebsd_committer 2017-02-13 18:39:53 UTC
A commit references this bug:

Author: dim
Date: Mon Feb 13 18:39:22 UTC 2017
New revision: 313702
URL: https://svnweb.freebsd.org/changeset/base/313702

Log:
  MFC r313052:

  Pull in r293536 from upstream compiler-rt trunk:

    Recommit: Stop intercepting some malloc-related functions on FreeBSD
    and macOS

    Summary:
    In https://bugs.freebsd.org/215125 I was notified that some configure
    scripts attempt to test for the Linux-specific `mallinfo` and
    `mallopt` functions by compiling and linking small programs which
    references the functions, and observing whether that results in
    errors.

    FreeBSD and macOS do not have the `mallinfo` and `mallopt` functions,
    so normally these tests would fail, but when sanitizers are enabled,
    they incorrectly succeed, because the sanitizers define interceptors
    for these functions.  This also applies to some other malloc-related
    functions, such as `memalign`, `pvalloc` and `cfree`.

    Fix this by not intercepting `mallinfo`, `mallopt`, `memalign`,
    `pvalloc` and `cfree` for FreeBSD and macOS, in all sanitizers.

    Also delete the non-functional `cfree` wrapper for Windows, to fix the
    test cases on that platform.

    Reviewers: emaste, kcc, rnk

    Subscribers: timurrrr, eugenis, hans, joerg, llvm-commits, kubamracek

    Differential Revision: https://reviews.llvm.org/D27654

  This prevents autoconf scripts from incorrectly detecting that functions
  like mallinfo, mallopt, memalign, pvalloc and cfree are supported.

  PR:		215125, 215455

Changes:
_U  stable/11/
  stable/11/contrib/compiler-rt/lib/asan/asan_malloc_linux.cc
  stable/11/contrib/compiler-rt/lib/asan/asan_malloc_win.cc
  stable/11/contrib/compiler-rt/lib/lsan/lsan_interceptors.cc
  stable/11/contrib/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h