From patchwork Tue Oct 4 18:46:21 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 678188 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3spSYr5hYGz9sBr for ; Wed, 5 Oct 2016 05:46:40 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b=JL292z3f; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:to:subject:message-id:reply-to :mime-version:content-type; q=dns; s=default; b=F18dhk4bFYvluQ+e U+DABnKCRvEQqRCfkLTnm2GpWuNyWFfCc4SSs4RPlt/YtY0u6pDs1FMCh2U+kNOr o9EVXoZa9Kp4pJYnW1IOMxHiXge6c2CR1PgAPhejrH8xm/CGYcMw2/bOLQysQnNd 6dUootPS1EQwEaYrVBvMeMUouU4= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:to:subject:message-id:reply-to :mime-version:content-type; s=default; bh=QAGdbqoDsha6BybT58kkdu Ncv9o=; b=JL292z3fATAtjN4JZ0L77Wq/mQZvHcj1F864bOkmF8aDf2oXf4ikeA 6EsUFZsuMshWdTOj/32uldU11hBRpOQJ6yr+ONWnBqtMCLYojLWXYsTGm59JZRfh ByBuIw9Ednd3XveGZPn4Ww1HzdN1LCKgzlJOgn1HuseUq3ZteeXso= Received: (qmail 106236 invoked by alias); 4 Oct 2016 18:46:34 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 105850 invoked by uid 89); 4 Oct 2016 18:46:33 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.3 required=5.0 tests=AWL, BAYES_00, KAM_LAZY_DOMAIN_SECURITY, NO_DNS_FOR_FROM, RCVD_IN_DNSWL_NONE, RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy= X-HELO: mga04.intel.com X-ExtLoop1: 1 Date: Tue, 4 Oct 2016 11:46:21 -0700 From: "H.J. Lu" To: GNU C Library Subject: [PATCH 2/2] Add an x86 IFUNC testcase for [BZ #20019] Message-ID: <20161004184621.GB27454@intel.com> Reply-To: "H.J. Lu" MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.7.0 (2016-08-17) If an IFUNC function is called before the providing shared library is unrelocated, ld.so may segfault. Add a testcase to verify that ld.so will issue a diagnostic and won't segfault in this case. Tested on i686 and x86-64. OK for master? H.J. --- [BZ #20019] * sysdeps/x86/Makefile (tests): Add tst-ifunc1. (tests-special): Add $(objpfx)tst-ifunc1.out. ($(objpfx)tst-ifunc1.out): New rule. (extra-test-objs): Add tst-ifunc1 objects. ($(objpfx)tst-ifunc1): New. ($(objpfx)tst-ifuncmod1a.so): New rule. ($(objpfx)tst-ifuncmod1b.so): LIkewise. ($(objpfx)tst-ifuncmod1a.os): LIkewise. ($(objpfx)tst-ifuncmod1b.os): LIkewise. * sysdeps/x86/tst-ifunc1.c: New file. * sysdeps/x86/tst-ifunc1.sh: LIkewise. * sysdeps/x86/tst-ifuncmod1a.c: LIkewise. * sysdeps/x86/tst-ifuncmod1b.c: LIkewise. --- sysdeps/x86/Makefile | 25 +++++++++++++++++++++++++ sysdeps/x86/tst-ifunc1.c | 26 ++++++++++++++++++++++++++ sysdeps/x86/tst-ifunc1.sh | 35 +++++++++++++++++++++++++++++++++++ sysdeps/x86/tst-ifuncmod1a.c | 27 +++++++++++++++++++++++++++ sysdeps/x86/tst-ifuncmod1b.c | 23 +++++++++++++++++++++++ 5 files changed, 136 insertions(+) create mode 100644 sysdeps/x86/tst-ifunc1.c create mode 100755 sysdeps/x86/tst-ifunc1.sh create mode 100644 sysdeps/x86/tst-ifuncmod1a.c create mode 100644 sysdeps/x86/tst-ifuncmod1b.c diff --git a/sysdeps/x86/Makefile b/sysdeps/x86/Makefile index 0d0326c2..6907b46 100644 --- a/sysdeps/x86/Makefile +++ b/sysdeps/x86/Makefile @@ -7,4 +7,29 @@ sysdep-dl-routines += dl-get-cpu-features tests += tst-get-cpu-features tests-static += tst-get-cpu-features-static + +ifeq ($(build-shared),yes) +tests += tst-ifunc1 +tests-special += $(objpfx)tst-ifunc1.out +$(objpfx)tst-ifunc1.out: ../sysdeps/x86/tst-ifunc1.sh $(objpfx)tst-ifunc1 + $(BASH) $< $(objpfx) '$(test-via-rtld-prefix)' \ + '$(test-wrapper-env)' '$(run-program-env)'; \ + $(evaluate-test) + +# Since tst-ifuncmod1a.so and tst-ifuncmod1b.so aren't linked against +# libc.so, use special rules to build them. +extra-test-objs += tst-ifunc1 tst-ifuncmod1a.os tst-ifuncmod1b.os \ + tst-ifuncmod1a.os tst-ifuncmod1b.os + +$(objpfx)tst-ifunc1: $(objpfx)tst-ifuncmod1a.so +$(objpfx)tst-ifuncmod1a.so: $(objpfx)tst-ifuncmod1a.os \ + $(objpfx)tst-ifuncmod1b.so + $(CC) -Wl,-z,now -shared -nostdlib -nostartfiles -o $@ $^ +$(objpfx)tst-ifuncmod1b.so: $(objpfx)tst-ifuncmod1b.os + $(CC) -Wl,-z,now -shared -nostdlib -nostartfiles -o $@ $^ +$(objpfx)tst-ifuncmod1a.os: ../sysdeps/x86/tst-ifuncmod1a.c + $(CC) -fPIC -c -o $@ $^ +$(objpfx)tst-ifuncmod1b.os: ../sysdeps/x86/tst-ifuncmod1b.c + $(CC) -fPIC -c -o $@ $^ +endif endif diff --git a/sysdeps/x86/tst-ifunc1.c b/sysdeps/x86/tst-ifunc1.c new file mode 100644 index 0000000..735153f --- /dev/null +++ b/sysdeps/x86/tst-ifunc1.c @@ -0,0 +1,26 @@ +/* Test case for x86 IFUNC. + Copyright (C) 2016 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +extern void foo (void); + +int +main (void) +{ + foo (); + return 0; +} diff --git a/sysdeps/x86/tst-ifunc1.sh b/sysdeps/x86/tst-ifunc1.sh new file mode 100755 index 0000000..5f5afe0 --- /dev/null +++ b/sysdeps/x86/tst-ifunc1.sh @@ -0,0 +1,35 @@ +#!/bin/bash +# An x86 IFUNC test. +# Copyright (C) 2016 Free Software Foundation, Inc. +# This file is part of the GNU C Library. + +# The GNU C Library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. + +# The GNU C Library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. + +# You should have received a copy of the GNU Lesser General Public +# License along with the GNU C Library; if not, see +# . + +set -e + +objpfx=$1; shift +test_via_rtld_prefix=$1; shift +test_wrapper_env=$1; shift +run_program_env=$1; shift +logfile=${objpfx}tst-ifunc1.out + +> $logfile +fail=0 + +${test_wrapper_env} \ +${run_program_env} \ +${objpfx}tst-ifunc1 2>&1 | grep Relink >> $logfile || fail=1 + +exit $fail diff --git a/sysdeps/x86/tst-ifuncmod1a.c b/sysdeps/x86/tst-ifuncmod1a.c new file mode 100644 index 0000000..a1c27ed --- /dev/null +++ b/sysdeps/x86/tst-ifuncmod1a.c @@ -0,0 +1,27 @@ +/* Test case for x86 IFUNC. + Copyright (C) 2016 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +void bar (void *dst, void *src); + +void +foo (void) +{ + char dst[50]; + char src[50]; + bar (dst, src); +} diff --git a/sysdeps/x86/tst-ifuncmod1b.c b/sysdeps/x86/tst-ifuncmod1b.c new file mode 100644 index 0000000..e6e9e9b --- /dev/null +++ b/sysdeps/x86/tst-ifuncmod1b.c @@ -0,0 +1,23 @@ +/* Test case for x86 IFUNC. + Copyright (C) 2016 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +void +bar (void *dst, void *src) +{ + __builtin_memmove (dst, src, 40); +}