[v6,1/4] package/clang: new package

Message ID 20180411161452.25043-2-valentin.korenblit@smile.fr
State Accepted
Headers show
Series
  • llvm for mesa3d
Related show

Commit Message

Valentin Korenblit April 11, 2018, 4:14 p.m.
This patch provides Clang tools and libraries for the host and libclang
for the target.

host-clang is needed to build libclc, which is also provided in a follup patch.

We need libclang for the target because it is used by most of OpenCL implementations.

A later patch in this series will enable Clover, the OpenCl implementation part
of Mesa3D, which requires libclang.

clang-tblgen must be copied to HOST_DIR as it is not installed by default but is needed
for cross-compilation: http://lists.llvm.org/pipermail/cfe-dev/2015-June/043318.html

Signed-off-by: Valentin Korenblit <valentin.korenblit@smile.fr>
---
 DEVELOPERS               |  1 +
 package/Config.in        |  1 +
 package/clang/Config.in  | 22 +++++++++++++++
 package/clang/clang.hash |  3 ++
 package/clang/clang.mk   | 72 ++++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 99 insertions(+)
 create mode 100644 package/clang/Config.in
 create mode 100644 package/clang/clang.hash
 create mode 100644 package/clang/clang.mk

Comments

Thomas Petazzoni April 28, 2018, 12:51 p.m. | #1
Hello Valentin,

On Wed, 11 Apr 2018 18:14:49 +0200, Valentin Korenblit wrote:
> This patch provides Clang tools and libraries for the host and libclang
> for the target.
> 
> host-clang is needed to build libclc, which is also provided in a follup patch.
> 
> We need libclang for the target because it is used by most of OpenCL implementations.
> 
> A later patch in this series will enable Clover, the OpenCl implementation part
> of Mesa3D, which requires libclang.
> 
> clang-tblgen must be copied to HOST_DIR as it is not installed by default but is needed
> for cross-compilation: http://lists.llvm.org/pipermail/cfe-dev/2015-June/043318.html
> 
> Signed-off-by: Valentin Korenblit <valentin.korenblit@smile.fr>
> ---
>  DEVELOPERS               |  1 +
>  package/Config.in        |  1 +
>  package/clang/Config.in  | 22 +++++++++++++++
>  package/clang/clang.hash |  3 ++
>  package/clang/clang.mk   | 72 ++++++++++++++++++++++++++++++++++++++++++++++++
>  5 files changed, 99 insertions(+)
>  create mode 100644 package/clang/Config.in
>  create mode 100644 package/clang/clang.hash
>  create mode 100644 package/clang/clang.mk

I've applied to master, after doing the following changes:

    [Thomas:
     - Add Config.in comment about BR2_TOOLCHAIN_HAS_GCC_BUG_64735
     - Minor reformatting/rewrapping of comments in .mk file]

However, I've noticed that a lot of stuff gets installed in the target,
which doesn't seem very useful (see below). At least the heders
in /usr/lib/clang don't see very useful. There's a bunch of Python
script and Javascript files as well. Do you think some of these could
be removed, perhaps through post-install target hooks ?

