Bug 201664 - [build] cannot build 'sort' using WITH_SORT_THREADS=yes
Summary: [build] cannot build 'sort' using WITH_SORT_THREADS=yes
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Only Me
Assignee: Mark Johnston
Keywords: patch
Depends on:
Reported: 2015-07-17 22:33 UTC by Anthony Cornehl
Modified: 2018-02-14 00:33 UTC (History)
4 users (show)

See Also:

Fix building 'sort' with threads support (347 bytes, patch)
2016-03-01 16:38 UTC, Vladimir Zakharov
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Anthony Cornehl 2015-07-17 22:33:56 UTC
I hit this error using a -CURRENT checkout from today. All that's needed to reproduce this is building usr.bin/sort with "WITH_SORT_THREADS=yes" in the environment or /etc/src.conf

# clang -v
FreeBSD clang version 3.6.0 (tags/RELEASE_360/final 230434) 20150225
Target: x86_64-unknown-freebsd11.0
Thread model: posix

--- radixsort.o ---
cc  -O2 -pipe   -DSORT_THREADS -g -std=gnu99 -fstack-protector -Wsystem-headers -Werror -Wall -Wno-format-y2k -W -Wno-unused-parameter -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith -Wreturn-type -Wcast-qual -Wwrite-strings -Wswitch -Wshadow -Wunused-parameter -Wcast-align -Wchar-subscripts -Winline -Wnested-externs -Wredundant-decls -Wold-style-definition -Wno-pointer-sign -Wmissing-variable-declarations -Wthread-safety -Wno-empty-body -Wno-string-plus-int -Wno-unused-const-variable -Qunused-arguments -c /usr/home/acornehl/git/freebsd/usr.bin/sort/radixsort.c -o radixsort.o
/usr/home/acornehl/git/freebsd/usr.bin/sort/radixsort.c:144:17: error: mutex 'g_ls_mutex' is not held on every path through here [-Werror,-Wthread-safety-analysis]
        new_ls->next = g_ls;
/usr/home/acornehl/git/freebsd/usr.bin/sort/radixsort.c:141:3: note: mutex acquired here
/usr/home/acornehl/git/freebsd/usr.bin/sort/radixsort.c:149:3: error: releasing mutex 'g_ls_mutex' that was not held [-Werror,-Wthread-safety-analysis]
2 errors generated.
*** [radixsort.o] Error code 1

make[4]: stopped in /usr/home/acornehl/git/freebsd/usr.bin/sort
1 error
Comment 1 Vladimir Zakharov 2016-03-01 16:38:14 UTC
Created attachment 167612 [details]
Fix building 'sort' with threads support
Comment 2 Vladimir Zakharov 2016-03-01 16:38:59 UTC
It seems to be ThreadSafetyAnasysis false positive [1]. Attached patch removes "-Werror" when sort is being built with threading support.

Another way around is to lock/unlock mutex unconditionally.

1: http://clang.llvm.org/docs/ThreadSafetyAnalysis.html#conditional-locks
Comment 3 Vladimir Zakharov 2016-12-02 12:27:01 UTC
Review: https://reviews.freebsd.org/D8694
Comment 4 Dries Michiels 2018-01-08 21:04:23 UTC
This is still an issue in 11.1-RELEASE.
Comment 5 commit-hook freebsd_committer 2018-02-07 20:37:26 UTC
A commit references this bug:

Author: markj
Date: Wed Feb  7 20:36:38 UTC 2018
New revision: 328995
URL: https://svnweb.freebsd.org/changeset/base/328995

  Fix the WITH_SORT_THREADS build.

  PR:		201664
  MFC after:	1 week

Comment 6 commit-hook freebsd_committer 2018-02-14 00:32:33 UTC
A commit references this bug:

Author: markj
Date: Wed Feb 14 00:32:20 UTC 2018
New revision: 329255
URL: https://svnweb.freebsd.org/changeset/base/329255

  MFC r328995:
  Fix the WITH_SORT_THREADS build.

  PR:	201664

_U  stable/11/