Bug 254048 - devel/llvm12: build fails with fatal error: 'unwind.h' file not found
Summary: devel/llvm12: build fails with fatal error: 'unwind.h' file not found
Status: New
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: amd64 Any
: --- Affects Only Me
Assignee: Brooks Davis
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-03-05 19:14 UTC by Philippe Michel
Modified: 2021-05-03 17:39 UTC (History)
2 users (show)

See Also:
bugzilla: maintainer-feedback? (brooks)


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Philippe Michel 2021-03-05 19:14:04 UTC
On 12.2-STABLE (stable/12-n307-f7007a7d0). Building llvm12 fails with :

FAILED: projects/compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommonSymbolizerNoHooks.i386.dir/sanitizer_unwind_linux_libcdep.cpp.o 
...
/usr/ports/devel/llvm12/work/llvm-project-12.0.0rc2.src/compiler-rt/lib/sanitizer_common/sanitizer_unwind_linux_libcdep.cpp:26:10: fatal error: 'unwind.h' file not found
#include <unwind.h>
         ^~~~~~~~~~
1 error generated.

OPTIONS_FILE_SET+=BE_AMDGPU
OPTIONS_FILE_SET+=CLANG
OPTIONS_FILE_SET+=COMPILER_RT
OPTIONS_FILE_UNSET+=DOCS
OPTIONS_FILE_SET+=EXTRAS
OPTIONS_FILE_UNSET+=GOLD
OPTIONS_FILE_UNSET+=LIT
OPTIONS_FILE_SET+=LLD
OPTIONS_FILE_UNSET+=LLDB
OPTIONS_FILE_SET+=LLD_LINK
OPTIONS_FILE_UNSET+=OPENMP
OPTIONS_FILE_UNSET+=PYCLANG
OPTIONS_FILE_UNSET+=BE_FREEBSD
OPTIONS_FILE_SET+=BE_NATIVE
OPTIONS_FILE_UNSET+=BE_STANDARD
Comment 1 Philippe Michel 2021-03-09 19:00:06 UTC
llvm-devel-13.0.d20210308 fails at the same place.
Comment 2 Tatsuki Makino 2021-04-26 02:03:19 UTC
Do you have any WITH_*/WITHOUT_* variables written in /etc/src.conf (or /etc/make.conf)?
My environment may also have a problem in that area, and I have problems building compiler-rt.
Comment 3 Philippe Michel 2021-04-26 20:05:48 UTC
I have a few WITHOUT_* variables in src.conf, but nothing seemingly related.

On the other hand, there is something weird in /usr/src/include: there is an unwind.h file there, but it never seems to be installed. It is not mentionned in the Makefile, neither for unconditional installation nor in any .if ${MK_whatever} != "no" sections.