`-- usr
    |-- bin
    |   |-- c-index-test
    |   |-- git-clang-format
    |   |-- scan-build
    |   `-- scan-view
    |-- lib
    |   |-- LLVMHello.so
    |   |-- clang
    |   |   `-- 5.0.1
    |   |       `-- include
    |   |           |-- __clang_cuda_builtin_vars.h
    |   |           |-- __clang_cuda_cmath.h
    |   |           |-- __clang_cuda_complex_builtins.h
    |   |           |-- __clang_cuda_intrinsics.h
    |   |           |-- __clang_cuda_math_forward_declares.h
    |   |           |-- __clang_cuda_runtime_wrapper.h
    |   |           |-- __stddef_max_align_t.h
    |   |           |-- __wmmintrin_aes.h
    |   |           |-- __wmmintrin_pclmul.h
    |   |           |-- adxintrin.h
    |   |           |-- altivec.h
    |   |           |-- ammintrin.h
    |   |           |-- arm_acle.h
    |   |           |-- arm_neon.h
    |   |           |-- armintr.h
    |   |           |-- avx2intrin.h
    |   |           |-- avx512bwintrin.h
    |   |           |-- avx512cdintrin.h
    |   |           |-- avx512dqintrin.h
    |   |           |-- avx512erintrin.h
    |   |           |-- avx512fintrin.h
    |   |           |-- avx512ifmaintrin.h
    |   |           |-- avx512ifmavlintrin.h
    |   |           |-- avx512pfintrin.h
    |   |           |-- avx512vbmiintrin.h
    |   |           |-- avx512vbmivlintrin.h
    |   |           |-- avx512vlbwintrin.h
    |   |           |-- avx512vlcdintrin.h
    |   |           |-- avx512vldqintrin.h
    |   |           |-- avx512vlintrin.h
    |   |           |-- avx512vpopcntdqintrin.h
    |   |           |-- avxintrin.h
    |   |           |-- bmi2intrin.h
    |   |           |-- bmiintrin.h
    |   |           |-- clflushoptintrin.h
    |   |           |-- clzerointrin.h
    |   |           |-- cpuid.h
    |   |           |-- cuda_wrappers
    |   |           |   |-- algorithm
    |   |           |   |-- complex
    |   |           |   `-- new
    |   |           |-- emmintrin.h
    |   |           |-- f16cintrin.h
    |   |           |-- float.h
    |   |           |-- fma4intrin.h
    |   |           |-- fmaintrin.h
    |   |           |-- fxsrintrin.h
    |   |           |-- htmintrin.h
    |   |           |-- htmxlintrin.h
    |   |           |-- ia32intrin.h
    |   |           |-- immintrin.h
    |   |           |-- intrin.h
    |   |           |-- inttypes.h
    |   |           |-- iso646.h
    |   |           |-- limits.h
    |   |           |-- lwpintrin.h
    |   |           |-- lzcntintrin.h
    |   |           |-- mm3dnow.h
    |   |           |-- mm_malloc.h
    |   |           |-- mmintrin.h
    |   |           |-- module.modulemap
    |   |           |-- msa.h
    |   |           |-- mwaitxintrin.h
    |   |           |-- nmmintrin.h
    |   |           |-- opencl-c.h
    |   |           |-- pkuintrin.h
    |   |           |-- pmmintrin.h
    |   |           |-- popcntintrin.h
    |   |           |-- prfchwintrin.h
    |   |           |-- rdseedintrin.h
    |   |           |-- rtmintrin.h
    |   |           |-- s390intrin.h
    |   |           |-- shaintrin.h
    |   |           |-- smmintrin.h
    |   |           |-- stdalign.h
    |   |           |-- stdarg.h
    |   |           |-- stdatomic.h
    |   |           |-- stdbool.h
    |   |           |-- stddef.h
    |   |           |-- stdint.h
    |   |           |-- stdnoreturn.h
    |   |           |-- tbmintrin.h
    |   |           |-- tgmath.h
    |   |           |-- tmmintrin.h
    |   |           |-- unwind.h
    |   |           |-- vadefs.h
    |   |           |-- varargs.h
    |   |           |-- vecintrin.h
    |   |           |-- wmmintrin.h
    |   |           |-- x86intrin.h
    |   |           |-- xmmintrin.h
    |   |           |-- xopintrin.h
    |   |           |-- xsavecintrin.h
    |   |           |-- xsaveintrin.h
    |   |           |-- xsaveoptintrin.h
    |   |           |-- xsavesintrin.h
    |   |           `-- xtestintrin.h
    |   |-- libLLVM-5.0.1.so -> libLLVM-5.0.so
    |   |-- libLLVM-5.0.so
    |   |-- libLLVM.so -> libLLVM-5.0.so
    |   |-- libLTO.so -> libLTO.so.5
    |   |-- libLTO.so.5 -> libLTO.so.5.0.1
    |   |-- libLTO.so.5.0.1
    |   |-- libclang.so -> libclang.so.5
    |   |-- libclang.so.5 -> libclang.so.5.0
    |   |-- libclang.so.5.0
    |   |-- libstdc++.so.6 -> libstdc++.so.6.0.22
    |   |-- libstdc++.so.6.0.22
    |   |-- libstdc++.so.6.0.22-gdb.py
    |   `-- os-release
    |-- lib64 -> lib
    |-- libexec
    |   |-- c++-analyzer
    |   `-- ccc-analyzer
    |-- sbin
    `-- share
        |-- clang
        |   |-- bash-autocomplete.sh
        |   |-- clang-format-bbedit.applescript
        |   |-- clang-format-diff.py
        |   |-- clang-format-sublime.py
        |   |-- clang-format.el
        |   |-- clang-format.py
        |   |-- clang-rename.el
        |   `-- clang-rename.py
        |-- opt-viewer
        |   |-- opt-diff.py
        |   |-- opt-stats.py
        |   |-- opt-viewer.py
        |   |-- optpmap.py
        |   |-- optrecord.py
        |   `-- style.css
        |-- scan-build
        |   |-- scanview.css
        |   `-- sorttable.js
        `-- scan-view
            |-- FileRadar.scpt
            |-- GetRadarVersion.scpt
            |-- Reporter.py
            |-- ScanView.py
            |-- bugcatcher.ico
            `-- startfile.py

