From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by sourceware.org (Postfix) with ESMTPS id DB3233858D32 for ; Mon, 8 May 2023 14:08:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DB3233858D32 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 0ACE91FF43 for ; Mon, 8 May 2023 14:08:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1683554890; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=AZpLN6HCPqLr558ZO0RG8010clgrwjHRM48jyrwtNdI=; b=TcoLsl8jA3f+p9qrfLxd2jiccHwKS6NG3NEaEPe2am9bLLcKjJ/SwVRg1DUGtgpldpSa7B Q0aQe4EjXaRwoU24GoH0vgmDOU5/t6/OBDoKYuwUhBM5msBeC7rA29INHibN9Ux3oUQgck eOGabRGURp4X7ct/dr9X09dYSCf9zcY= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1683554890; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=AZpLN6HCPqLr558ZO0RG8010clgrwjHRM48jyrwtNdI=; b=yemDe0HyscQ0pRUqvmFE995Ha9t1PFG4OgvTz3W5vaSPoPn8y4n4C/cmwo8x0YJ8kwq5Uy 7M/5Es1a+iHxkiBw== Received: from hawking.suse.de (unknown [10.168.4.11]) by relay2.suse.de (Postfix) with ESMTP id F3D062C141 for ; Mon, 8 May 2023 14:08:09 +0000 (UTC) Received: by hawking.suse.de (Postfix, from userid 17005) id E6E024A039C; Mon, 8 May 2023 16:08:09 +0200 (CEST) From: Andreas Schwab To: libc-alpha@sourceware.org Subject: [PATCH] dlopen: skip debugger notification for DSO loaded from sprof (bug 30258) X-Yow: .. Now I think I just reached the state of HYPERTENSION that comes JUST BEFORE you see the TOTAL at the SAFEWAY CHECKOUT COUNTER! Date: Mon, 08 May 2023 16:08:09 +0200 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-9.1 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Avoid inconsistent state in the debugger interface. --- elf/Makefile | 11 +++++++++++ elf/dl-load.c | 4 ++++ elf/tst-sprof-basic.c | 25 +++++++++++++++++++++++++ elf/tst-sprof-basic.sh | 41 +++++++++++++++++++++++++++++++++++++++++ elf/tst-sprof-mod.c | 24 ++++++++++++++++++++++++ 5 files changed, 105 insertions(+) create mode 100644 elf/tst-sprof-basic.c create mode 100755 elf/tst-sprof-basic.sh create mode 100644 elf/tst-sprof-mod.c diff --git a/elf/Makefile b/elf/Makefile index 396ec51424..4e98c9c1ea 100644 --- a/elf/Makefile +++ b/elf/Makefile @@ -509,6 +509,7 @@ tests-container += \ # tests-container test-srcs = \ + tst-sprof-basic \ tst-pathopt \ # tests-srcs @@ -861,6 +862,7 @@ modules-names += \ tst-sonamemove-linkmod1 \ tst-sonamemove-runmod1 \ tst-sonamemove-runmod2 \ + tst-sprof-mod \ tst-tls19mod1 \ tst-tls19mod2 \ tst-tls19mod3 \ @@ -1113,6 +1115,7 @@ ifeq ($(run-built-tests),yes) tests-special += \ $(objpfx)argv0test.out \ $(objpfx)tst-pathopt.out \ + $(objpfx)tst-sprof-basic.out \ $(objpfx)tst-rtld-help.out \ $(objpfx)tst-rtld-load-self.out \ $(objpfx)tst-rtld-preload.out \ @@ -2986,3 +2989,11 @@ tst-audit-tlsdesc-dlopen-ENV = LD_AUDIT=$(objpfx)tst-auditmod-tlsdesc.so $(objpfx)tst-dlmopen-twice.out: \ $(objpfx)tst-dlmopen-twice-mod1.so \ $(objpfx)tst-dlmopen-twice-mod2.so + +LDFLAGS-tst-sprof-mod.so = -Wl,-soname,tst-sprof-mod.so +$(objpfx)tst-sprof-basic: $(objpfx)tst-sprof-mod.so +$(objpfx)tst-sprof-basic.out: tst-sprof-basic.sh $(objpfx)tst-sprof-basic + $(SHELL) $< $(common-objpfx) '$(test-wrapper-env)' \ + '$(run-program-env)' > $@; \ + $(evaluate-test) +generated += tst-sprof-mod.so.profile diff --git a/elf/dl-load.c b/elf/dl-load.c index 9a0e40c0e9..39c63ff1b3 100644 --- a/elf/dl-load.c +++ b/elf/dl-load.c @@ -1483,6 +1483,10 @@ cannot enable executable stack as shared object requires"); /* Now that the object is fully initialized add it to the object list. */ _dl_add_to_namespace_list (l, nsid); + /* Skip auditing and debugger notification when called from 'sprof'. */ + if (mode & __RTLD_SPROF) + return l; + /* Signal that we are going to add new objects. */ struct r_debug *r = _dl_debug_update (nsid); if (r->r_state == RT_CONSISTENT) diff --git a/elf/tst-sprof-basic.c b/elf/tst-sprof-basic.c new file mode 100644 index 0000000000..5e4083305a --- /dev/null +++ b/elf/tst-sprof-basic.c @@ -0,0 +1,25 @@ +/* Copyright (C) 2023 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 hello (void); + +int +main (void) +{ + hello (); + return 0; +} diff --git a/elf/tst-sprof-basic.sh b/elf/tst-sprof-basic.sh new file mode 100755 index 0000000000..901db61708 --- /dev/null +++ b/elf/tst-sprof-basic.sh @@ -0,0 +1,41 @@ +#!/bin/sh +# Test basic functionality of sprof +# Copyright (C) 2023 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 + +common_objpfx=$1 +test_wrapper_env=$2 +run_program_env=$3 + +sprof_mod=tst-sprof-mod.so + +${test_wrapper_env} \ +${run_program_env} \ +LD_PROFILE=$sprof_mod \ +LD_PROFILE_OUTPUT=${common_objpfx}elf \ +LD_LIBRARY_PATH=${common_objpfx}.:${common_objpfx}elf \ + ${common_objpfx}elf/ld.so ${common_objpfx}elf/tst-sprof-basic + +${test_wrapper_env} \ +${run_program_env} \ +LD_LIBRARY_PATH=${common_objpfx}.:${common_objpfx}elf \ + ${common_objpfx}elf/ld.so ${common_objpfx}elf/sprof -p $sprof_mod \ + ${common_objpfx}elf/${sprof_mod}.profile + +exit $? diff --git a/elf/tst-sprof-mod.c b/elf/tst-sprof-mod.c new file mode 100644 index 0000000000..8b3f5e8e07 --- /dev/null +++ b/elf/tst-sprof-mod.c @@ -0,0 +1,24 @@ +/* Copyright (C) 2023 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 + . */ + +#include + +void +hello (void) +{ + printf ("Hello World\n"); +} -- 2.40.1 -- Andreas Schwab, SUSE Labs, schwab@suse.de GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE 1748 E4D4 88E3 0EEA B9D7 "And now for something completely different."