From patchwork Tue Mar 13 20:59:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Garnier X-Patchwork-Id: 10280789 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 E1FC0602C2 for ; Tue, 13 Mar 2018 21:05:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D1C2221327 for ; Tue, 13 Mar 2018 21:05:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C3EA1284C3; Tue, 13 Mar 2018 21:05:05 +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=-4.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from mother.openwall.net (mother.openwall.net [195.42.179.200]) by mail.wl.linuxfoundation.org (Postfix) with SMTP id 95F0521327 for ; Tue, 13 Mar 2018 21:05:04 +0000 (UTC) Received: (qmail 21855 invoked by uid 550); 13 Mar 2018 21:01:13 -0000 Mailing-List: contact kernel-hardening-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Delivered-To: mailing list kernel-hardening@lists.openwall.com Received: (qmail 21551 invoked from network); 13 Mar 2018 21:01:00 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=1pv1TCYX38Prk84i54e1XzmGAYVvBJdF3eg5DouhUXg=; b=Ib/hdzeFLuc+MZopTj3WaLBpuKjEFx+ThaRvKmcIXNNqtm+H8z+qWYIgpd9GeU/c7B uybQ337SRcL6XfwHAqcB/L0DdXApYGXpj+wuXFMVr6KwjzJys3fyNfY7LvEFNjl8v8mh IRjhvOrMRtR0WWa8R8D63SIAggj0hBT2vh56k0g0hv7IkX5qjYVmQGIFiMTXTjASx/7Y kEk5+PPa2gNFYzU+Qbfm5dAu3Elt5qq5gIUh1NX0KEwhP7Mw1YuUuyuPgsZ1ehSetNXQ hrmc5z27gyCSksbpf+MrkxMAgw8fPSYdFbkZEpOY6uaAG4mNTVE28VgzuQALdE7lgnz+ Ah9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=1pv1TCYX38Prk84i54e1XzmGAYVvBJdF3eg5DouhUXg=; b=R8JqdvKy0WLtoXhWZN7zUSUlHJp0XVIT1n2vhcSUlFKvvi/NCPFPz7U5GVSWs5gqa+ oD7W/CrJbmvwiypUM5FVqJ3Hn7PvWIDNJ6ecHP2LK0NSHzMQvWaOjJMv66UyltAE80ct XIllbD3yCWnp6bb0GAKMnKgBGifdXdr7BlXwCay2EBZEPdsAdxHLgGqpWSpr2pcgv1j/ t+qZqHnPQVxcF4pSQ0624zzP7W/OJK+M86e8S/e/KRf+0sul3FTVNaHil20Ci7zaApOb mYWDoJ4aE4PO7zO3VXYV0Vlenbt/M+ms2nXJCnkUD6eLAdy3PTrtDhh9YoD6zbB9zIQw 9evw== X-Gm-Message-State: AElRT7EFb1OPv/MpAUV5CoCfSnp1OwJNPEPAOVJXsGwVYEz4apq56WzG VgeuZO1ULG/xt4xmVT8yvNc+oA== X-Google-Smtp-Source: AG47ELvC9ii+0/P5pnq3bQVzPZktfrjo0njQPAjbs124XCd7nqJi9aJQE++F1ji5jf2JIUoOXxyDTw== X-Received: by 2002:a17:902:7401:: with SMTP id g1-v6mr1822760pll.4.1520974848592; Tue, 13 Mar 2018 14:00:48 -0700 (PDT) From: Thomas Garnier To: Herbert Xu , "David S . Miller" , Thomas Gleixner , Ingo Molnar , "H . Peter Anvin" , Peter Zijlstra , Josh Poimboeuf , Greg Kroah-Hartman , Kate Stewart , Thomas Garnier , Arnd Bergmann , Philippe Ombredanne , Arnaldo Carvalho de Melo , Andrey Ryabinin , Matthias Kaehlcke , Kees Cook , Tom Lendacky , "Kirill A . Shutemov" , Andy Lutomirski , Dominik Brodowski , Borislav Petkov , Borislav Petkov , "Rafael J . Wysocki" , Len Brown , Pavel Machek , Juergen Gross , Alok Kataria , Steven Rostedt , Tejun Heo , Christoph Lameter , Dennis Zhou , Boris Ostrovsky , David Woodhouse , Alexey Dobriyan , "Paul E . McKenney" , Andrew Morton , Nicolas Pitre , Randy Dunlap , "Luis R . Rodriguez" , Christopher Li , Jason Baron , Ashish Kalra , Kyle McMartin , Dou Liyang , Lukas Wunner , Petr Mladek , Sergey Senozhatsky , Masahiro Yamada , Ingo Molnar , Nicholas Piggin , Cao jin , "H . J . Lu" , Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , Joerg Roedel , Dave Hansen , Rik van Riel , Jia Zhang , Jiri Slaby , Kyle Huey , Jonathan Corbet , Matthew Wilcox , Michal Hocko , Rob Landley , Baoquan He , Daniel Micay , =?UTF-8?q?Jan=20H=20=2E=20Sch=C3=B6nherr?= Cc: x86@kernel.org, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, virtualization@lists.linux-foundation.org, xen-devel@lists.xenproject.org, linux-arch@vger.kernel.org, linux-sparse@vger.kernel.org, kvm@vger.kernel.org, linux-doc@vger.kernel.org, kernel-hardening@lists.openwall.com Subject: [PATCH v2 16/27] compiler: Option to add PROVIDE_HIDDEN replacement for weak symbols Date: Tue, 13 Mar 2018 13:59:34 -0700 Message-Id: <20180313205945.245105-17-thgarnie@google.com> X-Mailer: git-send-email 2.16.2.660.g709887971b-goog In-Reply-To: <20180313205945.245105-1-thgarnie@google.com> References: <20180313205945.245105-1-thgarnie@google.com> X-Virus-Scanned: ClamAV using ClamSMTP Provide an option to have a PROVIDE_HIDDEN (linker script) entry for each weak symbol. This option solve an error in x86_64 where the linker optimizes pie generate code to be non-pie because --emit-relocs was used instead of -pie (to reduce dynamic relocations). Signed-off-by: Thomas Garnier --- init/Kconfig | 7 +++++++ scripts/link-vmlinux.sh | 14 ++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/init/Kconfig b/init/Kconfig index c924babc6d47..fe9f9ada4db0 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -1927,6 +1927,13 @@ config ASN1 inform it as to what tags are to be expected in a stream and what functions to call on what tags. +config WEAK_PROVIDE_HIDDEN + bool + help + Generate linker script PROVIDE_HIDDEN entries for all weak symbols. It + allows to prevent non-pie code being replaced by the linker if the + emit-relocs option is used instead of pie (useful for x86_64 pie). + source "kernel/Kconfig.locks" config ARCH_HAS_SYNC_CORE_BEFORE_USERMODE diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh index 08ca08e9105c..c015f5142ecf 100755 --- a/scripts/link-vmlinux.sh +++ b/scripts/link-vmlinux.sh @@ -146,6 +146,17 @@ kallsyms() ${CC} ${aflags} -c -o ${2} ${afile} } +gen_weak_provide_hidden() +{ + if [ -n "${CONFIG_WEAK_PROVIDE_HIDDEN}" ]; then + local pattern="s/^\s\+ w \(\w\+\)$/PROVIDE_HIDDEN(\1 = .);/gp" + echo -e "SECTIONS {\n. = _end;" > .tmp_vmlinux_hiddenld + ${NM} ${1} | sed -n "${pattern}" >> .tmp_vmlinux_hiddenld + echo "}" >> .tmp_vmlinux_hiddenld + LDFLAGS_vmlinux="${LDFLAGS_vmlinux} -T .tmp_vmlinux_hiddenld" + fi +} + # Create map file with all symbols from ${1} # See mksymap for additional details mksysmap() @@ -230,6 +241,9 @@ modpost_link vmlinux.o # modpost vmlinux.o to check for section mismatches ${MAKE} -f "${srctree}/scripts/Makefile.modpost" vmlinux.o +# Generate weak linker script +gen_weak_provide_hidden vmlinux.o + kallsymso="" kallsyms_vmlinux="" if [ -n "${CONFIG_KALLSYMS}" ]; then