Also, I must say I was impressed by the size of the libLLVM and
libclang libraries. libLLVM is 23MB, while libclang is 22MB. What seems
weird however is that libclang is not linked against libLLVM:

$ readelf -d libclang.so.5.0   

Dynamic section at offset 0x15ebbd0 contains 31 entries:
  Tag        Type                         Name/Value
 0x0000000000000001 (NEEDED)             Shared library: [libstdc++.so.6]
 0x0000000000000001 (NEEDED)             Shared library: [libgcc_s.so.1]
 0x0000000000000001 (NEEDED)             Shared library: [libc.so.0]
 0x0000000000000001 (NEEDED)             Shared library: [ld64-uClibc.so.1]
 0x000000000000000e (SONAME)             Library soname: [libclang.so.5]
 0x000000000000001d (RUNPATH)            Library runpath: []

Is libclang statically linked against libLLVM, causing a huge
duplication of code size ?

Looking at the build output of libclang, it indeed seems like it uses
the .a libraries from LLVM, and not the dynamic library. So the LLVM
code is present twice: once in libLLVM.so, and a second time in
libclang.so. This isn't nice at all. Could you look into this ?

I've pasted the command line used by the clang package to produce its
libclang.so library at http://code.bulix.org/li1n6r-325499?raw. You can
see it uses the LLVM .a files directly.

My defconfig was:

BR2_x86_64=y
BR2_x86_core2=y
BR2_TOOLCHAIN_EXTERNAL=y
BR2_TOOLCHAIN_EXTERNAL_DOWNLOAD=y
BR2_TOOLCHAIN_EXTERNAL_URL="http://autobuild.buildroot.org/toolchains/tarballs/br-x86-64-core2-full-2018.02-891-g046c5e2.tar.bz2"
BR2_TOOLCHAIN_EXTERNAL_GCC_6=y
BR2_TOOLCHAIN_EXTERNAL_HEADERS_4_16=y
BR2_TOOLCHAIN_EXTERNAL_LOCALE=y
# BR2_TOOLCHAIN_EXTERNAL_HAS_THREADS_DEBUG is not set
BR2_TOOLCHAIN_EXTERNAL_CXX=y
BR2_INIT_NONE=y
BR2_SYSTEM_BIN_SH_NONE=y
# BR2_PACKAGE_BUSYBOX is not set
BR2_PACKAGE_CLANG=y
# BR2_TARGET_ROOTFS_TAR is not set

