From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: ARC-Seal: i=1; a=rsa-sha256; t=1520974849; cv=none; d=google.com; s=arc-20160816; b=AzGg18UYpx0yr4U4VcwmgXqPAtVS8cwaxBEJcpKdE7/KH5aoSFwup7XbAFt7IEWudh fvvIBGyXku0O5W+V0CRWtXu+Bzxfu9CMy0slgCATosQq9KiyjSTynrELOCQ4SAOaiFX5 OP/Npumm3YIt8CAbvU4mmWqGYmsC2wOwQd1B2xAMs7HIP6kjswExBn46flpHlrRGK6aw 4iV3FgKIRBzfJ6jUjxMcnzOekEpF3F+A+omxxuuWIFjCgUd6qZuFEMI+3rFvrlIo3T1+ g1g05eT+hxtxFuCvMS8+7p70Xup5iREJnoSfZnIC2Rn8LFdU4MN+5oTvTw2/zsZwLOvl w2+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=1pv1TCYX38Prk84i54e1XzmGAYVvBJdF3eg5DouhUXg=; b=incHjjj3KpiXaqN+mmax3PsKs+CgftV+avcvn0nawUXwNnEfh/6u0B+krCY2ijxJmQ Q2iy7FNW0qt7OmZqjllU5odFvMLPdG+Y4zDhiuoP4Z4UvA7CYpX9ht1X8BmMruN7/djQ dpbS4zqFzQ6MZdZTIVG4td5eLmSmILOv546KNC0KrhEIBkkpdeQb6iFLBxieZ+WSpo29 m9fijepJwaWa/IGg3TE5SJVzi9xfzcqhJaKPP1C5SdgWqfKBauhWdriJlSzClYl34QRt DFdDLb/7TgS+KKharrFQPGxOo22ZgYN9BPq/Rh+3QnwJHSJIVPjeL/O5KGaSZ5p5maca zyEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Ib/hdzeF; spf=pass (google.com: domain of thgarnie@google.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=thgarnie@google.com; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Ib/hdzeF; spf=pass (google.com: domain of thgarnie@google.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=thgarnie@google.com; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com X-Google-Smtp-Source: AG47ELvC9ii+0/P5pnq3bQVzPZktfrjo0njQPAjbs124XCd7nqJi9aJQE++F1ji5jf2JIUoOXxyDTw== 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-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: =?utf-8?q?1594857723684834572?= X-GMAIL-MSGID: =?utf-8?q?1594857723684834572?= X-Mailing-List: linux-kernel@vger.kernel.org List-ID: 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 -- 2.16.2.660.g709887971b-goog