linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Clang patch stacks for LTS kernels (v4.4 and v4.9) and status update
@ 2018-04-23 13:56 Sedat Dilek
  2018-04-23 17:42 ` Matthias Kaehlcke
  0 siblings, 1 reply; 22+ messages in thread
From: Sedat Dilek @ 2018-04-23 13:56 UTC (permalink / raw)
  To: Matthias Kaehlcke; +Cc: lkml, Arnd Bergmann, JF Bastien, Nick Desaulniers

[ CC Nick ]
[ CC Arnd ]
[ CC JF ]

Hi Matthias,

I was following [1] a bit and fell over your original posting in [2].

I wrote some early documentation (wiki) and tested/booted a
clang-compiled kernel on x86-64 bare metal.
The project was called "lll-project" these days.
The followup - LLVMlinux project - seems to be somehow dead?

After reading your posting, I got really excited and had a quick look
over the Linux v4.9.y-LTS patch-stack with additional stuff:

$ git fetch https://chromium.googlesource.com/chromiumos/third_party/kernel
refs/sandbox/mka/llvm/v4.9_ext
$ git checkout -b llvm_v4.9_ext FETCH_HEAD

I like your commit subjects and messages.

Before starting to compile I have some questions, I hope you can answer them.

[ CLANG-VERSION ]

Here on Debian/testing (will get Version 10 with codename "buster")
AMD64 I have the choice of installing CLANG v4.0.1, v5.0.1 and v6.0.0.
As you point out LLVM/CLANG v5.0 or higher are a good and faster
choice than v4.0.
Using CLANG >= 5.0 makes the *CLANG* patch-series obsolete?

[ REFRESH PATCH-STACK ]

What about the *FROMGIT* and *CUSTOM* patch-series?
Are they in upstream in the meantime?
If yes, will you refresh this v4.9.y-LTS patch-stack?

[ ASM-GOTO ]

Foremore, I have seen you have a "refs/sandbox/mka/llvm/v4.14" Git branch.
Linux v4.14 is also an LTS release.
After Linux v4.9 "asm-goto" support was added which is GCC specific.
Is there a workaround to compile Linux-kernel with any CLANG version?
You happen to know the status in LLVM upstream?

[ X86-EFLAGS/IF ]

AFAICS, I remember an EFLAGS/IF problem on X86 and interrupt handling.
You happen to know if this is fixed in LLVM upstream?
Some LLVM developers were interested in fixing this.
Can you comment on this, JF (we had some email conversation in private in 2016)?

I am looking forward to hearing from you.

Best regards,
- Sedat -

References:
[1] https://marc.info/?l=linux-kernel&m=152425978517449&w=2
[2] https://marc.info/?l=linux-kernel&m=150344365613264&w=2
[3] https://bugs.llvm.org/show_bug.cgi?id=9295

References from JF:
[0] Hans' fix: http://reviews.llvm.org/D15240
[1] my original pushf/popf disable: http://reviews.llvm.org/D6629
[2] More effort, such as: http://reviews.llvm.org/D15157

P.S.: Your Linux v4.9.y-LTS patch-stack

[ UPSTREAM ]
0001-UPSTREAM-kbuild-Add-better-clang-cross-build-support.patch
0002-UPSTREAM-kbuild-clang-add-no-integrated-as-to-KBUILD.patch
0003-UPSTREAM-kbuild-Consolidate-header-generation-from-A.patch
0004-UPSTREAM-kbuild-consolidate-redundant-sed-script-ASM.patch
0005-UPSTREAM-kbuild-fix-asm-offset-generation-to-work-wi.patch
0006-UPSTREAM-kbuild-drop-Wno-unknown-warning-option-from.patch
0007-UPSTREAM-kbuild-LLVMLinux-Add-Werror-to-cc-option-to.patch
0008-UPSTREAM-kbuild-use-Oz-instead-of-Os-when-using-clan.patch
0009-UPSTREAM-kbuild-Add-support-to-generate-LLVM-assembl.patch
0010-UPSTREAM-modules-mark-__inittest-__exittest-as-__may.patch
0011-UPSTREAM-compiler-clang-suppress-warning-for-unused-.patch
0012-UPSTREAM-compiler-clang-properly-override-inline-for.patch
0013-UPSTREAM-x86-kbuild-Use-cc-option-to-enable-falign-j.patch
0014-UPSTREAM-crypto-x86-aesni-fix-token-pasting-for-clan.patch
0015-UPSTREAM-x86-mm-kaslr-Use-the-_ASM_MUL-macro-for-mul.patch
0016-UPSTREAM-kbuild-Add-__cc-option-macro.patch
0017-UPSTREAM-x86-build-Use-__cc-option-for-boot-code-com.patch
0018-UPSTREAM-x86-build-Specify-stack-alignment-for-clang.patch
0019-UPSTREAM-kbuild-clang-Disable-address-of-packed-memb.patch
0020-UPSTREAM-crypto-arm64-sha-avoid-non-standard-inline-.patch
0021-UPSTREAM-llist-clang-introduce-member_address_is_non.patch
0022-UPSTREAM-x86-boot-undef-memcpy-et-al-in-string.c.patch
0023-UPSTREAM-compiler-clang-always-inline-when-CONFIG_OP.patch
0024-UPSTREAM-efi-libstub-arm64-Use-hidden-attribute-for-.patch
0025-UPSTREAM-efi-libstub-arm64-Force-hidden-visibility-f.patch
0026-UPSTREAM-efi-libstub-arm64-Set-fpie-when-building-th.patch
0027-UPSTREAM-x86-build-Fix-stack-alignment-for-CLang.patch
0028-UPSTREAM-x86-build-Use-cc-option-to-validate-stack-a.patch
0029-UPSTREAM-x86-asm-Fix-inline-asm-call-constraints-for.patch
0030-UPSTREAM-x86-asm-Fix-inline-asm-call-constraints-for.patch
0031-UPSTREAM-Kbuild-use-fshort-wchar-globally.patch
0043-UPSTREAM-arm64-ensure-extension-of-smp_store_release.patch
0044-UPSTREAM-arm64-xchg-hazard-against-entire-exchange-v.patch
0045-UPSTREAM-arm64-uaccess-ensure-extension-of-access_ok.patch
0046-UPSTREAM-arm64-armv8_deprecated-ensure-extension-of-.patch
0047-UPSTREAM-arm64-atomic_lse-match-asm-register-sizes.patch
0048-UPSTREAM-arm64-uaccess-suppress-spurious-clang-warni.patch
0049-UPSTREAM-drm-i915-Remove-unused-BSM_MASK-causing-war.patch
0050-UPSTREAM-audit-add-tty-field-to-LOGIN-event.patch
0051-UPSTREAM-audit-move-audit_get_tty-to-reduce-scope-an.patch
0052-UPSTREAM-media-uvcvideo-Fix-a-wrong-macro.patch
0053-UPSTREAM-dmaengine-Fix-array-index-out-of-bounds-war.patch
0054-UPSTREAM-hpet-Make-cmd-parameter-of-hpet_ioctl_commo.patch
0055-UPSTREAM-ALSA-hda-ca0132-Remove-double-parentheses.patch
0056-UPSTREAM-selinux-Remove-unnecessary-check-of-array-b.patch
0057-UPSTREAM-mac80211-Fix-clang-warning-about-constant-o.patch
0058-UPSTREAM-cpumask-Add-helper-cpumask_available.patch
0059-UPSTREAM-genirq-Use-cpumask_available-for-check-of-c.patch
0060-UPSTREAM-cfg80211-Fix-array-bounds-warning-in-fragme.patch
0061-UPSTREAM-mac80211-ibss-Fix-channel-type-enum-in-ieee.patch
0062-UPSTREAM-nl80211-Fix-enum-type-of-variable-in-nl8021.patch
0063-UPSTREAM-ALSA-hda-ca0132-Limit-values-for-chip-addre.patch
0064-UPSTREAM-media-vcodec-mediatek-Remove-double-parenth.patch
0065-UPSTREAM-misc-lkdtm-Add-volatile-to-intentional-NULL.patch
0066-UPSTREAM-jiffies.h-declare-jiffies-and-jiffies_64-wi.patch
0067-UPSTREAM-fs-compat-Remove-warning-from-COMPATIBLE_IO.patch
0068-UPSTREAM-dm-ioctl-remove-double-parentheses.patch
0069-UPSTREAM-ath9k-Add-cast-to-u8-to-FREQ2FBIN-macro.patch
0070-UPSTREAM-tracing-Use-cpumask_available-to-check-if-c.patch
0071-UPSTREAM-netfilter-ctnetlink-Make-some-parameters-in.patch
0072-UPSTREAM-selinux-Remove-redundant-check-for-unknown-.patch
0076-UPSTREAM-x86-boot-Disable-the-address-of-packed-memb.patch
0077-UPSTREAM-zram-rework-copy-of-compressor-name-in-comp.patch
0078-UPSTREAM-arm64-avoid-overflow-in-VA_START-and-PAGE_O.patch
0079-UPSTREAM-bitops-avoid-integer-overflow-in-GENMASK-_U.patch
0080-UPSTREAM-btrfs-Remove-extra-parentheses-from-conditi.patch
0081-UPSTREAM-netpoll-Fix-device-name-check-in-netpoll_se.patch

[ BACKPORT ]
0032-BACKPORT-kbuild-fix-linker-feature-test-macros-when-.patch
0033-BACKPORT-kbuild-Set-KBUILD_CFLAGS-before-incl.-arch-.patch
0034-BACKPORT-crypto-arm64-aes-ce-cipher-move-assembler-c.patch
0073-BACKPORT-clocksource-Use-GENMASK_ULL-in-definition-o.patch
0074-BACKPORT-PCI-Make-PCI_ROM_ADDRESS_MASK-a-32-bit-cons.patch
0075-BACKPORT-iio-light-isl29018-Only-declare-ACPI-table-.patch
0082-BACKPORT-drm-i915-Consistently-use-enum-pipe-for-PCH.patch
0083-BACKPORT-drm-i915-Pass-enum-pipe-to-intel_set_pch_fi.patch

[ FROMGIT ]
0084-FROMGIT-x86-boot-Disable-Clang-warnings-about-GNU-ex.patch
0085-FROMGIT-sched-sysctl-Fix-attributes-of-some-extern-d.patch

[ CUSTOM ]
0035-CUSTOM-kbuild-clang-Disable-the-duplicate-decl-speci.patch
0036-CUSTOM-arm64-Disable-asm-operand-width-warning-for-c.patch

[ CLANG ]
0037-CLANG4-crypto-arm64-crc32-explictly-pass-mcpu-option.patch
0038-CLANG4-kbuild-Add-meabi-gnu-to-the-clang-parameters.patch
0039-CLANG4-arm64-prefetch-Use-__builtin_arm_prefetch-for.patch
0040-CLANG4-Disable-lkdtm-when-ftrace-is-enabled.patch
0041-CLANG4-futex-don-t-optimize-futex_detect_cmpxchg-on-.patch
0042-CLANG3-core-clang-work-around-x86-regparm-intrinsics.patch
0086-CLANG4-x86-mce-Disable-gcc-compat-warning-for-mce.c-.patch
0087-CLANG4-task_work-Disable-gcc-compat-warning-locally.patch

^ permalink raw reply	[flat|nested] 22+ messages in thread
* Clang patch stacks for LTS kernels (v4.4 and v4.9) and status update
@ 2017-08-22 23:13 Matthias Kaehlcke
  0 siblings, 0 replies; 22+ messages in thread
From: Matthias Kaehlcke @ 2017-08-22 23:13 UTC (permalink / raw)
  To: linux-kernel
  Cc: Arnd Bergmann, Bernhard Rosenkränzer, Khem Raj,
	Behan Webster, Stefan Agner, Douglas Anderson, Guenter Roeck,
	Grant Grundler, Nick Desaulniers, Greg Hackmann,
	Michael Davidson, Alexander Potapenko, Kees Cook

Hi,

Over the past months efforts have been made to upstream the remaining
LLVMLinux patches (http://llvm.linuxfoundation.org) and to address
other outstanding issues in order to build a usable kernel with clang.
To my knowledge upstream is in a relatively good shape by now for x86
and arm64 (I heard the same about PowerPC, but have no first hand
experience), most of the patches are already in Linus' tree, others
have landed in maintainer trees.

Since many projects use an LTS kernel rather than the latest upstream
I thought it could be useful for others to share my upstreamish
patch stacks (derived from my work on Chrome OS) for building v4.4 and
v4.9 with clang:

https://chromium.googlesource.com/chromiumos/third_party/kernel/+log/sandbox/mka/llvm/v4.4
https://chromium.googlesource.com/chromiumos/third_party/kernel/+log/sandbox/mka/llvm/v4.9

These two branches only have the basic patches needed to build an x86
or arm64 kernel with clang, additional fixes for warnings can be found
here:

https://chromium.googlesource.com/chromiumos/third_party/kernel/+log/sandbox/mka/llvm/v4.9_ext

For reference also a stack for v4.13(-rc6):

https://chromium.googlesource.com/chromiumos/third_party/kernel/+log/sandbox/mka/llvm/v4.13

If v4.14 (LTS) misses important patches I will create a stack for it.


To retrieve the patches (v4.9):

git fetch https://chromium.googlesource.com/chromiumos/third_party/kernel refs/sandbox/mka/llvm/v4.9
git checkout -b llvm_v4.9 FETCH_HEAD


To build the kernel with clang:

make CC=clang

or cross compilation:

make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- CC=aarch64-linux-gnu-clang


A short description of the tags used in the patches:

UPSTREAM   From Linus' tree
BACKPORT   From Linus' tree, conflicts had to be resolved
FROMGIT    From a maintainer tree, will eventually propagate to UPSTREAM
FROMLIST   Patch sent to one or more kernel mailing lists, but not
           picked up (yet)
HACK       Workaround for an issue, not upstreamable, proper fix needed
CUSTOM     Similar to HACK, but less hacky, mainly used for older kernels
OBSOLETE   Workaround for issue fixed in upstream clang, not needed
           with recent clang version (more info in the commit message)

The branches are subject to rebasing (e.g. to promote FROMGIT patches
to UPSTREAM, or to incorporate proper fixes for HACKs). If anyone
really needs a static branch for some reason let me know.


Pending issues (incomplete):
- x86: incompatible inline assembly to force generation of stack
  frames. A possible solution is under development:
  https://lkml.org/lkml/2017/7/28/775
- x86: maintainers raised concerns that clang does not support asm goto,
  LLVM devs do not plan to implement it.
- arm64: inconsistent behavior of -mgeneral-regs-only
  (https://llvm.org/bugs/show_bug.cgi?id=30792). A fix is being worked on.
- build errors in different drivers. Arnd Bergmann put together a
  bunch of patches that can serve as starting point for upstream fixes:
  https://git.kernel.org/pub/scm/linux/kernel/git/arnd/playground.git/log/?h=next-20170420%2bllvmlinux
- warnings: clang raises more warnings than gcc. Most warnings for x86
  and arm64 defconfig have been fixed, others still need to be addressed.
- ...

Thanks to everybody who contributed/s to this effort!

Matthias

^ permalink raw reply	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2018-05-22 14:55 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-23 13:56 Clang patch stacks for LTS kernels (v4.4 and v4.9) and status update Sedat Dilek
2018-04-23 17:42 ` Matthias Kaehlcke
2018-04-24 11:54   ` Sedat Dilek
2018-04-24 23:06     ` Matthias Kaehlcke
2018-05-06  7:42       ` Sedat Dilek
2018-05-06  8:16         ` Sedat Dilek
2018-05-07 17:49         ` Matthias Kaehlcke
2018-05-07 19:37           ` Sedat Dilek
2018-05-11 11:52           ` Sedat Dilek
2018-05-18 22:54             ` Nick Desaulniers
2018-05-22  7:11               ` Sedat Dilek
2018-05-22  7:39               ` Sedat Dilek
2018-05-22  8:04                 ` Sedat Dilek
2018-05-22  8:49                   ` Sedat Dilek
2018-05-22 10:16                     ` Sedat Dilek
2018-05-22 12:05                       ` Sedat Dilek
2018-05-22 12:17                         ` Sedat Dilek
2018-05-22 14:55                           ` Sedat Dilek
2018-05-06  6:35   ` Sedat Dilek
2018-05-06  7:41     ` Dmitry Vyukov
2018-05-06  7:58       ` Sedat Dilek
  -- strict thread matches above, loose matches on Subject: below --
2017-08-22 23:13 Matthias Kaehlcke

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).