Thanks!

Thomas
Valentin Korenblit April 30, 2018, 7:20 a.m. | #2
Hi Thomas,

On 28/04/2018 14:51, Thomas Petazzoni wrote:
> Hello Valentin,
>
> On Wed, 11 Apr 2018 18:14:49 +0200, Valentin Korenblit wrote:
>> This patch provides Clang tools and libraries for the host and libclang
>> for the target.
>>
>> host-clang is needed to build libclc, which is also provided in a follup patch.
>>
>> We need libclang for the target because it is used by most of OpenCL implementations.
>>
>> A later patch in this series will enable Clover, the OpenCl implementation part
>> of Mesa3D, which requires libclang.
>>
>> clang-tblgen must be copied to HOST_DIR as it is not installed by default but is needed
>> for cross-compilation: http://lists.llvm.org/pipermail/cfe-dev/2015-June/043318.html
>>
>> Signed-off-by: Valentin Korenblit <valentin.korenblit@smile.fr>
>> ---
>>   DEVELOPERS               |  1 +
>>   package/Config.in        |  1 +
>>   package/clang/Config.in  | 22 +++++++++++++++
>>   package/clang/clang.hash |  3 ++
>>   package/clang/clang.mk   | 72 ++++++++++++++++++++++++++++++++++++++++++++++++
>>   5 files changed, 99 insertions(+)
>>   create mode 100644 package/clang/Config.in
>>   create mode 100644 package/clang/clang.hash
>>   create mode 100644 package/clang/clang.mk
> I've applied to master, after doing the following changes:
>
>      [Thomas:
>       - Add Config.in comment about BR2_TOOLCHAIN_HAS_GCC_BUG_64735
>       - Minor reformatting/rewrapping of comments in .mk file]
>
> However, I've noticed that a lot of stuff gets installed in the target,
> which doesn't seem very useful (see below). At least the heders
> in /usr/lib/clang don't see very useful. There's a bunch of Python
> script and Javascript files as well. Do you think some of these could
> be removed, perhaps through post-install target hooks ?

I'll check this today, I think the binaries and scripts shouldn't be necessary,
but I am not completely sure about the includes when using OpenCL. I will test what
happens at runtime.

