├── patches ├── llvm-6 ├── llvm-7 ├── llvm-all │ ├── linux │ │ └── arm64 │ │ │ └── silence-dwarf2-warnings.patch │ └── linux-next │ │ └── arm64 │ │ └── silence-dwarf2-warnings.patch ├── llvm-12 │ ├── 4.4 │ │ └── x86_64 │ │ │ └── 0001-x86-boot-compressed-Disable-relocation-relaxation.patch │ ├── 4.9 │ │ └── x86_64 │ │ │ └── 0001-x86-boot-compressed-Disable-relocation-relaxation.patch │ ├── 4.14 │ │ └── x86_64 │ │ │ └── 0001-x86-boot-compressed-Disable-relocation-relaxation.patch │ ├── android-4.9-q │ │ └── x86_64 │ │ │ └── 0001-x86-boot-compressed-Disable-relocation-relaxation.patch │ └── android-4.14-stable │ │ └── x86_64 │ │ └── 0001-x86-boot-compressed-Disable-relocation-relaxation.patch └── llvm-8 │ └── linux │ └── x86_64 │ └── x86-series.patch ├── .github ├── CODEOWNERS └── workflows │ └── main.yml ├── .gitignore ├── configs ├── tt.config └── common.config ├── README.md ├── env-setup.sh ├── usage.txt ├── .travis.yml ├── LICENSE └── driver.sh /patches/llvm-6: -------------------------------------------------------------------------------- 1 | llvm-8 -------------------------------------------------------------------------------- /patches/llvm-7: -------------------------------------------------------------------------------- 1 | llvm-8 -------------------------------------------------------------------------------- /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @msfjarvis @nathanchance @nickdesaulniers 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.swp 2 | *.tar.gz 3 | .ccache 4 | /boot-utils/ 5 | /common/ 6 | /linux/ 7 | /linux-next/ 8 | -------------------------------------------------------------------------------- /configs/tt.config: -------------------------------------------------------------------------------- 1 | # https://github.com/groeck/linux-build-test/blob/master/rootfs/x86_64/run-qemu-x86_64.sh#L43-L45 2 | CONFIG_LOCK_TORTURE_TEST=y 3 | CONFIG_RCU_TORTURE_TEST=y 4 | -------------------------------------------------------------------------------- /patches/llvm-all/linux/arm64/silence-dwarf2-warnings.patch: -------------------------------------------------------------------------------- 1 | diff --git a/Makefile b/Makefile 2 | index 37739ee53f27..bc69153041ec 100644 3 | --- a/Makefile 4 | +++ b/Makefile 5 | @@ -826,7 +826,9 @@ else 6 | DEBUG_CFLAGS += -g 7 | endif 8 | 9 | +ifneq ($(LLVM_IAS),1) 10 | KBUILD_AFLAGS += -Wa,-gdwarf-2 11 | +endif 12 | 13 | ifdef CONFIG_DEBUG_INFO_DWARF4 14 | DEBUG_CFLAGS += -gdwarf-4 15 | -------------------------------------------------------------------------------- /patches/llvm-all/linux-next/arm64/silence-dwarf2-warnings.patch: -------------------------------------------------------------------------------- 1 | diff --git a/Makefile b/Makefile 2 | index 37739ee53f27..bc69153041ec 100644 3 | --- a/Makefile 4 | +++ b/Makefile 5 | @@ -826,7 +826,9 @@ else 6 | DEBUG_CFLAGS += -g 7 | endif 8 | 9 | +ifneq ($(LLVM_IAS),1) 10 | KBUILD_AFLAGS += -Wa,-gdwarf-2 11 | +endif 12 | 13 | ifdef CONFIG_DEBUG_INFO_DWARF4 14 | DEBUG_CFLAGS += -gdwarf-4 15 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # continuous-integration 2 | 3 | A repo for daily continuous compilation and boot testing of Clang built Linux. 4 | Uses [daily snapshots](https://apt.llvm.org/) of 5 | [Clang](https://clang.llvm.org/), top of tree 6 | [torvalds/linux](torvalds/linux.git), [Buildroot](https://buildroot.org/) root 7 | filesystems, and [QEMU](https://www.qemu.org/) to boot. 8 | 9 | [![Build Status](https://travis-ci.com/ClangBuiltLinux/continuous-integration.svg?branch=master)](https://travis-ci.com/ClangBuiltLinux/continuous-integration) 10 | 11 | ```sh 12 | $ git clone git@github.com:ClangBuiltLinux/continuous-integration.git 13 | $ cd continuous-integration 14 | $ ./driver.sh 15 | ``` 16 | See also [usage](/usage.txt). 17 | -------------------------------------------------------------------------------- /env-setup.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Configure our Docker container during Travis builds 3 | 4 | # Show all commands and exit upon failure 5 | set -eux 6 | 7 | # By default, Travis's ccache size is around 500MB. We'll 8 | # start with 2GB just to see how it plays out. 9 | ccache -M 2G 10 | 11 | # Enable compression so that we can have more objects in 12 | # the cache (9 is most compressed, 6 is default) 13 | ccache --set-config=compression=true 14 | ccache --set-config=compression_level=9 15 | 16 | # Set the cache directory to /travis/.ccache, which we've 17 | # bind mounted during 'docker create' so that we can keep 18 | # this cached across builds 19 | ccache --set-config=cache_dir=/travis/.ccache 20 | 21 | # Clear out the stats so we actually know the cache stats 22 | ccache -z 23 | -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | # Run shellcheck and shfmt on all shell files in this repository 2 | name: shell-scripts-codestyle-check 3 | on: [push, pull_request] 4 | jobs: 5 | shellcheck: 6 | runs-on: ubuntu-latest 7 | steps: 8 | - uses: actions/checkout@v2 9 | - name: shellcheck 10 | uses: bewuethr/shellcheck-action@v1 11 | shfmt-check: 12 | runs-on: ubuntu-latest 13 | steps: 14 | - uses: actions/checkout@v2 15 | - uses: actions/setup-go@v2 16 | with: 17 | go-version: '1.14.2' 18 | - uses: actions/cache@v1 19 | with: 20 | path: ~/go/pkg/mod 21 | key: ${{ runner.os }}-go 22 | restore-keys: | 23 | ${{ runner.os }}-go- 24 | - name: Run shfmt 25 | run: | 26 | GO111MODULE=on go get mvdan.cc/sh/v3/cmd/shfmt 27 | while read -r f; do 28 | PATH=$HOME/go/bin:$PATH shfmt -ci -d -i 4 $f 29 | done < <(find . -type f -name "*.sh") 30 | -------------------------------------------------------------------------------- /configs/common.config: -------------------------------------------------------------------------------- 1 | # From https://github.com/groeck/linux-build-test/blob/master/rootfs/scripts/common.sh 2 | CONFIG_EXPERT=y 3 | CONFIG_DEBUG_KERNEL=y 4 | CONFIG_LOCK_DEBUGGING_SUPPORT=y 5 | CONFIG_DEBUG_RT_MUTEXES=y 6 | CONFIG_DEBUG_SPINLOCK=y 7 | CONFIG_DEBUG_MUTEXES=y 8 | CONFIG_DEBUG_WW_MUTEX_SLOWPATH=y 9 | CONFIG_DEBUG_LOCK_ALLOC=y 10 | CONFIG_DEBUG_LOCKDEP=y 11 | CONFIG_DEBUG_ATOMIC_SLEEP=y 12 | CONFIG_CRYPTO_MANAGER_DISABLE_TESTS=y 13 | CONFIG_CRC32_SELFTEST=y 14 | CONFIG_DEBUG_LOCKING_API_SELFTESTS=y 15 | CONFIG_DEBUG_NMI_SELFTEST=y 16 | CONFIG_DEBUG_RODATA_TEST=y 17 | CONFIG_DEBUG_TLBFLUSH=y 18 | CONFIG_DMATEST=y 19 | CONFIG_GLOB_SELFTEST=y 20 | CONFIG_PCI_EPF_TEST=y 21 | CONFIG_PCI_ENDPOINT_TEST=y 22 | CONFIG_PROVE_LOCKING=y 23 | CONFIG_PROVE_RCU=y 24 | CONFIG_RBTREE_TEST=y 25 | CONFIG_RCU_EQS_DEBUG=y 26 | CONFIG_STATIC_KEYS_SELFTEST=y 27 | CONFIG_STRING_SELFTEST=y 28 | CONFIG_TEST_BITMAP=y 29 | CONFIG_TEST_FIRMWARE=y 30 | CONFIG_TEST_SORT=y 31 | CONFIG_TEST_SYSCTL=y 32 | CONFIG_TEST_UUID=y 33 | CONFIG_TORTURE_TEST=y 34 | CONFIG_USB_TEST=y 35 | CONFIG_USB_EHSET_TEST_FIXTURE=y 36 | CONFIG_USB_LINK_LAYER_TEST=y 37 | CONFIG_WW_MUTEX_SELFTEST=y 38 | CONFIG_BLK_DEV_INITRD=y 39 | CONFIG_DEVTMPFS=y 40 | CONFIG_DEVTMPFS_MOUNT=y 41 | CONFIG_SCSI=y 42 | CONFIG_BLK_DEV_SD=y 43 | CONFIG_SCSI_LOWLEVEL=y 44 | CONFIG_SCSI_DC395x=y 45 | CONFIG_SCSI_AM53C974=y 46 | CONFIG_SCSI_SYM53C8XX_2=y 47 | CONFIG_MEGARAID_SAS=y 48 | CONFIG_FUSION=y 49 | CONFIG_FUSION_SAS=y 50 | CONFIG_MMC=y 51 | CONFIG_MMC_SDHCI=y 52 | CONFIG_MMC_SDHCI_PCI=y 53 | CONFIG_BLK_DEV_NVME=y 54 | CONFIG_USB=y 55 | CONFIG_USB_XHCI_HCD=y 56 | CONFIG_USB_EHCI_HCD=y 57 | CONFIG_USB_OHCI_HCD=y 58 | CONFIG_USB_STORAGE=y 59 | CONFIG_USB_UAS=y 60 | CONFIG_VIRTIO=y 61 | CONFIG_VIRTIO_PCI=y 62 | CONFIG_VIRTIO_PCI_LEGACY=y 63 | CONFIG_VIRTIO_BALLOON=y 64 | CONFIG_VIRTIO_MMIO=y 65 | CONFIG_BLK_MQ_VIRTIO=y 66 | CONFIG_VIRTIO_BLK=y 67 | CONFIG_VIRTIO_BLK_SCSI=y 68 | CONFIG_SCSI_VIRTIO=y 69 | -------------------------------------------------------------------------------- /usage.txt: -------------------------------------------------------------------------------- 1 | Usage: ./driver.sh 2 | 3 | Script description: Build a Linux kernel image with Clang and boot it 4 | 5 | Environment variables: 6 | The script can take into account specific environment variables, mostly used 7 | with Travis. They can be invoked in one of three ways: 8 | $ export VAR= && ./driver.sh 9 | $ VAR=value ./driver.sh 10 | $ ./driver.sh VAR=value 11 | 12 | AR: 13 | If no AR value is specified, the script will attempt to set AR to llvm-ar 14 | and fallback to ${CROSS_COMPILE}ar if it is not found in PATH. 15 | ARCH (required): 16 | If no ARCH value is specified, it's an error; there is no default. 17 | Currently, arm32_v7, arm32_v6, arm32_v5, arm64, mips, mipsel, ppc32, 18 | ppc64, ppc64le, s390, riscv, x86, and x86_64 are supported. 19 | CC: 20 | If no CC value is specified, clang is used. 21 | LD: 22 | If no LD value is specified, ${CROSS_COMPILE}ld is used. 23 | LLVM: 24 | If this is set to 1, all LLVM utilities are used, except for the 25 | integrated assembler. Use LLVM_IAS=1 to enable that. 26 | LLVM_IAS: 27 | If this is set to 1, the integrated assembler is used. No value means 28 | ${CROSS_COMPILE}as is used for assembling. 29 | NM: 30 | If no NM value is specified, the script will attempt to set NM to llvm-nm 31 | and fallback to ${CROSS_COMPILE}nm if it is not found in PATH. 32 | OBJCOPY: 33 | If no OBJCOPY value is specified, the script will attempt to set OBJCOPY 34 | to llvm-objcopy and fallback to ${CROSS_COMPILE}objcopy if it is not found 35 | in PATH. 36 | OBJDUMP: 37 | If no OBJDUMP value is specified, the script will attempt to set OBJDUMP 38 | to llvm-objdump and fallback to ${CROSS_COMPILE}objdump if it is not found 39 | in PATH. 40 | OBJSIZE: 41 | If no OBJSIZE value is specified, the script will attempt to set OBJSIZE 42 | to llvm-size and fallback to ${CROSS_COMPILE}size if it is not found in 43 | PATH. 44 | REPO: 45 | Nicknames for trees: 46 | linux (default) 47 | linux-next 48 | 5.4 49 | 4.19 50 | 4.14 51 | 4.9 52 | 4.4 53 | android-mainline 54 | android-5.4 55 | android-4.19 56 | android-4.14-stable 57 | android-4.9-q 58 | STRIP: 59 | If no STRIP value is specified, the script will attempt to set STRIP to 60 | llvm-strip and fallback to ${CROSS_COMPILE}strip if it is not found in 61 | PATH. 62 | 63 | Optional parameters: 64 | -c | --clean: 65 | Run 'make mrproper' before building the kernel. Normally, the build 66 | system is smart enought to figure out what needs to be rebuilt but 67 | sometimes it might be necessary to clean it manually. 68 | -j | --jobs 69 | Pass this value to make. The script will use all cores by default but 70 | this isn't always the best value. 71 | --lto 72 | By default, the script turns off LTO/CFI for quicker build times. If 73 | your machine can handle the more intensive compile, pass this flag 74 | to avoid attempting to disable it. This does not enable LTO explicitly. 75 | -------------------------------------------------------------------------------- /patches/llvm-12/4.4/x86_64/0001-x86-boot-compressed-Disable-relocation-relaxation.patch: -------------------------------------------------------------------------------- 1 | From c01391e3075ab922a696873e497ac6b7e0c8b8c4 Mon Sep 17 00:00:00 2001 2 | From: Arvind Sankar 3 | Date: Tue, 11 Aug 2020 20:43:08 -0400 4 | Subject: [PATCH] x86/boot/compressed: Disable relocation relaxation 5 | 6 | The x86-64 psABI [0] specifies special relocation types 7 | (R_X86_64_[REX_]GOTPCRELX) for indirection through the Global Offset 8 | Table, semantically equivalent to R_X86_64_GOTPCREL, which the linker 9 | can take advantage of for optimization (relaxation) at link time. This 10 | is supported by LLD and binutils versions 2.26 onwards. 11 | 12 | The compressed kernel is position-independent code, however, when using 13 | LLD or binutils versions before 2.27, it must be linked without the -pie 14 | option. In this case, the linker may optimize certain instructions into 15 | a non-position-independent form, by converting foo@GOTPCREL(%rip) to $foo. 16 | 17 | This potential issue has been present with LLD and binutils-2.26 for a 18 | long time, but it has never manifested itself before now: 19 | - LLD and binutils-2.26 only relax 20 | movq foo@GOTPCREL(%rip), %reg 21 | to 22 | leaq foo(%rip), %reg 23 | which is still position-independent, rather than 24 | mov $foo, %reg 25 | which is permitted by the psABI when -pie is not enabled. 26 | - gcc happens to only generate GOTPCREL relocations on mov instructions. 27 | - clang does generate GOTPCREL relocations on non-mov instructions, but 28 | when building the compressed kernel, it uses its integrated assembler 29 | (due to the redefinition of KBUILD_CFLAGS dropping -no-integrated-as), 30 | which has so far defaulted to not generating the GOTPCRELX 31 | relocations. 32 | 33 | Nick Desaulniers reports [1,2]: 34 | A recent change [3] to a default value of configuration variable 35 | (ENABLE_X86_RELAX_RELOCATIONS OFF -> ON) in LLVM now causes Clang's 36 | integrated assembler to emit R_X86_64_GOTPCRELX/R_X86_64_REX_GOTPCRELX 37 | relocations. LLD will relax instructions with these relocations based 38 | on whether the image is being linked as position independent or not. 39 | When not, then LLD will relax these instructions to use absolute 40 | addressing mode (R_RELAX_GOT_PC_NOPIC). This causes kernels built with 41 | Clang and linked with LLD to fail to boot. 42 | 43 | Patch series [4] is a solution to allow the compressed kernel to be 44 | linked with -pie unconditionally, but even if merged is unlikely to be 45 | backported. As a simple solution that can be applied to stable as well, 46 | prevent the assembler from generating the relaxed relocation types using 47 | the -mrelax-relocations=no option. For ease of backporting, do this 48 | unconditionally. 49 | 50 | [0] https://gitlab.com/x86-psABIs/x86-64-ABI/-/blob/master/x86-64-ABI/linker-optimization.tex#L65 51 | [1] https://lore.kernel.org/lkml/20200807194100.3570838-1-ndesaulniers@google.com/ 52 | [2] https://github.com/ClangBuiltLinux/linux/issues/1121 53 | [3] https://reviews.llvm.org/rGc41a18cf61790fc898dcda1055c3efbf442c14c0 54 | [4] https://lore.kernel.org/lkml/20200731202738.2577854-1-nivedita@alum.mit.edu/ 55 | 56 | Reported-by: Nick Desaulniers 57 | Signed-off-by: Arvind Sankar 58 | Tested-by: Nick Desaulniers 59 | Tested-by: Sedat Dilek 60 | Reviewed-by: Nick Desaulniers 61 | Cc: stable@vger.kernel.org 62 | Link: https://lore.kernel.org/r/20200812004308.1448603-1-nivedita@alum.mit.edu 63 | Signed-off-by: Nathan Chancellor 64 | --- 65 | arch/x86/boot/compressed/Makefile | 2 ++ 66 | 1 file changed, 2 insertions(+) 67 | 68 | diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile 69 | index bf0c7b6b00c3..01eafd8aeec6 100644 70 | --- a/arch/x86/boot/compressed/Makefile 71 | +++ b/arch/x86/boot/compressed/Makefile 72 | @@ -31,6 +31,8 @@ KBUILD_CFLAGS += -mno-mmx -mno-sse 73 | KBUILD_CFLAGS += $(call cc-option,-ffreestanding) 74 | KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector) 75 | KBUILD_CFLAGS += $(call cc-disable-warning, address-of-packed-member) 76 | +# Disable relocation relaxation in case the link is not PIE. 77 | +KBUILD_CFLAGS += $(call as-option,-Wa$(comma)-mrelax-relocations=no) 78 | 79 | KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__ 80 | GCOV_PROFILE := n 81 | -- 82 | 2.28.0 83 | 84 | -------------------------------------------------------------------------------- /patches/llvm-12/4.9/x86_64/0001-x86-boot-compressed-Disable-relocation-relaxation.patch: -------------------------------------------------------------------------------- 1 | From 6b0be2f13de88ba4b982cfe6103cb98271c696e4 Mon Sep 17 00:00:00 2001 2 | From: Arvind Sankar 3 | Date: Tue, 11 Aug 2020 20:43:08 -0400 4 | Subject: [PATCH] x86/boot/compressed: Disable relocation relaxation 5 | 6 | The x86-64 psABI [0] specifies special relocation types 7 | (R_X86_64_[REX_]GOTPCRELX) for indirection through the Global Offset 8 | Table, semantically equivalent to R_X86_64_GOTPCREL, which the linker 9 | can take advantage of for optimization (relaxation) at link time. This 10 | is supported by LLD and binutils versions 2.26 onwards. 11 | 12 | The compressed kernel is position-independent code, however, when using 13 | LLD or binutils versions before 2.27, it must be linked without the -pie 14 | option. In this case, the linker may optimize certain instructions into 15 | a non-position-independent form, by converting foo@GOTPCREL(%rip) to $foo. 16 | 17 | This potential issue has been present with LLD and binutils-2.26 for a 18 | long time, but it has never manifested itself before now: 19 | - LLD and binutils-2.26 only relax 20 | movq foo@GOTPCREL(%rip), %reg 21 | to 22 | leaq foo(%rip), %reg 23 | which is still position-independent, rather than 24 | mov $foo, %reg 25 | which is permitted by the psABI when -pie is not enabled. 26 | - gcc happens to only generate GOTPCREL relocations on mov instructions. 27 | - clang does generate GOTPCREL relocations on non-mov instructions, but 28 | when building the compressed kernel, it uses its integrated assembler 29 | (due to the redefinition of KBUILD_CFLAGS dropping -no-integrated-as), 30 | which has so far defaulted to not generating the GOTPCRELX 31 | relocations. 32 | 33 | Nick Desaulniers reports [1,2]: 34 | A recent change [3] to a default value of configuration variable 35 | (ENABLE_X86_RELAX_RELOCATIONS OFF -> ON) in LLVM now causes Clang's 36 | integrated assembler to emit R_X86_64_GOTPCRELX/R_X86_64_REX_GOTPCRELX 37 | relocations. LLD will relax instructions with these relocations based 38 | on whether the image is being linked as position independent or not. 39 | When not, then LLD will relax these instructions to use absolute 40 | addressing mode (R_RELAX_GOT_PC_NOPIC). This causes kernels built with 41 | Clang and linked with LLD to fail to boot. 42 | 43 | Patch series [4] is a solution to allow the compressed kernel to be 44 | linked with -pie unconditionally, but even if merged is unlikely to be 45 | backported. As a simple solution that can be applied to stable as well, 46 | prevent the assembler from generating the relaxed relocation types using 47 | the -mrelax-relocations=no option. For ease of backporting, do this 48 | unconditionally. 49 | 50 | [0] https://gitlab.com/x86-psABIs/x86-64-ABI/-/blob/master/x86-64-ABI/linker-optimization.tex#L65 51 | [1] https://lore.kernel.org/lkml/20200807194100.3570838-1-ndesaulniers@google.com/ 52 | [2] https://github.com/ClangBuiltLinux/linux/issues/1121 53 | [3] https://reviews.llvm.org/rGc41a18cf61790fc898dcda1055c3efbf442c14c0 54 | [4] https://lore.kernel.org/lkml/20200731202738.2577854-1-nivedita@alum.mit.edu/ 55 | 56 | Reported-by: Nick Desaulniers 57 | Signed-off-by: Arvind Sankar 58 | Tested-by: Nick Desaulniers 59 | Tested-by: Sedat Dilek 60 | Reviewed-by: Nick Desaulniers 61 | Cc: stable@vger.kernel.org 62 | Link: https://lore.kernel.org/r/20200812004308.1448603-1-nivedita@alum.mit.edu 63 | Signed-off-by: Nathan Chancellor 64 | --- 65 | arch/x86/boot/compressed/Makefile | 2 ++ 66 | 1 file changed, 2 insertions(+) 67 | 68 | diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile 69 | index 89b163351e64..7be7acd6a540 100644 70 | --- a/arch/x86/boot/compressed/Makefile 71 | +++ b/arch/x86/boot/compressed/Makefile 72 | @@ -35,6 +35,8 @@ KBUILD_CFLAGS += -mno-mmx -mno-sse 73 | KBUILD_CFLAGS += $(call cc-option,-ffreestanding) 74 | KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector) 75 | KBUILD_CFLAGS += $(call cc-disable-warning, address-of-packed-member) 76 | +# Disable relocation relaxation in case the link is not PIE. 77 | +KBUILD_CFLAGS += $(call as-option,-Wa$(comma)-mrelax-relocations=no) 78 | 79 | KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__ 80 | GCOV_PROFILE := n 81 | -- 82 | 2.28.0 83 | 84 | -------------------------------------------------------------------------------- /patches/llvm-12/4.14/x86_64/0001-x86-boot-compressed-Disable-relocation-relaxation.patch: -------------------------------------------------------------------------------- 1 | From 60f03a69a210f25cbedce250c606001e140d32a9 Mon Sep 17 00:00:00 2001 2 | From: Arvind Sankar 3 | Date: Tue, 11 Aug 2020 20:43:08 -0400 4 | Subject: [PATCH] x86/boot/compressed: Disable relocation relaxation 5 | 6 | The x86-64 psABI [0] specifies special relocation types 7 | (R_X86_64_[REX_]GOTPCRELX) for indirection through the Global Offset 8 | Table, semantically equivalent to R_X86_64_GOTPCREL, which the linker 9 | can take advantage of for optimization (relaxation) at link time. This 10 | is supported by LLD and binutils versions 2.26 onwards. 11 | 12 | The compressed kernel is position-independent code, however, when using 13 | LLD or binutils versions before 2.27, it must be linked without the -pie 14 | option. In this case, the linker may optimize certain instructions into 15 | a non-position-independent form, by converting foo@GOTPCREL(%rip) to $foo. 16 | 17 | This potential issue has been present with LLD and binutils-2.26 for a 18 | long time, but it has never manifested itself before now: 19 | - LLD and binutils-2.26 only relax 20 | movq foo@GOTPCREL(%rip), %reg 21 | to 22 | leaq foo(%rip), %reg 23 | which is still position-independent, rather than 24 | mov $foo, %reg 25 | which is permitted by the psABI when -pie is not enabled. 26 | - gcc happens to only generate GOTPCREL relocations on mov instructions. 27 | - clang does generate GOTPCREL relocations on non-mov instructions, but 28 | when building the compressed kernel, it uses its integrated assembler 29 | (due to the redefinition of KBUILD_CFLAGS dropping -no-integrated-as), 30 | which has so far defaulted to not generating the GOTPCRELX 31 | relocations. 32 | 33 | Nick Desaulniers reports [1,2]: 34 | A recent change [3] to a default value of configuration variable 35 | (ENABLE_X86_RELAX_RELOCATIONS OFF -> ON) in LLVM now causes Clang's 36 | integrated assembler to emit R_X86_64_GOTPCRELX/R_X86_64_REX_GOTPCRELX 37 | relocations. LLD will relax instructions with these relocations based 38 | on whether the image is being linked as position independent or not. 39 | When not, then LLD will relax these instructions to use absolute 40 | addressing mode (R_RELAX_GOT_PC_NOPIC). This causes kernels built with 41 | Clang and linked with LLD to fail to boot. 42 | 43 | Patch series [4] is a solution to allow the compressed kernel to be 44 | linked with -pie unconditionally, but even if merged is unlikely to be 45 | backported. As a simple solution that can be applied to stable as well, 46 | prevent the assembler from generating the relaxed relocation types using 47 | the -mrelax-relocations=no option. For ease of backporting, do this 48 | unconditionally. 49 | 50 | [0] https://gitlab.com/x86-psABIs/x86-64-ABI/-/blob/master/x86-64-ABI/linker-optimization.tex#L65 51 | [1] https://lore.kernel.org/lkml/20200807194100.3570838-1-ndesaulniers@google.com/ 52 | [2] https://github.com/ClangBuiltLinux/linux/issues/1121 53 | [3] https://reviews.llvm.org/rGc41a18cf61790fc898dcda1055c3efbf442c14c0 54 | [4] https://lore.kernel.org/lkml/20200731202738.2577854-1-nivedita@alum.mit.edu/ 55 | 56 | Reported-by: Nick Desaulniers 57 | Signed-off-by: Arvind Sankar 58 | Tested-by: Nick Desaulniers 59 | Tested-by: Sedat Dilek 60 | Reviewed-by: Nick Desaulniers 61 | Cc: stable@vger.kernel.org 62 | Link: https://lore.kernel.org/r/20200812004308.1448603-1-nivedita@alum.mit.edu 63 | Signed-off-by: Nathan Chancellor 64 | --- 65 | arch/x86/boot/compressed/Makefile | 2 ++ 66 | 1 file changed, 2 insertions(+) 67 | 68 | diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile 69 | index 3a250ca2406c..644f9e14cb09 100644 70 | --- a/arch/x86/boot/compressed/Makefile 71 | +++ b/arch/x86/boot/compressed/Makefile 72 | @@ -36,6 +36,8 @@ KBUILD_CFLAGS += -mno-mmx -mno-sse 73 | KBUILD_CFLAGS += $(call cc-option,-ffreestanding) 74 | KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector) 75 | KBUILD_CFLAGS += $(call cc-disable-warning, address-of-packed-member) 76 | +# Disable relocation relaxation in case the link is not PIE. 77 | +KBUILD_CFLAGS += $(call as-option,-Wa$(comma)-mrelax-relocations=no) 78 | 79 | KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__ 80 | GCOV_PROFILE := n 81 | -- 82 | 2.28.0 83 | 84 | -------------------------------------------------------------------------------- /patches/llvm-12/android-4.9-q/x86_64/0001-x86-boot-compressed-Disable-relocation-relaxation.patch: -------------------------------------------------------------------------------- 1 | From 6b0be2f13de88ba4b982cfe6103cb98271c696e4 Mon Sep 17 00:00:00 2001 2 | From: Arvind Sankar 3 | Date: Tue, 11 Aug 2020 20:43:08 -0400 4 | Subject: [PATCH] x86/boot/compressed: Disable relocation relaxation 5 | 6 | The x86-64 psABI [0] specifies special relocation types 7 | (R_X86_64_[REX_]GOTPCRELX) for indirection through the Global Offset 8 | Table, semantically equivalent to R_X86_64_GOTPCREL, which the linker 9 | can take advantage of for optimization (relaxation) at link time. This 10 | is supported by LLD and binutils versions 2.26 onwards. 11 | 12 | The compressed kernel is position-independent code, however, when using 13 | LLD or binutils versions before 2.27, it must be linked without the -pie 14 | option. In this case, the linker may optimize certain instructions into 15 | a non-position-independent form, by converting foo@GOTPCREL(%rip) to $foo. 16 | 17 | This potential issue has been present with LLD and binutils-2.26 for a 18 | long time, but it has never manifested itself before now: 19 | - LLD and binutils-2.26 only relax 20 | movq foo@GOTPCREL(%rip), %reg 21 | to 22 | leaq foo(%rip), %reg 23 | which is still position-independent, rather than 24 | mov $foo, %reg 25 | which is permitted by the psABI when -pie is not enabled. 26 | - gcc happens to only generate GOTPCREL relocations on mov instructions. 27 | - clang does generate GOTPCREL relocations on non-mov instructions, but 28 | when building the compressed kernel, it uses its integrated assembler 29 | (due to the redefinition of KBUILD_CFLAGS dropping -no-integrated-as), 30 | which has so far defaulted to not generating the GOTPCRELX 31 | relocations. 32 | 33 | Nick Desaulniers reports [1,2]: 34 | A recent change [3] to a default value of configuration variable 35 | (ENABLE_X86_RELAX_RELOCATIONS OFF -> ON) in LLVM now causes Clang's 36 | integrated assembler to emit R_X86_64_GOTPCRELX/R_X86_64_REX_GOTPCRELX 37 | relocations. LLD will relax instructions with these relocations based 38 | on whether the image is being linked as position independent or not. 39 | When not, then LLD will relax these instructions to use absolute 40 | addressing mode (R_RELAX_GOT_PC_NOPIC). This causes kernels built with 41 | Clang and linked with LLD to fail to boot. 42 | 43 | Patch series [4] is a solution to allow the compressed kernel to be 44 | linked with -pie unconditionally, but even if merged is unlikely to be 45 | backported. As a simple solution that can be applied to stable as well, 46 | prevent the assembler from generating the relaxed relocation types using 47 | the -mrelax-relocations=no option. For ease of backporting, do this 48 | unconditionally. 49 | 50 | [0] https://gitlab.com/x86-psABIs/x86-64-ABI/-/blob/master/x86-64-ABI/linker-optimization.tex#L65 51 | [1] https://lore.kernel.org/lkml/20200807194100.3570838-1-ndesaulniers@google.com/ 52 | [2] https://github.com/ClangBuiltLinux/linux/issues/1121 53 | [3] https://reviews.llvm.org/rGc41a18cf61790fc898dcda1055c3efbf442c14c0 54 | [4] https://lore.kernel.org/lkml/20200731202738.2577854-1-nivedita@alum.mit.edu/ 55 | 56 | Reported-by: Nick Desaulniers 57 | Signed-off-by: Arvind Sankar 58 | Tested-by: Nick Desaulniers 59 | Tested-by: Sedat Dilek 60 | Reviewed-by: Nick Desaulniers 61 | Cc: stable@vger.kernel.org 62 | Link: https://lore.kernel.org/r/20200812004308.1448603-1-nivedita@alum.mit.edu 63 | Signed-off-by: Nathan Chancellor 64 | --- 65 | arch/x86/boot/compressed/Makefile | 2 ++ 66 | 1 file changed, 2 insertions(+) 67 | 68 | diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile 69 | index 89b163351e64..7be7acd6a540 100644 70 | --- a/arch/x86/boot/compressed/Makefile 71 | +++ b/arch/x86/boot/compressed/Makefile 72 | @@ -35,6 +35,8 @@ KBUILD_CFLAGS += -mno-mmx -mno-sse 73 | KBUILD_CFLAGS += $(call cc-option,-ffreestanding) 74 | KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector) 75 | KBUILD_CFLAGS += $(call cc-disable-warning, address-of-packed-member) 76 | +# Disable relocation relaxation in case the link is not PIE. 77 | +KBUILD_CFLAGS += $(call as-option,-Wa$(comma)-mrelax-relocations=no) 78 | 79 | KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__ 80 | GCOV_PROFILE := n 81 | -- 82 | 2.28.0 83 | 84 | -------------------------------------------------------------------------------- /patches/llvm-12/android-4.14-stable/x86_64/0001-x86-boot-compressed-Disable-relocation-relaxation.patch: -------------------------------------------------------------------------------- 1 | From 60f03a69a210f25cbedce250c606001e140d32a9 Mon Sep 17 00:00:00 2001 2 | From: Arvind Sankar 3 | Date: Tue, 11 Aug 2020 20:43:08 -0400 4 | Subject: [PATCH] x86/boot/compressed: Disable relocation relaxation 5 | 6 | The x86-64 psABI [0] specifies special relocation types 7 | (R_X86_64_[REX_]GOTPCRELX) for indirection through the Global Offset 8 | Table, semantically equivalent to R_X86_64_GOTPCREL, which the linker 9 | can take advantage of for optimization (relaxation) at link time. This 10 | is supported by LLD and binutils versions 2.26 onwards. 11 | 12 | The compressed kernel is position-independent code, however, when using 13 | LLD or binutils versions before 2.27, it must be linked without the -pie 14 | option. In this case, the linker may optimize certain instructions into 15 | a non-position-independent form, by converting foo@GOTPCREL(%rip) to $foo. 16 | 17 | This potential issue has been present with LLD and binutils-2.26 for a 18 | long time, but it has never manifested itself before now: 19 | - LLD and binutils-2.26 only relax 20 | movq foo@GOTPCREL(%rip), %reg 21 | to 22 | leaq foo(%rip), %reg 23 | which is still position-independent, rather than 24 | mov $foo, %reg 25 | which is permitted by the psABI when -pie is not enabled. 26 | - gcc happens to only generate GOTPCREL relocations on mov instructions. 27 | - clang does generate GOTPCREL relocations on non-mov instructions, but 28 | when building the compressed kernel, it uses its integrated assembler 29 | (due to the redefinition of KBUILD_CFLAGS dropping -no-integrated-as), 30 | which has so far defaulted to not generating the GOTPCRELX 31 | relocations. 32 | 33 | Nick Desaulniers reports [1,2]: 34 | A recent change [3] to a default value of configuration variable 35 | (ENABLE_X86_RELAX_RELOCATIONS OFF -> ON) in LLVM now causes Clang's 36 | integrated assembler to emit R_X86_64_GOTPCRELX/R_X86_64_REX_GOTPCRELX 37 | relocations. LLD will relax instructions with these relocations based 38 | on whether the image is being linked as position independent or not. 39 | When not, then LLD will relax these instructions to use absolute 40 | addressing mode (R_RELAX_GOT_PC_NOPIC). This causes kernels built with 41 | Clang and linked with LLD to fail to boot. 42 | 43 | Patch series [4] is a solution to allow the compressed kernel to be 44 | linked with -pie unconditionally, but even if merged is unlikely to be 45 | backported. As a simple solution that can be applied to stable as well, 46 | prevent the assembler from generating the relaxed relocation types using 47 | the -mrelax-relocations=no option. For ease of backporting, do this 48 | unconditionally. 49 | 50 | [0] https://gitlab.com/x86-psABIs/x86-64-ABI/-/blob/master/x86-64-ABI/linker-optimization.tex#L65 51 | [1] https://lore.kernel.org/lkml/20200807194100.3570838-1-ndesaulniers@google.com/ 52 | [2] https://github.com/ClangBuiltLinux/linux/issues/1121 53 | [3] https://reviews.llvm.org/rGc41a18cf61790fc898dcda1055c3efbf442c14c0 54 | [4] https://lore.kernel.org/lkml/20200731202738.2577854-1-nivedita@alum.mit.edu/ 55 | 56 | Reported-by: Nick Desaulniers 57 | Signed-off-by: Arvind Sankar 58 | Tested-by: Nick Desaulniers 59 | Tested-by: Sedat Dilek 60 | Reviewed-by: Nick Desaulniers 61 | Cc: stable@vger.kernel.org 62 | Link: https://lore.kernel.org/r/20200812004308.1448603-1-nivedita@alum.mit.edu 63 | Signed-off-by: Nathan Chancellor 64 | --- 65 | arch/x86/boot/compressed/Makefile | 2 ++ 66 | 1 file changed, 2 insertions(+) 67 | 68 | diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile 69 | index 3a250ca2406c..644f9e14cb09 100644 70 | --- a/arch/x86/boot/compressed/Makefile 71 | +++ b/arch/x86/boot/compressed/Makefile 72 | @@ -36,6 +36,8 @@ KBUILD_CFLAGS += -mno-mmx -mno-sse 73 | KBUILD_CFLAGS += $(call cc-option,-ffreestanding) 74 | KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector) 75 | KBUILD_CFLAGS += $(call cc-disable-warning, address-of-packed-member) 76 | +# Disable relocation relaxation in case the link is not PIE. 77 | +KBUILD_CFLAGS += $(call as-option,-Wa$(comma)-mrelax-relocations=no) 78 | 79 | KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__ 80 | GCOV_PROFILE := n 81 | -- 82 | 2.28.0 83 | 84 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: cpp 2 | jobs: 3 | include: 4 | # linux 5 | - name: "ARCH=arm32_v5 LLVM=1 LLVM_IAS=1" 6 | env: ARCH=arm32_v5 LLVM=1 LLVM_IAS=1 7 | - name: "ARCH=arm32_v6" 8 | env: ARCH=arm32_v6 9 | - name: "ARCH=arm32_v7 LLVM=1" 10 | env: ARCH=arm32_v7 LLVM=1 11 | - name: "ARCH=arm64 LLVM=1 LLVM_IAS=1" 12 | env: ARCH=arm64 LLVM=1 LLVM_IAS=1 13 | - name: "ARCH=mips" 14 | env: ARCH=mips 15 | - name: "ARCH=mipsel LD=ld.lld" 16 | env: ARCH=mipsel LD=ld.lld 17 | - name: "ARCH=ppc32" 18 | env: ARCH=ppc32 19 | - name: "ARCH=ppc64" 20 | env: ARCH=ppc64 21 | - name: "ARCH=ppc64le LD=ld.lld" 22 | env: ARCH=ppc64le LD=ld.lld 23 | - name: "ARCH=riscv BOOT=false LLVM_IAS=1" 24 | env: ARCH=riscv BOOT=false LLVM_IAS=1 25 | - name: "ARCH=s390 BOOT=false" 26 | env: ARCH=s390 BOOT=false 27 | - name: "ARCH=x86 LLVM=1 LLVM_IAS=1" 28 | env: ARCH=x86 LLVM=1 LLVM_IAS=1 29 | - name: "ARCH=x86_64 LLVM=1 LLVM_IAS=1" 30 | env: ARCH=x86_64 LLVM=1 LLVM_IAS=1 31 | # linux (cron only) 32 | # 33 | # linux-next (cron only) 34 | - name: "ARCH=arm32_v5 LLVM=1 LLVM_IAS=1 REPO=linux-next" 35 | env: ARCH=arm32_v5 LLVM=1 LLVM_IAS=1 REPO=linux-next 36 | if: type = cron 37 | - name: "ARCH=arm32_v6 REPO=linux-next" 38 | env: ARCH=arm32_v6 REPO=linux-next 39 | if: type = cron 40 | - name: "ARCH=arm32_v7 LLVM=1 REPO=linux-next" 41 | env: ARCH=arm32_v7 LLVM=1 REPO=linux-next 42 | if: type = cron 43 | - name: "ARCH=arm64 LLVM=1 REPO=linux-next" 44 | env: ARCH=arm64 LLVM=1 REPO=linux-next 45 | if: type = cron 46 | - name: "ARCH=mips REPO=linux-next" 47 | env: ARCH=mips REPO=linux-next 48 | if: type = cron 49 | - name: "ARCH=mipsel LD=ld.lld REPO=linux-next" 50 | env: ARCH=mipsel LD=ld.lld REPO=linux-next 51 | if: type = cron 52 | - name: "ARCH=ppc32 REPO=linux-next" 53 | env: ARCH=ppc32 REPO=linux-next 54 | if: type = cron 55 | - name: "ARCH=ppc64 REPO=linux-next" 56 | env: ARCH=ppc64 REPO=linux-next 57 | if: type = cron 58 | - name: "ARCH=ppc64le LD=ld.lld REPO=linux-next" 59 | env: ARCH=ppc64le LD=ld.lld REPO=linux-next 60 | if: type = cron 61 | - name: "ARCH=riscv BOOT=false LLVM_IAS=1 REPO=linux-next" 62 | env: ARCH=riscv BOOT=false LLVM_IAS=1 REPO=linux-next 63 | if: type = cron 64 | - name: "ARCH=s390 BOOT=false REPO=linux-next" 65 | env: ARCH=s390 REPO=linux-next BOOT=false 66 | if: type = cron 67 | - name: "ARCH=x86 LLVM=1 LLVM_IAS=1 REPO=linux-next" 68 | env: ARCH=x86 LLVM=1 LLVM_IAS=1 REPO=linux-next 69 | if: type = cron 70 | - name: "ARCH=x86_64 LLVM=1 LLVM_IAS=1 REPO=linux-next" 71 | env: ARCH=x86_64 LLVM=1 LLVM_IAS=1 REPO=linux-next 72 | if: type = cron 73 | # stable 74 | - name: "ARCH=arm32_v7 LLVM=1 REPO=5.4" 75 | env: ARCH=arm32_v7 LLVM=1 REPO=5.4 76 | if: type = cron 77 | - name: "ARCH=arm64 LLVM=1 REPO=5.4" 78 | env: ARCH=arm64 LLVM=1 REPO=5.4 79 | if: type = cron 80 | - name: "ARCH=mips LD=ld.lld REPO=5.4" 81 | env: ARCH=mips LD=ld.lld REPO=5.4 82 | if: type = cron 83 | - name: "ARCH=mipsel LD=ld.lld REPO=5.4" 84 | env: ARCH=mipsel LD=ld.lld REPO=5.4 85 | if: type = cron 86 | - name: "ARCH=ppc32 REPO=5.4" 87 | env: ARCH=ppc32 REPO=5.4 88 | if: type = cron 89 | - name: "ARCH=x86_64 LLVM=1 REPO=5.4" 90 | env: ARCH=x86_64 LLVM=1 REPO=5.4 91 | if: type = cron 92 | - name: "ARCH=arm32_v7 LLVM=1 REPO=4.19" 93 | env: ARCH=arm32_v7 LLVM=1 REPO=4.19 94 | if: type = cron 95 | - name: "ARCH=arm64 LLVM=1 REPO=4.19" 96 | env: ARCH=arm64 LLVM=1 REPO=4.19 97 | if: type = cron 98 | - name: "ARCH=ppc64le REPO=4.19" 99 | env: ARCH=ppc64le REPO=4.19 100 | if: type = cron 101 | - name: "ARCH=x86_64 LLVM=1 REPO=4.19" 102 | env: ARCH=x86_64 LLVM=1 REPO=4.19 103 | if: type = cron 104 | - name: "ARCH=arm32_v7 REPO=4.14" 105 | env: ARCH=arm32_v7 REPO=4.14 106 | if: type = cron 107 | - name: "ARCH=arm64 LD=ld.lld REPO=4.14" 108 | env: ARCH=arm64 LD=ld.lld REPO=4.14 109 | if: type = cron 110 | - name: "ARCH=ppc64le REPO=4.14" 111 | env: ARCH=ppc64le REPO=4.14 112 | if: type = cron 113 | - name: "ARCH=x86_64 LD=ld.lld REPO=4.14" 114 | env: ARCH=x86_64 LD=ld.lld REPO=4.14 115 | if: type = cron 116 | - name: "ARCH=arm32_v7 REPO=4.9" 117 | env: ARCH=arm32_v7 REPO=4.9 118 | if: type = cron 119 | - name: "ARCH=arm64 REPO=4.9" 120 | env: ARCH=arm64 REPO=4.9 121 | if: type = cron 122 | - name: "ARCH=x86_64 LD=ld.lld REPO=4.9" 123 | env: ARCH=x86_64 LD=ld.lld REPO=4.9 124 | if: type = cron 125 | - name: "ARCH=arm64 REPO=4.4" 126 | env: ARCH=arm64 REPO=4.4 127 | if: type = cron 128 | - name: "ARCH=x86_64 LD=ld.lld REPO=4.4" 129 | env: ARCH=x86_64 LD=ld.lld REPO=4.4 130 | if: type = cron 131 | # kernel/common 132 | - name: "ARCH=arm64 REPO=android-4.9-q" 133 | env: ARCH=arm64 REPO=android-4.9-q 134 | if: type = cron 135 | - name: "ARCH=arm64 REPO=android-4.14-stable" 136 | env: ARCH=arm64 REPO=android-4.14-stable 137 | if: type = cron 138 | - name: "ARCH=arm64 LLVM=1 REPO=android-4.19-stable" 139 | env: ARCH=arm64 LLVM=1 REPO=android-4.19-stable 140 | if: type = cron 141 | - name: "ARCH=arm64 LLVM=1 REPO=android12-5.4" 142 | env: ARCH=arm64 LLVM=1 REPO=android12-5.4 143 | if: type = cron 144 | - name: "ARCH=arm64 LLVM=1 LLVM_IAS=1 REPO=android-mainline" 145 | env: ARCH=arm64 LLVM=1 LLVM_IAS=1 REPO=android-mainline 146 | if: type = cron 147 | - name: "ARCH=x86_64 LD=ld.lld REPO=android-4.9-q" 148 | env: ARCH=x86_64 LD=ld.lld REPO=android-4.9-q 149 | if: type = cron 150 | - name: "ARCH=x86_64 LD=ld.lld REPO=android-4.14-stable" 151 | env: ARCH=x86_64 LD=ld.lld REPO=android-4.14-stable 152 | if: type = cron 153 | - name: "ARCH=x86_64 LLVM=1 REPO=android-4.19-stable" 154 | env: ARCH=x86_64 LLVM=1 REPO=android-4.19-stable 155 | if: type = cron 156 | - name: "ARCH=x86_64 LLVM=1 REPO=android12-5.4" 157 | env: ARCH=x86_64 LLVM=1 REPO=android12-5.4 158 | if: type = cron 159 | - name: "ARCH=x86_64 LLVM=1 LLVM_IAS=1 REPO=android-mainline" 160 | env: ARCH=x86_64 LLVM=1 LLVM_IAS=1 REPO=android-mainline 161 | if: type = cron 162 | # linux with stable LLVM/Clang 163 | - name: "ARCH=arm32_v5 LD=ld.lld LLVM_VERSION=11" 164 | env: ARCH=arm32_v5 LD=ld.lld LLVM_VERSION=11 165 | if: type = cron 166 | - name: "ARCH=arm32_v6 LLVM_VERSION=11" 167 | env: ARCH=arm32_v6 LLVM_VERSION=11 168 | if: type = cron 169 | - name: "ARCH=arm32_v7 LD=ld.lld LLVM_VERSION=11" 170 | env: ARCH=arm32_v7 LD=ld.lld LLVM_VERSION=11 171 | if: type = cron 172 | - name: "ARCH=arm64 LLVM_VERSION=11" 173 | env: ARCH=arm64 LLVM_VERSION=11 174 | if: type = cron 175 | - name: "ARCH=mips LLVM_VERSION=11" 176 | env: ARCH=mips LLVM_VERSION=11 177 | if: type = cron 178 | - name: "ARCH=mipsel LLVM_VERSION=11" 179 | env: ARCH=mipsel LLVM_VERSION=11 180 | if: type = cron 181 | - name: "ARCH=ppc32 LLVM_VERSION=11" 182 | env: ARCH=ppc32 LLVM_VERSION=11 183 | if: type = cron 184 | - name: "ARCH=ppc64 LLVM_VERSION=11" 185 | env: ARCH=ppc64 LLVM_VERSION=11 186 | if: type = cron 187 | - name: "ARCH=ppc64le LLVM_VERSION=11" 188 | env: ARCH=ppc64le LLVM_VERSION=11 189 | if: type = cron 190 | - name: "ARCH=x86_64 LLVM_VERSION=11" 191 | env: ARCH=x86_64 LLVM_VERSION=11 192 | if: type = cron 193 | compiler: gcc 194 | os: linux 195 | cache: 196 | directories: 197 | - .ccache 198 | services: 199 | - docker 200 | script: 201 | - | 202 | docker run \ 203 | --env ARCH=${ARCH} \ 204 | --env LD=${LD} \ 205 | --env LLVM=${LLVM} \ 206 | --env LLVM_IAS=${LLVM_IAS} \ 207 | --env REPO=${REPO} \ 208 | --env BOOT=${BOOT} \ 209 | --rm \ 210 | --workdir /travis \ 211 | --volume ${TRAVIS_BUILD_DIR}:/travis \ 212 | clangbuiltlinux/ubuntu:llvm${LLVM_VERSION:-12}-latest /bin/bash -c './env-setup.sh && ./driver.sh && ccache -s' 213 | after_script: 214 | - sleep 1 215 | notifications: 216 | email: 217 | recipients: 218 | - ndesaulniers@google.com 219 | - natechancellor@gmail.com 220 | on_success: never 221 | on_failure: always 222 | if: type = cron 223 | -------------------------------------------------------------------------------- /patches/llvm-8/linux/x86_64/x86-series.patch: -------------------------------------------------------------------------------- 1 | From 3b5f7c47389865240a781933324d165897e00abc Mon Sep 17 00:00:00 2001 2 | From: Nathan Chancellor 3 | Date: Sat, 5 Jan 2019 11:51:39 -0700 4 | Subject: [PATCH 1/2] DO-NOT-UPSTREAM: x86: Revert two commits that break the 5 | build with Clang 6 | 7 | * 4a789213c9a5 ("x86 uaccess: Introduce __put_user_goto") 8 | * a959dc88f9c8 ("Use __put_user_goto in __put_user_size() and unsafe_put_user()") 9 | 10 | We've been fortunate enough to get around the asm goto requirement 11 | introduced in commit e501ce957a78 ("x86: Force asm-goto") until now. 12 | 13 | This is not a clean revert because of commit 2a418cf3f5f1 ("x86/uaccess: 14 | Don't leak the AC flag into __put_user() value evaluation") and commit 15 | 6ae865615fc4 ("x86/uaccess: Dont leak the AC flag into __put_user() 16 | argument evaluation"). 17 | 18 | Link: https://github.com/ClangBuiltLinux/linux/issues/6 19 | Signed-off-by: Nathan Chancellor 20 | --- 21 | arch/x86/include/asm/uaccess.h | 80 +++++++++++++++++----------------- 22 | 1 file changed, 41 insertions(+), 39 deletions(-) 23 | 24 | diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h 25 | index c82abd6e4ca3..5abc7e144e01 100644 26 | --- a/arch/x86/include/asm/uaccess.h 27 | +++ b/arch/x86/include/asm/uaccess.h 28 | @@ -182,14 +182,19 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL)) 29 | 30 | 31 | #ifdef CONFIG_X86_32 32 | -#define __put_user_goto_u64(x, addr, label) \ 33 | - asm_volatile_goto("\n" \ 34 | - "1: movl %%eax,0(%1)\n" \ 35 | - "2: movl %%edx,4(%1)\n" \ 36 | - _ASM_EXTABLE_UA(1b, %l2) \ 37 | - _ASM_EXTABLE_UA(2b, %l2) \ 38 | - : : "A" (x), "r" (addr) \ 39 | - : : label) 40 | +#define __put_user_asm_u64(x, addr, err, errret) \ 41 | + asm volatile("\n" \ 42 | + "1: movl %%eax,0(%2)\n" \ 43 | + "2: movl %%edx,4(%2)\n" \ 44 | + "3:" \ 45 | + ".section .fixup,\"ax\"\n" \ 46 | + "4: movl %3,%0\n" \ 47 | + " jmp 3b\n" \ 48 | + ".previous\n" \ 49 | + _ASM_EXTABLE_UA(1b, 4b) \ 50 | + _ASM_EXTABLE_UA(2b, 4b) \ 51 | + : "=r" (err) \ 52 | + : "A" (x), "r" (addr), "i" (errret), "0" (err)) 53 | 54 | #define __put_user_asm_ex_u64(x, addr) \ 55 | asm volatile("\n" \ 56 | @@ -204,8 +209,8 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL)) 57 | asm volatile("call __put_user_8" : "=a" (__ret_pu) \ 58 | : "A" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx") 59 | #else 60 | -#define __put_user_goto_u64(x, ptr, label) \ 61 | - __put_user_goto(x, ptr, "q", "", "er", label) 62 | +#define __put_user_asm_u64(x, ptr, retval, errret) \ 63 | + __put_user_asm(x, ptr, retval, "q", "", "er", errret) 64 | #define __put_user_asm_ex_u64(x, addr) \ 65 | __put_user_asm_ex(x, addr, "q", "", "er") 66 | #define __put_user_x8(x, ptr, __ret_pu) __put_user_x(8, x, ptr, __ret_pu) 67 | @@ -266,21 +271,22 @@ extern void __put_user_8(void); 68 | __builtin_expect(__ret_pu, 0); \ 69 | }) 70 | 71 | -#define __put_user_size(x, ptr, size, label) \ 72 | +#define __put_user_size(x, ptr, size, retval, errret) \ 73 | do { \ 74 | + retval = 0; \ 75 | __chk_user_ptr(ptr); \ 76 | switch (size) { \ 77 | case 1: \ 78 | - __put_user_goto(x, ptr, "b", "b", "iq", label); \ 79 | + __put_user_asm(x, ptr, retval, "b", "b", "iq", errret); \ 80 | break; \ 81 | case 2: \ 82 | - __put_user_goto(x, ptr, "w", "w", "ir", label); \ 83 | + __put_user_asm(x, ptr, retval, "w", "w", "ir", errret); \ 84 | break; \ 85 | case 4: \ 86 | - __put_user_goto(x, ptr, "l", "k", "ir", label); \ 87 | + __put_user_asm(x, ptr, retval, "l", "k", "ir", errret); \ 88 | break; \ 89 | case 8: \ 90 | - __put_user_goto_u64(x, ptr, label); \ 91 | + __put_user_asm_u64(x, ptr, retval, errret); \ 92 | break; \ 93 | default: \ 94 | __put_user_bad(); \ 95 | @@ -425,15 +431,12 @@ do { \ 96 | 97 | #define __put_user_nocheck(x, ptr, size) \ 98 | ({ \ 99 | - __label__ __pu_label; \ 100 | - int __pu_err = -EFAULT; \ 101 | + int __pu_err; \ 102 | __typeof__(*(ptr)) __pu_val = (x); \ 103 | __typeof__(ptr) __pu_ptr = (ptr); \ 104 | __typeof__(size) __pu_size = (size); \ 105 | __uaccess_begin(); \ 106 | - __put_user_size(__pu_val, __pu_ptr, __pu_size, __pu_label); \ 107 | - __pu_err = 0; \ 108 | -__pu_label: \ 109 | + __put_user_size(__pu_val, __pu_ptr, __pu_size, __pu_err, -EFAULT);\ 110 | __uaccess_end(); \ 111 | __builtin_expect(__pu_err, 0); \ 112 | }) 113 | @@ -458,23 +461,17 @@ struct __large_struct { unsigned long buf[100]; }; 114 | * we do not write to any memory gcc knows about, so there are no 115 | * aliasing issues. 116 | */ 117 | -#define __put_user_goto(x, addr, itype, rtype, ltype, label) \ 118 | - asm_volatile_goto("\n" \ 119 | - "1: mov"itype" %"rtype"0,%1\n" \ 120 | - _ASM_EXTABLE_UA(1b, %l2) \ 121 | - : : ltype(x), "m" (__m(addr)) \ 122 | - : : label) 123 | - 124 | -#define __put_user_failed(x, addr, itype, rtype, ltype, errret) \ 125 | - ({ __label__ __puflab; \ 126 | - int __pufret = errret; \ 127 | - __put_user_goto(x,addr,itype,rtype,ltype,__puflab); \ 128 | - __pufret = 0; \ 129 | - __puflab: __pufret; }) 130 | - 131 | -#define __put_user_asm(x, addr, retval, itype, rtype, ltype, errret) do { \ 132 | - retval = __put_user_failed(x, addr, itype, rtype, ltype, errret); \ 133 | -} while (0) 134 | +#define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \ 135 | + asm volatile("\n" \ 136 | + "1: mov"itype" %"rtype"1,%2\n" \ 137 | + "2:\n" \ 138 | + ".section .fixup,\"ax\"\n" \ 139 | + "3: mov %3,%0\n" \ 140 | + " jmp 2b\n" \ 141 | + ".previous\n" \ 142 | + _ASM_EXTABLE_UA(1b, 3b) \ 143 | + : "=r"(err) \ 144 | + : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err)) 145 | 146 | #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \ 147 | asm volatile("1: mov"itype" %"rtype"0,%1\n" \ 148 | @@ -718,8 +715,13 @@ static __must_check __always_inline bool user_access_begin(const void __user *pt 149 | #define user_access_save() smap_save() 150 | #define user_access_restore(x) smap_restore(x) 151 | 152 | -#define unsafe_put_user(x, ptr, label) \ 153 | - __put_user_size((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)), label) 154 | +#define unsafe_put_user(x, ptr, err_label) \ 155 | +do { \ 156 | + int __pu_err; \ 157 | + __typeof__(*(ptr)) __pu_val = (x); \ 158 | + __put_user_size(__pu_val, (ptr), sizeof(*(ptr)), __pu_err, -EFAULT); \ 159 | + if (unlikely(__pu_err)) goto err_label; \ 160 | +} while (0) 161 | 162 | #define unsafe_get_user(x, ptr, err_label) \ 163 | do { \ 164 | -- 165 | 2.21.0 166 | 167 | 168 | From f272bf78754e6250c2ea118520686c5b873a114c Mon Sep 17 00:00:00 2001 169 | From: Nathan Chancellor 170 | Date: Tue, 25 Sep 2018 13:32:33 -0700 171 | Subject: [PATCH 2/2] DO-NOT-UPSTREAM: x86: Avoid warnings/errors due to lack 172 | of asm goto 173 | 174 | We don't want to see an inordinate amount of warning spam from 175 | the BPF samples and after reverting commits 4a789213c9a5 ("x86 176 | uaccess: Introduce __put_user_goto") and a959dc88f9c8 ("Use 177 | __put_user_goto in __put_user_size() and unsafe_put_user()"), we 178 | can successfully compile an x86 kernel with Clang. 179 | 180 | This is obviously not a long term solution. LLVM/Clang support for 181 | asm goto can be tracked at the below link. 182 | 183 | Link: https://github.com/ClangBuiltLinux/linux/issues/6 184 | Signed-off-by: Nathan Chancellor 185 | --- 186 | arch/x86/Makefile | 9 +++++---- 187 | arch/x86/boot/compressed/Makefile | 3 +++ 188 | drivers/firmware/efi/libstub/Makefile | 4 ++++ 189 | 3 files changed, 12 insertions(+), 4 deletions(-) 190 | 191 | diff --git a/arch/x86/Makefile b/arch/x86/Makefile 192 | index 56e748a7679f..9237af36280b 100644 193 | --- a/arch/x86/Makefile 194 | +++ b/arch/x86/Makefile 195 | @@ -227,6 +227,11 @@ ifdef CONFIG_RETPOLINE 196 | endif 197 | endif 198 | 199 | +# Avoid warnings in arch/x86/include/asm/cpufeature.h when building with Clang 200 | +ifndef CONFIG_CC_HAS_ASM_GOTO 201 | + KBUILD_CFLAGS += -D__BPF_TRACING__ 202 | +endif 203 | + 204 | archscripts: scripts_basic 205 | $(Q)$(MAKE) $(build)=arch/x86/tools relocs 206 | 207 | @@ -297,10 +302,6 @@ vdso_install: 208 | 209 | archprepare: checkbin 210 | checkbin: 211 | -ifndef CONFIG_CC_HAS_ASM_GOTO 212 | - @echo Compiler lacks asm-goto support. 213 | - @exit 1 214 | -endif 215 | ifdef CONFIG_RETPOLINE 216 | ifeq ($(RETPOLINE_CFLAGS),) 217 | @echo "You are building kernel with non-retpoline compiler." >&2 218 | diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile 219 | index 6b84afdd7538..c7265084dd78 100644 220 | --- a/arch/x86/boot/compressed/Makefile 221 | +++ b/arch/x86/boot/compressed/Makefile 222 | @@ -38,6 +38,9 @@ KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector) 223 | KBUILD_CFLAGS += $(call cc-disable-warning, address-of-packed-member) 224 | KBUILD_CFLAGS += $(call cc-disable-warning, gnu) 225 | KBUILD_CFLAGS += -Wno-pointer-sign 226 | +ifndef CONFIG_CC_HAS_ASM_GOTO 227 | +KBUILD_CFLAGS += -D__BPF_TRACING__ 228 | +endif 229 | 230 | KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__ 231 | GCOV_PROFILE := n 232 | diff --git a/drivers/firmware/efi/libstub/Makefile b/drivers/firmware/efi/libstub/Makefile 233 | index 0460c7581220..315f43ea5b0c 100644 234 | --- a/drivers/firmware/efi/libstub/Makefile 235 | +++ b/drivers/firmware/efi/libstub/Makefile 236 | @@ -24,6 +24,10 @@ cflags-$(CONFIG_ARM) := $(subst $(CC_FLAGS_FTRACE),,$(KBUILD_CFLAGS)) \ 237 | 238 | cflags-$(CONFIG_EFI_ARMSTUB) += -I$(srctree)/scripts/dtc/libfdt 239 | 240 | +ifndef CONFIG_CC_HAS_ASM_GOTO 241 | +cflags-$(CONFIG_X86) += -D__BPF_TRACING__ 242 | +endif 243 | + 244 | KBUILD_CFLAGS := $(cflags-y) -DDISABLE_BRANCH_PROFILING \ 245 | -D__NO_FORTIFY \ 246 | $(call cc-option,-ffreestanding) \ 247 | -- 248 | 2.21.0 249 | 250 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2018 The ClangBuiltLinux Authors. 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /driver.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -eu 4 | 5 | setup_variables() { 6 | while [[ ${#} -ge 1 ]]; do 7 | case ${1} in 8 | "AR="* | "ARCH="* | "CC="* | "LD="* | "LLVM="* | "LLVM_IAS="* | "NM"=* | "OBJCOPY"=* | "OBJDUMP"=* | "OBJSIZE"=* | "REPO="* | "STRIP"=*) export "${1?}" ;; 9 | "-c" | "--clean") cleanup=true ;; 10 | "-j" | "--jobs") 11 | shift 12 | jobs=$1 13 | ;; 14 | "-j"*) jobs=${1/-j/} ;; 15 | "--lto") disable_lto=false ;; 16 | "-h" | "--help") 17 | cat usage.txt 18 | exit 0 19 | ;; 20 | esac 21 | 22 | shift 23 | done 24 | 25 | if [ "${ARCH:-0}" -eq "0" ]; then 26 | cat usage.txt 27 | exit 1 28 | fi 29 | 30 | # Turn on debug mode after parameters in case -h was specified 31 | set -x 32 | 33 | # torvalds/linux is the default repo if nothing is specified 34 | case ${REPO:=linux} in 35 | "android"*) 36 | tree=common 37 | branch=${REPO} 38 | url=https://android.googlesource.com/kernel/${tree} 39 | ;; 40 | "linux") 41 | owner=torvalds 42 | tree=linux 43 | ;; 44 | "linux-next") 45 | owner=next 46 | tree=linux-next 47 | ;; 48 | "4.4" | "4.9" | "4.14" | "4.19" | "5.4") 49 | owner=stable 50 | branch=linux-${REPO}.y 51 | tree=linux 52 | ;; 53 | esac 54 | [[ -z "${url:-}" ]] && url=git://git.kernel.org/pub/scm/linux/kernel/git/${owner}/${tree}.git 55 | 56 | SUBARCH=${ARCH} 57 | case ${SUBARCH} in 58 | "arm32_v5") 59 | config=multi_v5_defconfig 60 | make_target=zImage 61 | export ARCH=arm 62 | export CROSS_COMPILE=arm-linux-gnueabi- 63 | ;; 64 | 65 | "arm32_v6") 66 | config=aspeed_g5_defconfig 67 | make_target=zImage 68 | timeout=4 # This architecture needs a bit of a longer timeout due to some flakiness on Travis 69 | export ARCH=arm 70 | export CROSS_COMPILE=arm-linux-gnueabi- 71 | ;; 72 | 73 | "arm32_v7") 74 | config=multi_v7_defconfig 75 | make_target=zImage 76 | export ARCH=arm 77 | export CROSS_COMPILE=arm-linux-gnueabi- 78 | ;; 79 | 80 | "arm64") 81 | case ${REPO} in 82 | android-*) 83 | case ${branch} in 84 | *4.9-q | *4.14-stable) config=cuttlefish_defconfig ;; 85 | *) config=gki_defconfig ;; 86 | esac 87 | ;; 88 | *) config=defconfig ;; 89 | esac 90 | make_target=Image.gz 91 | timeout=8 # '-cpu max' with QEMU takes longer to boot, increase timeout to 8m for Travis 92 | export CROSS_COMPILE=aarch64-linux-gnu- 93 | ;; 94 | 95 | "mips") 96 | config=malta_kvm_guest_defconfig 97 | make_target=vmlinux 98 | export ARCH=mips 99 | export CROSS_COMPILE=mips-linux-gnu- 100 | ;; 101 | 102 | "mipsel") 103 | config=malta_kvm_guest_defconfig 104 | make_target=vmlinux 105 | export ARCH=mips 106 | export CROSS_COMPILE=mipsel-linux-gnu- 107 | ;; 108 | 109 | "ppc32") 110 | config=ppc44x_defconfig 111 | make_target=uImage 112 | export ARCH=powerpc 113 | export CROSS_COMPILE=powerpc-linux-gnu- 114 | ;; 115 | 116 | "ppc64") 117 | config=pseries_defconfig 118 | make_target=vmlinux 119 | export ARCH=powerpc 120 | export CROSS_COMPILE=powerpc64-linux-gnu- 121 | ;; 122 | 123 | "ppc64le") 124 | config=powernv_defconfig 125 | make_target=zImage.epapr 126 | export ARCH=powerpc 127 | export CROSS_COMPILE=powerpc64le-linux-gnu- 128 | ;; 129 | 130 | "riscv") 131 | config=defconfig 132 | make_target=Image 133 | export CROSS_COMPILE=riscv64-linux-gnu- 134 | ;; 135 | 136 | "s390") 137 | BOOT=false 138 | config=defconfig 139 | make_target=bzImage 140 | export CROSS_COMPILE=s390x-linux-gnu- 141 | 142 | # llvm-objcopy: error: invalid output format: 'elf64-s390' 143 | # https://github.com/llvm/llvm-project/blob/llvmorg-11-init/llvm/tools/llvm-objcopy/CopyConfig.cpp#L242-L275 144 | OBJCOPY=${CROSS_COMPILE}objcopy 145 | OBJDUMP=${CROSS_COMPILE}objdump 146 | ;; 147 | 148 | "x86") 149 | config=i386_defconfig 150 | make_target=bzImage 151 | export ARCH=i386 152 | ;; 153 | 154 | "x86_64") 155 | case ${REPO} in 156 | android-*) 157 | case ${branch} in 158 | *4.9-q | *4.14-stable) config=x86_64_cuttlefish_defconfig ;; 159 | *) config=gki_defconfig ;; 160 | esac 161 | ;; 162 | *) 163 | config=defconfig 164 | ;; 165 | esac 166 | make_target=bzImage 167 | ;; 168 | 169 | # Unknown arch, error out 170 | *) 171 | echo "Unknown ARCH specified!" 172 | exit 1 173 | ;; 174 | esac 175 | export ARCH=${ARCH} 176 | } 177 | 178 | # Clone/update the boot-utils 179 | # It would be nice to use submodules for this but those don't always play well with Travis 180 | # https://github.com/ClangBuiltLinux/continuous-integration/commit/e9054499bb1cb1a51cd1cdc73dc3c1dfa45b4199 181 | function update_boot_utils() { 182 | images_url=https://github.com/ClangBuiltLinux/boot-utils 183 | if [[ -d boot-utils ]]; then 184 | cd boot-utils 185 | git fetch --depth=1 ${images_url} main 186 | git reset --hard FETCH_HEAD 187 | cd .. 188 | else 189 | git clone --depth=1 ${images_url} 190 | fi 191 | } 192 | 193 | check_dependencies() { 194 | # Check for existence of needed binaries 195 | command -v nproc 196 | command -v timeout 197 | command -v unbuffer 198 | command -v zstd 199 | 200 | update_boot_utils 201 | 202 | oldest_llvm_version=7 203 | latest_llvm_version=$(curl -LSs https://raw.githubusercontent.com/llvm/llvm-project/main/llvm/CMakeLists.txt | grep -s -F "set(LLVM_VERSION_MAJOR" | cut -d ' ' -f 4 | sed 's/)//') 204 | 205 | for llvm_version in $(seq "${latest_llvm_version}" -1 "${oldest_llvm_version}"); do 206 | debian_llvm_bin=/usr/lib/llvm-${llvm_version}/bin 207 | if [[ -d ${debian_llvm_bin} ]]; then 208 | export PATH=${debian_llvm_bin}:${PATH} 209 | break 210 | fi 211 | done 212 | 213 | READELF=llvm-readelf 214 | command -v "${READELF}" 215 | 216 | # Check for LD, CC, and AR environmental variables 217 | # and print the version string of each. If CC and AR 218 | # don't exist, try to find them. 219 | # clang's integrated assembler and lld aren't ready for all architectures so 220 | # it's just simpler to fall back to GNU as/ld when AS/LD isn't specified to 221 | # avoid architecture specific selection logic. 222 | 223 | "${LD:="${CROSS_COMPILE:-}"ld}" --version 224 | if [[ -z "${LLVM_IAS:-}" ]]; then 225 | LLVM_IAS=0 226 | command -v "${CROSS_COMPILE:-}"as 227 | fi 228 | 229 | if [[ -z "${CC:-}" ]]; then 230 | CC=clang 231 | command -v "${CC}" 232 | fi 233 | ${CC} --version 2>/dev/null || { 234 | set +x 235 | echo 236 | echo "Looks like ${CC} could not be found in PATH!" 237 | echo 238 | echo "Please install as recent a version of clang as you can from your distro or" 239 | echo "properly specify the CC variable to point to the correct clang binary." 240 | echo 241 | echo "If you don't want to install clang, you can either download AOSP's prebuilt" 242 | echo "clang [1] or build it from source [2] then add the bin folder to your PATH." 243 | echo 244 | echo "[1]: https://android.googlesource.com/platform/prebuilts/clang/host/linux-x86/" 245 | echo "[2]: https://github.com/ClangBuiltLinux/linux/wiki/Building-Clang-from-source" 246 | echo 247 | exit 248 | } 249 | 250 | if [[ -z "${AR:-}" ]]; then 251 | for AR in llvm-ar "${CROSS_COMPILE:-}"ar; do 252 | command -v "${AR}" 2>/dev/null && break 253 | done 254 | fi 255 | check_ar_version 256 | "${AR}" --version 257 | 258 | if [[ -z "${NM:-}" ]]; then 259 | for NM in llvm-nm "${CROSS_COMPILE:-}"nm; do 260 | command -v "${NM}" 2>/dev/null && break 261 | done 262 | fi 263 | 264 | if [[ -z "${OBJCOPY:-}" ]]; then 265 | for OBJCOPY in llvm-objcopy "${CROSS_COMPILE:-}"objcopy; do 266 | command -v "${OBJCOPY}" 2>/dev/null && break 267 | done 268 | fi 269 | 270 | if [[ -z "${OBJDUMP:-}" ]]; then 271 | for OBJDUMP in llvm-objdump "${CROSS_COMPILE:-}"objdump; do 272 | command -v "${OBJDUMP}" 2>/dev/null && break 273 | done 274 | fi 275 | 276 | if [[ -z "${OBJSIZE:-}" ]]; then 277 | for OBJSIZE in llvm-size "${CROSS_COMPILE:-}"size; do 278 | command -v "${OBJSIZE}" 2>/dev/null && break 279 | done 280 | fi 281 | 282 | if [[ -z "${STRIP:-}" ]]; then 283 | for STRIP in llvm-strip "${CROSS_COMPILE:-}"strip; do 284 | command -v "${STRIP}" 2>/dev/null && break 285 | done 286 | fi 287 | 288 | check_objcopy_strip_version 289 | "${OBJCOPY}" --version 290 | "${STRIP}" --version 291 | } 292 | 293 | # Optimistically check to see that the user has a llvm-ar 294 | # with https://reviews.llvm.org/rL354044. If they don't, 295 | # fall back to GNU ar and let them know. 296 | check_ar_version() { 297 | if ${AR} --version | grep -q "LLVM" && 298 | [[ $(${AR} --version | grep version | sed -e 's/.*LLVM version //g' -e 's/[[:blank:]]*$//' -e 's/\.//g' -e 's/svn//' -e 's/git//') -lt 900 ]]; then 299 | set +x 300 | echo 301 | echo "${AR} found but appears to be too old to build the kernel (needs to be at least 9.0.0)." 302 | echo 303 | echo "Please either update llvm-ar from your distro or build it from source!" 304 | echo 305 | echo "See https://github.com/ClangBuiltLinux/linux/issues/33 for more info." 306 | echo 307 | echo "Falling back to GNU ar..." 308 | echo 309 | AR=${CROSS_COMPILE:-}ar 310 | set -x 311 | fi 312 | } 313 | 314 | # Optimistically check to see that the user has an llvm-{objcopy,strip} 315 | # with https://reviews.llvm.org/rGedeebad7715774b8481103733dc5d52dac43bdf3. 316 | # If they don't, fall back to GNU objcopy and let them know. 317 | check_objcopy_strip_version() { 318 | for TOOL in ${OBJCOPY} ${STRIP}; do 319 | if ${TOOL} --version | grep -q "LLVM" && 320 | [[ $(${TOOL} --version | grep version | sed -e 's/.*LLVM version //g' -e 's/[[:blank:]]*$//' -e 's/\.//g' -e 's/svn//' -e 's/git//') -lt 1000 ]]; then 321 | set +x 322 | echo 323 | echo "${TOOL} found but appears to be too old to build the kernel (needs to be at least 10.0.0)." 324 | echo 325 | echo "Please either update ${TOOL} from your distro or build it from source!" 326 | echo 327 | echo "See https://github.com/ClangBuiltLinux/linux/issues/478 for more info." 328 | echo 329 | echo "Falling back to GNU ${TOOL//llvm-/}..." 330 | echo 331 | case ${TOOL} in 332 | *objcopy*) OBJCOPY=${CROSS_COMPILE:-}objcopy ;; 333 | *strip*) STRIP=${CROSS_COMPILE:-}strip ;; 334 | esac 335 | set -x 336 | fi 337 | done 338 | } 339 | mako_reactor() { 340 | if [[ ${LLVM:-0} -eq "1" ]]; then 341 | time \ 342 | KBUILD_BUILD_TIMESTAMP="Thu Jan 1 00:00:00 UTC 1970" \ 343 | KBUILD_BUILD_USER=driver \ 344 | KBUILD_BUILD_HOST=clangbuiltlinux \ 345 | make -j"${jobs:-$(nproc)}" \ 346 | LLVM=1 \ 347 | LLVM_IAS="${LLVM_IAS}" \ 348 | "${@}" 349 | else 350 | # https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/kbuild/kbuild.txt 351 | time \ 352 | KBUILD_BUILD_TIMESTAMP="Thu Jan 1 00:00:00 UTC 1970" \ 353 | KBUILD_BUILD_USER=driver \ 354 | KBUILD_BUILD_HOST=clangbuiltlinux \ 355 | make -j"${jobs:-$(nproc)}" \ 356 | AR="${AR}" \ 357 | CC="${CC}" \ 358 | HOSTCC="${CC}" \ 359 | HOSTLD="${HOSTLD:-ld}" \ 360 | KCFLAGS="-Wno-implicit-fallthrough" \ 361 | LD="${LD}" \ 362 | LLVM_IAS="${LLVM_IAS}" \ 363 | NM="${NM}" \ 364 | OBJCOPY="${OBJCOPY}" \ 365 | OBJDUMP="${OBJDUMP}" \ 366 | OBJSIZE="${OBJSIZE}" \ 367 | READELF="${READELF}" \ 368 | STRIP="${STRIP}" \ 369 | "${@}" 370 | fi 371 | } 372 | 373 | apply_patches() { 374 | patches_folder=$1 375 | if [[ -d ${patches_folder} ]]; then 376 | git apply -v -3 "${patches_folder}"/*.patch 377 | else 378 | return 0 379 | fi 380 | } 381 | 382 | build_linux() { 383 | # Wrap CC in ccache if it is available (it's not strictly required) 384 | CC="$(command -v ccache) ${CC}" 385 | [[ ${LD} =~ lld ]] && HOSTLD=${LD} 386 | 387 | if [[ -d ${tree} ]]; then 388 | cd ${tree} 389 | git fetch --depth=1 ${url} ${branch:=master} 390 | git reset --hard FETCH_HEAD 391 | else 392 | git clone --depth=1 -b ${branch:=master} --single-branch ${url} 393 | cd ${tree} 394 | fi 395 | 396 | git show -s | cat 397 | 398 | llvm_all_folder="../patches/llvm-all" 399 | apply_patches "${llvm_all_folder}/kernel-all" 400 | apply_patches "${llvm_all_folder}/${REPO}/arch-all" 401 | apply_patches "${llvm_all_folder}/${REPO}/${SUBARCH}" 402 | llvm_version_folder="../patches/llvm-$(echo __clang_major__ | ${CC} -E -x c - | tail -n 1)" 403 | apply_patches "${llvm_version_folder}/kernel-all" 404 | apply_patches "${llvm_version_folder}/${REPO}/arch-all" 405 | apply_patches "${llvm_version_folder}/${REPO}/${SUBARCH}" 406 | 407 | # Only clean up old artifacts if requested, the Linux build system 408 | # is good about figuring out what needs to be rebuilt 409 | [[ -n "${cleanup:-}" ]] && mako_reactor mrproper 410 | mako_reactor ${config} 411 | # If we're using a defconfig, enable some more common config options 412 | # like debugging, selftests, and common drivers 413 | if [[ ${config} =~ defconfig ]]; then 414 | cat ../configs/common.config >>.config 415 | # Some torture test configs cause issues on PowerPC and x86_64 416 | [[ $ARCH != "x86_64" && $ARCH != "powerpc" ]] && cat ../configs/tt.config >>.config 417 | # For RISC-V, disable a couple of configs: 418 | # * CONFIG_EFI: https://github.com/ClangBuiltLinux/linux/issues/1143 419 | # * CONFIG_KALLSYMS_ALL: https://github.com/ClangBuiltLinux/linux/issues/1144 420 | # Every other configuration option disabled is to get rid of CONFIG_KALLSYMS_ALL. 421 | if [[ $ARCH = "riscv" ]]; then 422 | ./scripts/config \ 423 | -d DEBUG_LOCK_ALLOC \ 424 | -d DEBUG_WW_MUTEX_SLOWPATH \ 425 | -d EFI \ 426 | -d KALLSYMS_ALL \ 427 | -d LOCK_STAT \ 428 | -d PROVE_LOCKING 429 | fi 430 | # Disable LTO and CFI unless explicitly requested 431 | ${disable_lto:=true} && ./scripts/config -d CONFIG_LTO -d CONFIG_LTO_CLANG 432 | fi 433 | [[ $SUBARCH == "mips" ]] && ./scripts/config -e CPU_BIG_ENDIAN -d CPU_LITTLE_ENDIAN 434 | # Make sure we build with CONFIG_DEBUG_SECTION_MISMATCH so that the 435 | # full warning gets printed and we can file and fix it properly. 436 | ./scripts/config -e DEBUG_SECTION_MISMATCH 437 | mako_reactor olddefconfig &>/dev/null 438 | mako_reactor ${make_target} 439 | [[ $ARCH =~ arm ]] && mako_reactor dtbs 440 | "${READELF}" --string-dump=.comment vmlinux 441 | 442 | cd "${OLDPWD}" 443 | } 444 | 445 | boot_qemu() { 446 | ${BOOT:=true} || return 0 447 | ./boot-utils/boot-qemu.sh -a "${SUBARCH}" -k "${tree}" -t "${timeout:-2}"m 448 | } 449 | 450 | setup_variables "${@}" 451 | check_dependencies 452 | build_linux 453 | boot_qemu 454 | --------------------------------------------------------------------------------