Bug 238404 - AddressSanitizer should intercept pthread_get_name_np (FreeBSD), not pthread_getname_np (Glibc) symbol
Summary: AddressSanitizer should intercept pthread_get_name_np (FreeBSD), not pthread_...
Status: New
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Only Me
Assignee: freebsd-toolchain (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-06-07 23:09 UTC by Jan Beich
Modified: 2020-06-03 20:54 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jan Beich freebsd_committer 2019-06-07 23:09:32 UTC
AC_CHECK_FUNCS() doesn't check declaration, only library symbol. For one, FreeBSD never had pthread_getname_np() but added a similar function in base r337983.
See contrib/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc

$ cat >a.c
char pthread_getname_np();

int main()
{
	pthread_getname_np();
	return 0;
}

$ cc a.c -fsanitize=address
$ cc a.c
ld: error: undefined symbol: pthread_getname_np
>>> referenced by a.c
>>>               /tmp/a-101e7b.o:(main)
cc: error: linker command failed with exit code 1 (use -v to see invocation)


$ pkg install python27
$ hash git 2>/dev/null || pkg install mercurial
$ hg clone https://hg.mozilla.org/mozilla-unified firefox ||
  git clone https://github.com/mozilla/gecko-dev firefox
$ cd firefox
$ hg update central || git checkout origin/master
$ echo "ac_add_options --with-libclang-path=${LOCALBASE-/usr/local}/llvm80/lib" >>.mozconfig
$ echo "ac_add_options --enable-address-sanitizer" >>.mozconfig
$ ./mach bootstrap # select Firefox for Desktop
$ ./mach build
[...]
In file included from objdir/js/src/Unified_cpp_js_src9.cpp:29:
js/src/threading/posix/Thread.cpp:174:8: error: use of undeclared identifier 'pthread_getname_np'; did you mean 'pthread_get_name_np'?
  rv = pthread_getname_np(pthread_self(), nameBuffer, len);
       ^~~~~~~~~~~~~~~~~~
       pthread_get_name_np
/usr/include/pthread_np.h:52:6: note: 'pthread_get_name_np' declared here
void pthread_get_name_np(pthread_t, char *, size_t);
     ^
In file included from objdir/js/src/Unified_cpp_js_src9.cpp:29:
js/src/threading/posix/Thread.cpp:174:8: error: assigning to 'int' from incompatible type 'void'
  rv = pthread_getname_np(pthread_self(), nameBuffer, len);
       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2 errors generated.
Comment 1 Mark Johnston freebsd_committer 2020-06-03 15:19:10 UTC
I suspect it would be simplest to just make pthread_(get|set)name_np() aliases of pthread_(get|set)_name_np().  Linux and NetBSD use the former, FreeBSD and OpenBSD use the latter.

We could just teach compiler-rt to intercept pthread_get_name_np(), but it's a silly compatibility wart that will bite over and over I'm sure.
Comment 2 Konstantin Belousov freebsd_committer 2020-06-03 15:51:22 UTC
(In reply to Mark Johnston from comment #1)
https://reviews.freebsd.org/D25117
Comment 3 commit-hook freebsd_committer 2020-06-03 20:54:59 UTC
A commit references this bug:

Author: kib
Date: Wed Jun  3 20:54:38 UTC 2020
New revision: 361770
URL: https://svnweb.freebsd.org/changeset/base/361770

Log:
  Add pthread_getname_np() and pthread_setname_np() aliases

  for pthread_get_name_np() and pthread_set_name_np(), to be
  compatible with Linux.

  PR:	238404
  Proposed and reviewed by:	markj
  Sponsored by:	The FreeBSD Foundation
  MFC after:	1 week
  Differential revision:	https://reviews.freebsd.org/D25117

Changes:
  head/include/pthread_np.h
  head/lib/libthr/pthread.map
  head/lib/libthr/thread/thr_info.c
  head/share/man/man3/Makefile
  head/share/man/man3/pthread_set_name_np.3