>
> `-- usr
>      |-- bin
>      |   |-- c-index-test
>      |   |-- git-clang-format
>      |   |-- scan-build
>      |   `-- scan-view
>      |-- lib
>      |   |-- LLVMHello.so
>      |   |-- clang
>      |   |   `-- 5.0.1
>      |   |       `-- include
>      |   |           |-- __clang_cuda_builtin_vars.h
>      |   |           |-- __clang_cuda_cmath.h
>      |   |           |-- __clang_cuda_complex_builtins.h
>      |   |           |-- __clang_cuda_intrinsics.h
>      |   |           |-- __clang_cuda_math_forward_declares.h
>      |   |           |-- __clang_cuda_runtime_wrapper.h
>      |   |           |-- __stddef_max_align_t.h
>      |   |           |-- __wmmintrin_aes.h
>      |   |           |-- __wmmintrin_pclmul.h
>      |   |           |-- adxintrin.h
>      |   |           |-- altivec.h
>      |   |           |-- ammintrin.h
>      |   |           |-- arm_acle.h
>      |   |           |-- arm_neon.h
>      |   |           |-- armintr.h
>      |   |           |-- avx2intrin.h
>      |   |           |-- avx512bwintrin.h
>      |   |           |-- avx512cdintrin.h
>      |   |           |-- avx512dqintrin.h
>      |   |           |-- avx512erintrin.h
>      |   |           |-- avx512fintrin.h
>      |   |           |-- avx512ifmaintrin.h
>      |   |           |-- avx512ifmavlintrin.h
>      |   |           |-- avx512pfintrin.h
>      |   |           |-- avx512vbmiintrin.h
>      |   |           |-- avx512vbmivlintrin.h
>      |   |           |-- avx512vlbwintrin.h
>      |   |           |-- avx512vlcdintrin.h
>      |   |           |-- avx512vldqintrin.h
>      |   |           |-- avx512vlintrin.h
>      |   |           |-- avx512vpopcntdqintrin.h
>      |   |           |-- avxintrin.h
>      |   |           |-- bmi2intrin.h
>      |   |           |-- bmiintrin.h
>      |   |           |-- clflushoptintrin.h
>      |   |           |-- clzerointrin.h
>      |   |           |-- cpuid.h
>      |   |           |-- cuda_wrappers
>      |   |           |   |-- algorithm
>      |   |           |   |-- complex
>      |   |           |   `-- new
>      |   |           |-- emmintrin.h
>      |   |           |-- f16cintrin.h
>      |   |           |-- float.h
>      |   |           |-- fma4intrin.h
>      |   |           |-- fmaintrin.h
>      |   |           |-- fxsrintrin.h
>      |   |           |-- htmintrin.h
>      |   |           |-- htmxlintrin.h
>      |   |           |-- ia32intrin.h
>      |   |           |-- immintrin.h
>      |   |           |-- intrin.h
>      |   |           |-- inttypes.h
>      |   |           |-- iso646.h
>      |   |           |-- limits.h
>      |   |           |-- lwpintrin.h
>      |   |           |-- lzcntintrin.h
>      |   |           |-- mm3dnow.h
>      |   |           |-- mm_malloc.h
>      |   |           |-- mmintrin.h
>      |   |           |-- module.modulemap
>      |   |           |-- msa.h
>      |   |           |-- mwaitxintrin.h
>      |   |           |-- nmmintrin.h
>      |   |           |-- opencl-c.h
>      |   |           |-- pkuintrin.h
>      |   |           |-- pmmintrin.h
>      |   |           |-- popcntintrin.h
>      |   |           |-- prfchwintrin.h
>      |   |           |-- rdseedintrin.h
>      |   |           |-- rtmintrin.h
>      |   |           |-- s390intrin.h
>      |   |           |-- shaintrin.h
>      |   |           |-- smmintrin.h
>      |   |           |-- stdalign.h
>      |   |           |-- stdarg.h
>      |   |           |-- stdatomic.h
>      |   |           |-- stdbool.h
>      |   |           |-- stddef.h
>      |   |           |-- stdint.h
>      |   |           |-- stdnoreturn.h
>      |   |           |-- tbmintrin.h
>      |   |           |-- tgmath.h
>      |   |           |-- tmmintrin.h
>      |   |           |-- unwind.h
>      |   |           |-- vadefs.h
>      |   |           |-- varargs.h
>      |   |           |-- vecintrin.h
>      |   |           |-- wmmintrin.h
>      |   |           |-- x86intrin.h
>      |   |           |-- xmmintrin.h
>      |   |           |-- xopintrin.h
>      |   |           |-- xsavecintrin.h
>      |   |           |-- xsaveintrin.h
>      |   |           |-- xsaveoptintrin.h
>      |   |           |-- xsavesintrin.h
>      |   |           `-- xtestintrin.h
>      |   |-- libLLVM-5.0.1.so -> libLLVM-5.0.so
>      |   |-- libLLVM-5.0.so
>      |   |-- libLLVM.so -> libLLVM-5.0.so
>      |   |-- libLTO.so -> libLTO.so.5
>      |   |-- libLTO.so.5 -> libLTO.so.5.0.1
>      |   |-- libLTO.so.5.0.1
>      |   |-- libclang.so -> libclang.so.5
>      |   |-- libclang.so.5 -> libclang.so.5.0
>      |   |-- libclang.so.5.0
>      |   |-- libstdc++.so.6 -> libstdc++.so.6.0.22
>      |   |-- libstdc++.so.6.0.22
>      |   |-- libstdc++.so.6.0.22-gdb.py
>      |   `-- os-release
>      |-- lib64 -> lib
>      |-- libexec
>      |   |-- c++-analyzer
>      |   `-- ccc-analyzer
>      |-- sbin
>      `-- share
>          |-- clang
>          |   |-- bash-autocomplete.sh
>          |   |-- clang-format-bbedit.applescript
>          |   |-- clang-format-diff.py
>          |   |-- clang-format-sublime.py
>          |   |-- clang-format.el
>          |   |-- clang-format.py
>          |   |-- clang-rename.el
>          |   `-- clang-rename.py
>          |-- opt-viewer
>          |   |-- opt-diff.py
>          |   |-- opt-stats.py
>          |   |-- opt-viewer.py
>          |   |-- optpmap.py
>          |   |-- optrecord.py
>          |   `-- style.css
>          |-- scan-build
>          |   |-- scanview.css
>          |   `-- sorttable.js
>          `-- scan-view
>              |-- FileRadar.scpt
>              |-- GetRadarVersion.scpt
>              |-- Reporter.py
>              |-- ScanView.py
>              |-- bugcatcher.ico
>              `-- startfile.py
>
> Also, I must say I was impressed by the size of the libLLVM and
> libclang libraries. libLLVM is 23MB, while libclang is 22MB. What seems
> weird however is that libclang is not linked against libLLVM:
>
> $ readelf -d libclang.so.5.0
>
> Dynamic section at offset 0x15ebbd0 contains 31 entries:
>    Tag        Type                         Name/Value
>   0x0000000000000001 (NEEDED)             Shared library: [libstdc++.so.6]
>   0x0000000000000001 (NEEDED)             Shared library: [libgcc_s.so.1]
>   0x0000000000000001 (NEEDED)             Shared library: [libc.so.0]
>   0x0000000000000001 (NEEDED)             Shared library: [ld64-uClibc.so.1]
>   0x000000000000000e (SONAME)             Library soname: [libclang.so.5]
>   0x000000000000001d (RUNPATH)            Library runpath: []
>
> Is libclang statically linked against libLLVM, causing a huge
> duplication of code size ?
>
> Looking at the build output of libclang, it indeed seems like it uses
> the .a libraries from LLVM, and not the dynamic library. So the LLVM
> code is present twice: once in libLLVM.so, and a second time in
> libclang.so. This isn't nice at all. Could you look into this ?