Maybe the issue is there, in the base system rather than in the port ? I have copied this file in /usr/include and then llvm12 and llvm-devel build sucessfully.
Comment 4 Tatsuki Makino 2021-04-26 20:24:23 UTC
(In reply to Philippe Michel from comment #3)

It seems that unwind.h is always installed, but it is removed under certain conditions.
You can find it in /usr/src/tools/build/mk/OptionalObsoleteFiles.inc.
If ${MK_CLANG} == no or ${MK_LIBCPLUSPLUS} == no, it is assumed to be deleted by make delete-old.
Comment 5 Philippe Michel 2021-04-27 22:05:39 UTC
I don't think the file is installed then removed by delete-old or not installed at all due to a WITHOUT_something option.

There are 4 unwind.h files in /usr/src:
./contrib/libcxxrt/unwind.h
./contrib/llvm-project/clang/lib/Headers/unwind.h
./contrib/llvm-project/libunwind/include/unwind.h
./include/unwind.h

The first one is not what is needed (just look at its content), but it is installed in /usr/include/c++/v1/unwind.h

I don't think the third one is right either. I didn't find anything that looked like it could install it. I think it is only used to build libunwind.

No. 4 looks like the best candidate. The Makefile there has a comment

# Doing a "make install" builds /usr/include.

but the file is not listed there. There is a "INCS= ... unistd.h utime.h ..." with the headers unconditionally installed, some ".if ${MK_something) == "yes" INCS+= ..." for those only installed only if some flag is set, but unwind.h is never mentionned, which seems wrong since the source file is present.

Finally, No. 2 look like it could be installed by /usr/src/lib/clang/headers/Makefile but it is in a conditional section:
# Headers which possibly conflict with our own versions:
.ifdef INSTALL_CONFLICTING_CLANG_HEADERS
...
INCS+=          unwind.h
and this Makefile is the only file in /usr/src containing the string INSTALL_CONFLICTING_CLANG_HEADERS, so this version of unwind.h is not installed either.


If we look at the port, its Makefile contains this:

# An unwind.h is require to build.  I think an in-tree one should be used
# but this seems to work as a workaround...
COMPILER_RT_BUILD_DEPENDS=      libunwind>0:devel/libunwind

The port tree indeed contains 4 more unwind.h files (llvm-project-12.0.0.src/clang/lib/Headers/unwind.h, corresponding to the CONFLICTING_CLANG_HEADERS above looks like the best candidate), but the workaround doesn't work for me, probably because devel/libunwind installs the file in $LOCALBASE/include, not /usr/include and the devel/llvm12 build doesn't look for it there.


At this point, my impression is that there may well be something wrong in the base system (it is weird that there are two plausible unwind.h files in the sources but neither is installed) and that the port workaround is iffy.
Comment 6 Tatsuki Makino 2021-04-28 03:47:12 UTC
The problem of failing to build in my environment has been solved.
(If WITHOUT_LIB32 is defined in /etc/src.conf, __i386__ will not be found and libclang_rt.asan-i386.so etc. will not be built.)

I've got a buildable environment, so let's compare.

FreeBSD 12.2-STABLE stable/12-n233006-93c6a323224-dirty amd64
kern.ident: GENERIC

# With no packages installed
find -s -- /usr/include/ /usr/local/include/ -iname unwind.h
/usr/include/c++/v1/unwind.h
find: /usr/local/include/: No such file or directory

# after make -C /usr/ports/devel/llvm12/ -D USE_PACKAGE_DEPENDS_ONLY pkg-depends build-depends lib-depends
find -s -- /usr/include/ /usr/local/include/ -iname unwind.h
/usr/include/c++/v1/unwind.h
/usr/local/include/unwind.h

pkg which /usr/local/include/unwind.h
/usr/local/include/unwind.h was installed by package libunwind-20201110

# Installed with the following.
===>   llvm12-12.0.0 depends on package: libunwind>0 - not found
===>   Installing existing package /packages/All/libunwind-20201110.txz

# Command to compile sanitizer_unwind_linux_libcdep.cpp
[ 38% 2620/6826] /usr/bin/c++ -DHAVE_RPC_XDR_H=0 -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Iprojects/compiler-rt/lib/sanitizer_common -I/wrkdirs/usr/ports/devel/llvm12/work/llvm-project-12.0.0.src/compiler-rt/lib/sanitizer_common -Iinclude -I/wrkdirs/usr/ports/devel/llvm12/work/llvm-project-12.0.0.src/llvm/include -I/wrkdirs/usr/ports/devel/llvm12/work/llvm-project-12.0.0.src/compiler-rt/lib/sanitizer_common/.. -O2 -pipe -DNDEBUG -fstack-protector-strong -isystem /usr/local/include -fno-strict-aliasing  -DNDEBUG -isystem /usr/local/include -fPIC -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wstring-conversion -fdiagnostics-color -ffunction-sections -fdata-sections -Wall -std=c++14 -Wno-unused-parameter -O2 -pipe -DNDEBUG -fstack-protector-strong -isystem /usr/local/include -fno-strict-aliasing  -DNDEBUG -isystem /usr/local/include  -m32 -fPIC -fno-builtin -fno-exceptions -fomit-frame-pointer -funwind-tables -fno-stack-protector -fno-sanitize=safe-stack -fvisibility=hidden -fno-lto -O3 -gline-tables-only -Wno-gnu -Wno-variadic-macros -Wno-c99-extensions -nostdinc++ -fno-rtti -Wframe-larger-than=570 -Wglobal-constructors -DSANITIZER_SUPPORTS_WEAK_HOOKS=0 -std=c++14 -MD -MT projects/compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommonSymbolizerNoHooks.i386.dir/sanitizer_unwind_linux_libcdep.cpp.o -MF projects/compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommonSymbolizerNoHooks.i386.dir/sanitizer_unwind_linux_libcdep.cpp.o.d -o projects/compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommonSymbolizerNoHooks.i386.dir/sanitizer_unwind_linux_libcdep.cpp.o -c /wrkdirs/usr/ports/devel/llvm12/work/llvm-project-12.0.0.src/compiler-rt/lib/sanitizer_common/sanitizer_unwind_linux_libcdep.cpp

# options have not been changed.
Options        :
        BE_AMDGPU      : on
        BE_FREEBSD     : off
        BE_NATIVE      : off
        BE_STANDARD    : on
        CLANG          : on
        COMPILER_RT    : on
        DOCS           : on
        EXTRAS         : on
        GOLD           : on
        LIT            : on
        LLD            : on
        LLDB           : on
        LLD_LINK       : on
        OPENMP         : on
        PYCLANG        : on

Is it because of the different options?
Comment 7 Philippe Michel 2021-04-28 20:57:08 UTC
I have upgraded my machine since I opened the bug report. Now it is at:
FreeBSD 13.0-STABLE stable/13-87c0db9d0 MYKERNEL  amd64

I have the file from libunwind-20201110 (already installed as a dependency of other packages):

/usr/include/c++/v1/unwind.h
/usr/local/include/unwind.h

A minor isssue here, the dependency for llvm12 does not appear in the packages database:

# pkg info -d llvm12
llvm12-12.0.0:
        libxml2-2.9.10_3
        perl5-5.32.1_1

# pkg info -r libunwind
libunwind-20201110:
        xorg-server-1.20.11,1
        mesa-dri-20.2.3_1
        ruby-2.7.2_1,1
        mesa-libs-20.2.3

I build llvm12 for the native arch only and with a few options off:

Options        :
        BE_AMDGPU      : on
        BE_FREEBSD     : off
        BE_NATIVE      : on
        BE_STANDARD    : off
        CLANG          : on
        COMPILER_RT    : on
        DOCS           : off
        EXTRAS         : on
        GOLD           : off
        LIT            : off
        LLD            : on
        LLDB           : off
        LLD_LINK       : on
        OPENMP         : off
        PYCLANG        : off

Compilation fails at:

[ 35% 1802/5015] /usr/bin/c++ -DHAVE_RPC_XDR_H=0 -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Iprojects/compiler-rt/lib/sanitizer_common -I/usr/ports/devel/llvm12/work/llvm-project-12.0.0.src/compiler-rt/lib/sanitizer_common -Iinclude -I/usr/ports/devel/llvm12/work/llvm-project-12.0.0.src/llvm/include -I/usr/ports/devel/llvm12/work/llvm-project-12.0.0.src/compiler-rt/lib/sanitizer_common/.. -O2 -pipe -march=broadwell -DNDEBUG -fstack-protector-strong -fno-strict-aliasing  -DNDEBUG -fPIC -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -fdiagnostics-color -ffunction-sections -fdata-sections -Wall -std=c++14 -Wno-unused-parameter -O2 -pipe -march=broadwell -DNDEBUG -fstack-protector-strong -fno-strict-aliasing  -DNDEBUG  -m32 -fPIC -fno-builtin -fno-exceptions -fomit-frame-pointer -funwind-tables -fno-stack-protector -fno-sanitize=safe-stack -fvisibility=hidden -fno-lto -O3 -gline-tables-only -Wno-gnu -Wno-variadic-macros -Wno-c99-extensions -nostdinc++ -fno-rtti -Wframe-larger-than=570 -Wglobal-constructors -DSANITIZER_SUPPORTS_WEAK_HOOKS=0 -std=c++14 -MD -MT projects/compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommonSymbolizerNoHooks.i386.dir/sanitizer_unwind_linux_libcdep.cpp.o -MF projects/compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommonSymbolizerNoHooks.i386.dir/sanitizer_unwind_linux_libcdep.cpp.o.d -o projects/compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommonSymbolizerNoHooks.i386.dir/sanitizer_unwind_linux_libcdep.cpp.o -c /usr/ports/devel/llvm12/work/llvm-project-12.0.0.src/compiler-rt/lib/sanitizer_common/sanitizer_unwind_linux_libcdep.cpp

I dont't have "-isystem /usr/local/include" which is why the libunwind port doesn't help.

I don't know where it comes from for you. A possibly relevant option is GOLD (on for you, off for me) since the port Makefile has theses lines:

GOLD_DESC=              Build the LLVM Gold plugin for LTO
GOLD_CMAKE_ON=          -DLLVM_BINUTILS_INCDIR=${LOCALBASE}/include

although I don't see why a binutils-related flag would be used for the compiler-rt libraries.
Comment 8 Tatsuki Makino 2021-04-28 23:16:27 UTC
(In reply to Philippe Michel from comment #7)

My -isystem /usr/local/include seems to have been added by USES=localbase.
USES=localbase seems to have been added by USES=libedit.
This seems to be caused by OPTIONS_FILE_UNSET+=LLDB.
Comment 9 Philippe Michel 2021-04-29 20:59:45 UTC
OK. In that case the using libunwind works for the default options set, or at least when lldb is built. Maybe a bit by luck (is it expected that a flag intended for building lldb applies for other components ?)

Anyway, what I will do is use (copy or link to /usr/include) the unwind.h from the libunwind port instead of that from /usr/src/include, to stay closer to what is in the llvm port, and check if this is still needed when new version of llvm or llvm-devel appear.
Comment 10 Tatsuki Makino 2021-04-29 22:18:03 UTC
devel/llvm11 includes libedit in USES in all cases.
That is, llvm11 will be built using USES=localbase (_USES_POST+=localbase), which is implicitly defined by USES=libedit.

devel/llvm12 has been changed so that USES=libedit is defined by options only when building lldb that uses libedit.
For this reason, llvm12 will need to explicitly define USES=localbase.

The same applies to devel/llvm-devel.
Comment 11 John Hein 2021-04-30 19:46:16 UTC
(In reply to Tatsuki Makino from comment #10)
+1 - I have the same problem reported by Philippe.  And no -I/usr/local/include nor -isystem /usr/local/include is used to compile sanitizer_unwind_linux_libcdep.cpp (but --nostdinc++ is used, so that causes /usr/include/unwind.h to not be found).

Seems like USES=localbase will work.  Or better perhaps, the llvm build should try to find unwind.h and add the appropriate -I flags to be able to include it when compiling the code that wants unwind.h

A patch for the former is not provided, but is trivial.  I have no patch suggestion yet for the latter.
Comment 12 commit-hook freebsd_committer 2021-05-03 17:39:32 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/ports/commit/?id=6354328d5f77001b261a22475dbf4f465d3e4758

commit 6354328d5f77001b261a22475dbf4f465d3e4758
Author:     Brooks Davis <brooks@FreeBSD.org>
AuthorDate: 2021-05-03 17:13:52 +0000
Commit:     Brooks Davis <brooks@FreeBSD.org>
CommitDate: 2021-05-03 17:35:40 +0000

    devel/llvm12: address build issues in some configs

    In some cases (notably when LLDB is not selected), COMPILER_RT fails to
    build owing to not finding unwind.h.  Add USES=localbase to COMPILER_RT
    to address this.[0]

    When building on amd64 without /usr/lib32 compat libraries installed,
    COMPILER_RT doesn't build i386 sanitizer libs.  Detect this case and
    don't add to plist.[1]

    Submitted by:   Tatsuki Makino [0]
    PR:             254048 [0], 255527 [1]
    MFH:            2020Q2

 devel/llvm12/Makefile | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)