From patchwork Wed May 23 19:54:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Garnier X-Patchwork-Id: 10422285 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 355346032A for ; Wed, 23 May 2018 19:59:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 212F528CD4 for ; Wed, 23 May 2018 19:59:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1182528CBF; Wed, 23 May 2018 19:59:25 +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=-12.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, USER_IN_DEF_DKIM_WL 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 E087E28CBF for ; Wed, 23 May 2018 19:59:23 +0000 (UTC) Received: (qmail 24143 invoked by uid 550); 23 May 2018 19:56:00 -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 24043 invoked from network); 23 May 2018 19:55:55 -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=Lpe6msBXPMqx+zdvvTWhyiRIH4wvEMEqExpHKXjTtpI=; b=TLH2bukWSP1YE7OTJmDOlr8aMzY1LF/dHHdLvUq1S8bOSDHWGvINdcy9vx7HOrngmR v1bcupowaUbpzbooODzv9g9k+RzUah/AyyhVMqw1LvKDpvQ7Io5gjtrWi3UoSsyhjDcI q51FJ1kflrZ6HFrlywY2rcx16ZKQrhxLhpLUIJk90LVqqXDZ2YbCrqf8CQzfjnTioU5q qYtO5FqG15HZnkX8ocnMKxuIsqkZZmsFs1xZNfc7Ck4PGa+T//rYJ1toP6jb308y/xzo bzTzleKf8siKl+C1+WbAzi65cDFjxx0JstKADL6lnGToJKjP1Fsr+NLLOQXrlqhOk8kC 8pfw== 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=Lpe6msBXPMqx+zdvvTWhyiRIH4wvEMEqExpHKXjTtpI=; b=NMe+5jPIq20L6Ay+VXZI+NBufyB1c0DVqiarvD+kW1xp2JufjhMQHPWyd0mg/K8WXv qQ43ijWkwFJ35IAZpuZ32SJxD8CtvUngdL8p1RCg7URwVrWtsTHPOLCB7in9KKHiVhF7 QPBXtYYAGOP2jKnzTo4rBKsU7iSYGvaxK/4nChooXPGIQdgd4t6nsWSsGVjCcz0dJrrK WPiou5XFkx1SmDdBp6A0AUI24actX0FFTI1TF1EfzYxPcAMc4pz4M5l7jkrUnvVlD8ZD d49ntJ4ji96aMmWoqwzSf/fApBsuvp7YYmue4uRUq5PB2/uZMUS5Fm58N45jv8x6uaOp osTQ== X-Gm-Message-State: ALKqPwc/m4H8oN7JveN9tr4BAzG5oOB6LRG9qB1GBgrragdr3vl91C7Z BGH2Qt6f+0axjIUJ5o1wYzH1mw== X-Google-Smtp-Source: AB8JxZoLsB0/2S070mh7DlkvFnttkufDh7TDyrBg24fiSAQa0FYf6O3xmUWP5HmystEzh72E0ie0cA== X-Received: by 2002:a17:902:988b:: with SMTP id s11-v6mr4245551plp.304.1527105343117; Wed, 23 May 2018 12:55:43 -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 , Thomas Garnier , Philippe Ombredanne , Kate Stewart , Arnaldo Carvalho de Melo , Yonghong Song , Andrey Ryabinin , 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 , Jan Kiszka , Tejun Heo , Christoph Lameter , Dennis Zhou , Boris Ostrovsky , Alexey Dobriyan , Masami Hiramatsu , Cao jin , Francis Deslauriers , "Paul E . McKenney" , Nicolas Pitre , Andrew Morton , Randy Dunlap , "Luis R . Rodriguez" , Arnd Bergmann , Christopher Li , Jason Baron , Mika Westerberg , Lukas Wunner , Dou Liyang , Sergey Senozhatsky , Petr Mladek , Masahiro Yamada , Ingo Molnar , Nicholas Piggin , "H . J . Lu" , Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , Joerg Roedel , David Woodhouse , Dave Hansen , Rik van Riel , Jia Zhang , Ricardo Neri , Jonathan Corbet , Jan Beulich , Matthias Kaehlcke , Baoquan He , =?UTF-8?q?Jan=20H=20=2E=20Sch=C3=B6nherr?= , Daniel Micay 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 v3 16/27] compiler: Option to add PROVIDE_HIDDEN replacement for weak symbols Date: Wed, 23 May 2018 12:54:10 -0700 Message-Id: <20180523195421.180248-17-thgarnie@google.com> X-Mailer: git-send-email 2.17.0.441.gb46fe60e1d-goog In-Reply-To: <20180523195421.180248-1-thgarnie@google.com> References: <20180523195421.180248-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 0fc3a58d9f2f..2866cca86b4a 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -1954,6 +1954,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 4bf811c09f59..f5d31119b9d7 100755 --- a/scripts/link-vmlinux.sh +++ b/scripts/link-vmlinux.sh @@ -142,6 +142,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() @@ -226,6 +237,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