From patchwork Wed Oct 5 18:16:39 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: 16282 Received: (qmail 108991 invoked by alias); 5 Oct 2016 18:16:54 -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 108971 invoked by uid 89); 5 Oct 2016 18:16:53 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.1 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, RCVD_IN_SORBS_SPAM, SPF_PASS, URIBL_RED autolearn=ham version=3.3.2 spammy=run-built-tests, tests-special, yes, $, testsspecial X-HELO: mail-qk0-f196.google.com X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=WPiaun5nD8AQtGrIoSxssSjJByOeVnjEIEOEpi6n41Q=; b=cRAaZ0k2QAvIoTWCz2qYSJT+q+8rtMUdRnJ9AF2KGFbygM8JJou5KTQpf3bffQRqso n3zWosyYxQu4w0+iVOrmPBG48Wm8dZbK/JyKiFaXirseCvEIp52itAEJFzvdN4WWyggd KenfhQrxJbeiXL5Babec+sPXVIPbJvv6ae7PTMrrhtLTvn/BG4F9Xiq8R2k/thumR3za 3SzUBuz+tq5LO4w5J0xzOZGo0pBwrTNUicDNH94dRWp0tIrXUoHb1Mubvys93MUwQ8eF aNnGZp/LoDWu8/JPxN4wkvhYApWVHKyozvRjjk8CNQFPBXIN+jOXYZbHt0cXU2IQegrE qm7w== X-Gm-Message-State: AA6/9RnNM12lltFfYCPPmGv5+Q2fgSoX9Ah/wgwAyhzzlPALFJYLfg40+Yo8OAq+hPIc4zHOF8VBXPI3rpyHGw== X-Received: by 10.55.209.26 with SMTP id s26mr9658443qki.24.1475691401216; Wed, 05 Oct 2016 11:16:41 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: References: <20161004184621.GB27454@intel.com> From: "H.J. Lu" Date: Wed, 5 Oct 2016 11:16:39 -0700 Message-ID: Subject: Re: [PATCH 2/2] Add an x86 IFUNC testcase for [BZ #20019] To: Joseph Myers Cc: GNU C Library On Tue, Oct 4, 2016 at 5:09 PM, Joseph Myers wrote: > On Wed, 5 Oct 2016, H.J. Lu wrote: > >> I can try __builtin_memcpy, instread of __builtin_memmove. There are 2 I changed it to use __builtin_memset. >> acceptable results. One is ld.so issues an error and the other is program runs. >> On x86, ld.so issues an error. I don't know what should happen on others. > > You could make the test pass on either of those results (while failing if > ld.so crashes). > I moved the test to elf. It passes if the test runs or ld.so issues an error. Please try it on arm, powerpc and s390. From 45fa40391e8e46ccfe3fde6120671e638f54ed45 Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Tue, 4 Oct 2016 11:29:55 -0700 Subject: [PATCH] Add an IFUNC testcase for [BZ #20019] If an IFUNC function is called before the providing shared library is unrelocated, ld.so may segfault. Add a testcase to verify that the program won't segfault. It should either run or ld.so issues a diagnostic. [BZ #20019] * elf/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. * elf/tst-ifunc1.c: New file. * elf/tst-ifunc1.sh: LIkewise. * elf/tst-ifuncmod1a.c: LIkewise. * elf/tst-ifuncmod1b.c: LIkewise. --- elf/Makefile | 26 ++++++++++++++++++++++++++ elf/tst-ifunc1.c | 26 ++++++++++++++++++++++++++ elf/tst-ifunc1.sh | 43 +++++++++++++++++++++++++++++++++++++++++++ elf/tst-ifuncmod1a.c | 26 ++++++++++++++++++++++++++ elf/tst-ifuncmod1b.c | 23 +++++++++++++++++++++++ 5 files changed, 144 insertions(+) create mode 100644 elf/tst-ifunc1.c create mode 100755 elf/tst-ifunc1.sh create mode 100644 elf/tst-ifuncmod1a.c create mode 100644 elf/tst-ifuncmod1b.c diff --git a/elf/Makefile b/elf/Makefile index caffd92..6a5eaf0 100644 --- a/elf/Makefile +++ b/elf/Makefile @@ -329,6 +329,11 @@ $(objpfx)tst-_dl_addr_inside_object: $(objpfx)dl-addr-obj.os CFLAGS-tst-_dl_addr_inside_object.c += $(PIE-ccflag) endif +ifeq ($(run-built-tests)$(build-shared),yesyes) +tests += tst-ifunc1 +tests-special += $(objpfx)tst-ifunc1.out +endif + include ../Rules ifeq (yes,$(build-shared)) @@ -965,6 +970,27 @@ CFLAGS-tst-pie2.c += $(pie-ccflag) $(objpfx)tst-pie1: $(objpfx)tst-piemod1.so +$(objpfx)tst-ifunc1.out: 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: tst-ifuncmod1a.c + $(CC) -fPIC -c -o $@ $< +$(objpfx)tst-ifuncmod1b.os: tst-ifuncmod1b.c + $(CC) -fPIC -c -o $@ $< + ifeq (yes,$(build-shared)) all-built-dso := $(common-objpfx)elf/ld.so $(common-objpfx)libc.so \ $(filter-out $(common-objpfx)linkobj/libc.so, \ diff --git a/elf/tst-ifunc1.c b/elf/tst-ifunc1.c new file mode 100644 index 0000000..d6a54aa --- /dev/null +++ b/elf/tst-ifunc1.c @@ -0,0 +1,26 @@ +/* Test case for 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/elf/tst-ifunc1.sh b/elf/tst-ifunc1.sh new file mode 100755 index 0000000..7152d79 --- /dev/null +++ b/elf/tst-ifunc1.sh @@ -0,0 +1,43 @@ +#!/bin/bash +# An 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 || fail=1 + +if test $fail = 1; then + # If it fails to run, check for the expected error from ld.so. + fail=0 + ${test_wrapper_env} \ + ${run_program_env} \ + ${objpfx}tst-ifunc1 2>&1 | grep Relink >> $logfile || fail=1 +fi + +exit $fail diff --git a/elf/tst-ifuncmod1a.c b/elf/tst-ifuncmod1a.c new file mode 100644 index 0000000..a5b818d --- /dev/null +++ b/elf/tst-ifuncmod1a.c @@ -0,0 +1,26 @@ +/* Test case for 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, unsigned int); + +void +foo (void) +{ + char dst[50]; + bar (dst, sizeof (dst)); +} diff --git a/elf/tst-ifuncmod1b.c b/elf/tst-ifuncmod1b.c new file mode 100644 index 0000000..b7a6315 --- /dev/null +++ b/elf/tst-ifuncmod1b.c @@ -0,0 +1,23 @@ +/* Test case for 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, unsigned int len) +{ + __builtin_memset (dst, 3, len); +} -- 2.7.4