Yes, I've just checked with nm that functions are duplicated. I'll try to
fix this.

> I've pasted the command line used by the clang package to produce its
> libclang.so library at http://code.bulix.org/li1n6r-325499?raw. You can
> see it uses the LLVM .a files directly.
>
> My defconfig was:
>
> BR2_x86_64=y
> BR2_x86_core2=y
> BR2_TOOLCHAIN_EXTERNAL=y
> BR2_TOOLCHAIN_EXTERNAL_DOWNLOAD=y
> BR2_TOOLCHAIN_EXTERNAL_URL="http://autobuild.buildroot.org/toolchains/tarballs/br-x86-64-core2-full-2018.02-891-g046c5e2.tar.bz2"
> BR2_TOOLCHAIN_EXTERNAL_GCC_6=y
> BR2_TOOLCHAIN_EXTERNAL_HEADERS_4_16=y
> BR2_TOOLCHAIN_EXTERNAL_LOCALE=y
> # BR2_TOOLCHAIN_EXTERNAL_HAS_THREADS_DEBUG is not set
> BR2_TOOLCHAIN_EXTERNAL_CXX=y
> BR2_INIT_NONE=y
> BR2_SYSTEM_BIN_SH_NONE=y
> # BR2_PACKAGE_BUSYBOX is not set
> BR2_PACKAGE_CLANG=y
> # BR2_TARGET_ROOTFS_TAR is not set
>
> Thanks!
>
> Thomas

