From patchwork Mon Nov 6 18:47:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Nick Desaulniers X-Patchwork-Id: 10044239 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 3D14B6032D for ; Mon, 6 Nov 2017 18:47:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2F55E29F3A for ; Mon, 6 Nov 2017 18:47:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2399829F81; Mon, 6 Nov 2017 18:47:42 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BF53D29F3A for ; Mon, 6 Nov 2017 18:47:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932703AbdKFSrl (ORCPT ); Mon, 6 Nov 2017 13:47:41 -0500 Received: from mail-wm0-f68.google.com ([74.125.82.68]:56018 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932469AbdKFSrk (ORCPT ); Mon, 6 Nov 2017 13:47:40 -0500 Received: by mail-wm0-f68.google.com with SMTP id y83so16202278wmc.4 for ; Mon, 06 Nov 2017 10:47:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=kKET/BRVDDD1VmzGdgzOXFROIo1ElN2D6KijLyNbP3s=; b=m7U8CEZ+3HYd4bD0hqC+GStU6BExy1e4sYUECftb9oIetObC3V1OVApY4Oowrn/6xt WidjK3P1aFsvOW7NLqEVK1qIO0TF5Mzboo4mAkBNwb15KDBcZLe25GlpaVg87AwpDyi+ cDpbGQDNeszwxzg+W7C2inR8OkV+a2zZRM8n8I+UedO9l48me7f+6qXzM8IGfOjuO7Rl Yk4FZ8JpXdrYJer7wWVq70FssrlNWLUCt74kOjndjsSmhy8aCkQdNRLqMtoqiy7SPGT6 N5gxPlZ+H56Qo67yvstSaAdefp3116yHtJPWwVK6DLr3sfzToDniDTZTKPclw39k5dLN 28NQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=kKET/BRVDDD1VmzGdgzOXFROIo1ElN2D6KijLyNbP3s=; b=p3eONBdTW4GARZIoxJOoXu0DLuwmR1sr+lfosy5XIC3V7g5Xq1ulFSCsxejOHm74ut M9F67cvJW1XbFwXxb05g3uGogKNv9XiZT8N+5ghSqj+kV+fePsIcyoWG/Cj4JctXjHOT GowDwpaT8XP2FMX2XRN470hXwcQFs6IuTOgaOPxvOtS0QgmTuEuLI4BG9pqIn6+0zqaY M6jvTS6rBnSTAgOl61yUsuTXbvst4il5s8aarERmAWhHPgQvF8s3RbBsKt2yL5t+GCxN ZcoM6wjY8ras6x4fJU5hD55zN7XXKYKcbmv85BXnGIc4DZEmZKb/fzffFnq8jiGFZCm4 pFYA== X-Gm-Message-State: AJaThX4cDfwEHOLH6+qkUwa9AlFjoqQuaaUdIo1muaadwl2mmz+eMQYl tmCyzT1aurugfYltrZ3RE/pS/747q698F21Hg0MOHQ== X-Google-Smtp-Source: ABhQp+QVoTHksCyTlXMomZydcs1nPs9+G6HyW9CVvsfoP7CIxGkMCEa7//zptSJXljC40HnKhz6UOltfj6KfJSumYf0= X-Received: by 10.28.45.214 with SMTP id t205mr6168076wmt.94.1509994058547; Mon, 06 Nov 2017 10:47:38 -0800 (PST) MIME-Version: 1.0 Received: by 10.223.156.26 with HTTP; Mon, 6 Nov 2017 10:47:37 -0800 (PST) In-Reply-To: References: <20171027201345.87383-1-ndesaulniers@google.com> From: Nick Desaulniers Date: Mon, 6 Nov 2017 10:47:37 -0800 Message-ID: Subject: Re: [PATCH v2] kbuild: fix linker feature test macros when cross compiling with Clang To: Masahiro Yamada Cc: Linux Kbuild mailing list , Michael Davidson , Greg Hackmann , Pirama Arumuga Nainar , Douglas Anderson , Ingo Molnar , Matthias Kaehlcke , Arnd Bergmann , Marcin Nowakowski , Mark Charlebois , Josh Poimboeuf , Cao jin , Linux Kernel Mailing List Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Comparing make V=1 with the suggested config before my patch, after my patch, and after Masahiro's suggestion to add $(LDFLAGS): before: ... ld -m elf_i386 -pie -T arch/x86/boot/compressed/vmlinux.lds ... ... after my: ... ld -m elf_i386 -T arch/x86/boot/compressed/vmlinux.lds ... ... after my+Masahiro: ... ld -m elf_i386 -pie -T arch/x86/boot/compressed/vmlinux.lds ... ... :) Just to dig into this a little more (though I suspect we've found the issue): Next is to debug what we're passing to try-run and see what errors it's masking. Adding to arch/x86/boot/compressed/Makefile: then grepping for XXX in a build output: "XXX" "KBUILD_CPPFLAGS: -D__KERNEL__ " "CC_OPTION_CFLAGS: -m32 -D__KERNEL__ -O2 -fno-strict-aliasing -fPIE -DDISABLE_BRANCH_PROFILING -march=i386 -mno-mmx -mno-sse -ffreestanding -fno-stack-protector" "LD_FLAGS: " then trying this on the command line: ➜ kernel-all git:(kbuild) ✗ cc -pie -D__KERNEL__ -m32 -D__KERNEL__ -O2 -fno-strict-aliasing -fPIE -DDISABLE_BRANCH_PROFILING -march=i386 -mno-mmx -mno-sse -ffreestanding -fno-stack-protector -x c /dev/null -c -o temp.o ➜ kernel-all git:(kbuild) ✗ ld -pie temp.o -o temp ld: i386 architecture of input file `temp.o' is incompatible with i386:x86-64 output ld: warning: cannot find entry symbol _start; defaulting to 0000000000000078 ➜ kernel-all git:(kbuild) ✗ echo $? 1 ➜ kernel-all git:(kbuild) ✗ file temp.o temp.o: ELF 32-bit LSB relocatable, Intel 80386, version 1 (SYSV), not stripped So it looks like without LDFLAGS, we don't tell the linker to link as 32b, causing ld-option to fail to add -pie to LDFLAGS. ➜ kernel-all git:(kbuild) ✗ ld -pie -m elf_i386 temp.o -o temp ld: warning: cannot find entry symbol _start; defaulting to 0000000000000185 ➜ kernel-all git:(kbuild) ✗ echo $? 0 sure enough, just before the call to ld-option from arch/x86/boot/compressed/Makefile: 43 LDFLAGS := -m elf_$(UTS_MACHINE) so looks like Masahiro's suggestion is correct. Will send a v3. --- To unsubscribe from this list: send the line "unsubscribe linux-kbuild" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html --- a/arch/x86/boot/compressed/Makefile +++ b/arch/x86/boot/compressed/Makefile @@ -44,6 +44,10 @@ LDFLAGS := -m elf_$(UTS_MACHINE) # Compressed kernel should be built as PIE since it may be loaded at any # address by the bootloader. ifeq ($(CONFIG_X86_32),y) +$(info "XXX") +$(info "KBUILD_CPPFLAGS: ${KBUILD_CPPFLAGS}") +$(info "CC_OPTION_CFLAGS: ${CC_OPTION_CFLAGS}") +$(info "LDFLAGS: ${LDFLAGS}") LDFLAGS += $(call ld-option, -pie) $(call ld-option, --no-dynamic-linker) else # To build 64-bit compressed kernel as PIE, we disable relocation