Best regards,

Valentin

Patch

diff --git a/DEVELOPERS b/DEVELOPERS
index 85e22c2e71..da1c6fa58e 100644
--- a/DEVELOPERS
+++ b/DEVELOPERS
@@ -1906,6 +1906,7 @@  F:	package/dropwatch/
 F:	package/tstools/
 
 N:	Valentin Korenblit <valentin.korenblit@smile.fr>
+F:	package/clang/
 F:	package/llvm/
 
 N:	Vanya Sergeev <vsergeev@gmail.com>
diff --git a/package/Config.in b/package/Config.in
index e48d0b4c64..62770790a1 100644
--- a/package/Config.in
+++ b/package/Config.in
@@ -1481,6 +1481,7 @@  menu "Other"
 	source "package/bctoolbox/Config.in"
 	source "package/bdwgc/Config.in"
 	source "package/boost/Config.in"
+	source "package/clang/Config.in"
 	source "package/clapack/Config.in"
 	source "package/classpath/Config.in"
 	source "package/cppcms/Config.in"
diff --git a/package/clang/Config.in b/package/clang/Config.in
new file mode 100644
index 0000000000..f94ddfdc21
--- /dev/null
+++ b/package/clang/Config.in
@@ -0,0 +1,22 @@ 
+config BR2_PACKAGE_CLANG
+	bool "clang"
+	depends on BR2_PACKAGE_LLVM_ARCH_SUPPORTS
+	depends on BR2_HOST_GCC_AT_LEAST_4_8
+	depends on BR2_TOOLCHAIN_GCC_AT_LEAST_4_8
+	depends on BR2_TOOLCHAIN_HAS_THREADS
+	depends on BR2_INSTALL_LIBSTDCPP
+	depends on !BR2_TOOLCHAIN_HAS_GCC_BUG_64735 # std::shared_future
+	depends on !BR2_STATIC_LIBS
+	depends on BR2_USE_WCHAR # std::wstring
+	select BR2_PACKAGE_LLVM
+	help
+	  Clang is a C/C++, Objective C/C++ and OpenCL C front-end
+	  for the LLVM compiler.
+
+	  http://clang.llvm.org
+
+comment "clang needs a toolchain w/ wchar, threads, C++, gcc >= 4.8, host gcc >= 4.8, dynamic library"
+	depends on BR2_PACKAGE_LLVM_ARCH_SUPPORTS
+	depends on !BR2_TOOLCHAIN_HAS_THREADS || !BR2_INSTALL_LIBSTDCPP || \
+		!BR2_HOST_GCC_AT_LEAST_4_8 || !BR2_TOOLCHAIN_GCC_AT_LEAST_4_8 \
+		|| BR2_STATIC_LIBS || !BR2_USE_WCHAR
diff --git a/package/clang/clang.hash b/package/clang/clang.hash
new file mode 100644
index 0000000000..a5bf909814
--- /dev/null
+++ b/package/clang/clang.hash
@@ -0,0 +1,3 @@ 
+# locally calculated
+sha256 135f6c9b0cd2da1aff2250e065946258eb699777888df39ca5a5b4fe5e23d0ff cfe-5.0.1.src.tar.xz
+sha256 de4c79665f0f5688b0ace17cba6f8e0343925bb95e0949d66d47bbd4527310d6 LICENSE.TXT
diff --git a/package/clang/clang.mk b/package/clang/clang.mk
new file mode 100644
index 0000000000..d5f378b7f1
--- /dev/null
+++ b/package/clang/clang.mk
@@ -0,0 +1,72 @@ 
+################################################################################
+#
+# clang
+#
+################################################################################
+
+CLANG_VERSION = 5.0.1
+CLANG_SITE = http://llvm.org/releases/$(CLANG_VERSION)
+CLANG_SOURCE = cfe-$(CLANG_VERSION).src.tar.xz
+CLANG_LICENSE = NCSA
+CLANG_LICENSE_FILES = LICENSE.TXT
+CLANG_SUPPORTS_IN_SOURCE_BUILD = NO
+CLANG_INSTALL_STAGING = YES
+
+HOST_CLANG_DEPENDENCIES = host-llvm host-libxml2
+CLANG_DEPENDENCIES = llvm host-clang
+
+# This option is needed. Otherwise multiple shared libs (libclangAST.so,
+# libclangBasic.so, libclangFrontend.so, etc.) will be generated. As a final
+# shared lib containing all these components (libclang.so) is also generated, this
+# resulted in the following error when trying to use tools that use libclang:
+# $ CommandLine Error: Option 'track-memory' registered more than once!
+# $ LLVM ERROR: inconsistency in registered CommandLine options
+# By setting BUILD_SHARED_LIBS to OFF, we generate multiple static libraries
+# (the same way as host's clang build) and finally libclang.so to be installed on the
+# target.
+CLANG_CONF_OPTS += -DBUILD_SHARED_LIBS=OFF
+
+# Default is Debug build, which requires considerably more disk space and
+# build time. Release build is selected for host and target because the linker
+# can run out of memory in Debug mode.
+HOST_CLANG_CONF_OPTS += -DCMAKE_BUILD_TYPE=Release
+CLANG_CONF_OPTS += -DCMAKE_BUILD_TYPE=Release
+
+CLANG_CONF_OPTS += -DCMAKE_CROSSCOMPILING=1
+
+# We need to build tools because libclang is a tool
+HOST_CLANG_CONF_OPTS += -DCLANG_BUILD_TOOLS=ON
+CLANG_CONF_OPTS += -DCLANG_BUILD_TOOLS=ON
+
+HOST_CLANG_CONF_OPTS += \
+	-DCLANG_BUILD_EXAMPLES=OFF \
+	-DCLANG_INCLUDE_DOCS=OFF \
+	-DCLANG_INCLUDE_TESTS=OFF
+
+CLANG_CONF_OPTS += \
+	-DCLANG_BUILD_EXAMPLES=OFF \
+	-DCLANG_INCLUDE_DOCS=OFF \
+	-DCLANG_INCLUDE_TESTS=OFF
+
+HOST_CLANG_CONF_OPTS += -DLLVM_CONFIG:FILEPATH=$(HOST_DIR)/bin/llvm-config
+CLANG_CONF_OPTS += -DLLVM_CONFIG:FILEPATH=$(STAGING_DIR)/usr/bin/llvm-config \
+	-DCLANG_TABLEGEN:FILEPATH=$(HOST_DIR)/usr/bin/clang-tblgen \
+	-DLLVM_TABLEGEN_EXE:FILEPATH=$(HOST_DIR)/usr/bin/llvm-tblgen
+
+# Clang can't be used as compiler on the target since there are no development files
+# (headers) and other build tools. So remove clang binaries from target.
+define CLANG_DELETE_BINARIES_FROM_TARGET
+	rm -f $(TARGET_DIR)/usr/bin/clang*
+endef
+CLANG_POST_INSTALL_TARGET_HOOKS += CLANG_DELETE_BINARIES_FROM_TARGET
+
+# clang-tblgen is not installed by default, however it is necessary for
+# cross-compiling clang
+define HOST_CLANG_INSTALL_CLANG_TBLGEN
+	$(INSTALL) -D -m 0755 $(HOST_CLANG_BUILDDIR)/bin/clang-tblgen \
+		$(HOST_DIR)/usr/bin/clang-tblgen
+endef
+HOST_CLANG_POST_INSTALL_HOOKS = HOST_CLANG_INSTALL_CLANG_TBLGEN
+
+$(eval $(cmake-package))
+$(eval $(host-cmake-package))