From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oi1-x22f.google.com (mail-oi1-x22f.google.com [IPv6:2607:f8b0:4864:20::22f]) by sourceware.org (Postfix) with ESMTPS id ED4783858419 for ; Fri, 4 Mar 2022 12:00:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org ED4783858419 Received: by mail-oi1-x22f.google.com with SMTP id s5so7587089oic.10 for ; Fri, 04 Mar 2022 04:00:59 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=PZ9XuDzYyOb5vGd8qSRnUCowugXPByKRHXYHlh8/J4M=; b=KNQCWJVFj+IgCa5Z86KNcvHyUUsImE3tUNZhuP3t/d6hENFtgwOMDLztesHkWQPstf ZtbHjdu/F6WvHu2xw9Gqzhrwkjed/w1v1j59/c8kqjjx2uYAc1DKgR365p4YJWeMod7o CXHKPGMb2UgMIh/c8C8ziGarRx8ajbv2LleGWPuNpg97zw4Ek765qpFMmM0B5E7pfXxi 0WZwkbozvlMcv6xTfSAng9eUT0DIUdHRqgXcrfcyIt72AahM/fDq/ZYpIVrfeZE+qHC3 2ecLB9qcFRABC67iQ3z7/WNrv5BIv1GMC3lGS+0brKISKmgJb18GN1hfN7+dlGhiAS6w vDQw== X-Gm-Message-State: AOAM532iw98ZB3YIsVslNxR1tMt8NXfFB9I1oUXbgz3eYFtM9V1p3tNE cnZoZAQlcKu7Lzq8IvTKGIFuznttPAZxGQ== X-Google-Smtp-Source: ABdhPJzGB8USmCq3V/liiG5WJ/hArQlB6EtR9o8ms2eFi38pBMpJ5Gr7RBizZDe0gYmWH3GzKe4rkw== X-Received: by 2002:a05:6808:13ca:b0:2d0:6e82:6983 with SMTP id d10-20020a05680813ca00b002d06e826983mr8961214oiw.5.1646395259209; Fri, 04 Mar 2022 04:00:59 -0800 (PST) Received: from ?IPV6:2804:431:c7ca:2dcb:a992:742c:8048:43bc? ([2804:431:c7ca:2dcb:a992:742c:8048:43bc]) by smtp.gmail.com with ESMTPSA id r9-20020a056870e8c900b000d7133a15b3sm2225482oan.20.2022.03.04.04.00.57 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 04 Mar 2022 04:00:58 -0800 (PST) Message-ID: Date: Fri, 4 Mar 2022 09:00:55 -0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.6.1 Subject: Re: [PATCH v3] elf: Fix DFS sorting algorithm for LD_TRACE_LOADED_OBJECTS with missing libraries (BZ #28868) Content-Language: en-US To: Florian Weimer Cc: libc-alpha@sourceware.org References: <20220222141059.1142890-1-adhemerval.zanella@linaro.org> <87pmnavp0g.fsf@oldenburg.str.redhat.com> From: Adhemerval Zanella In-Reply-To: <87pmnavp0g.fsf@oldenburg.str.redhat.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 04 Mar 2022 12:01:01 -0000 On 25/02/2022 14:23, Florian Weimer wrote: > * Adhemerval Zanella: > >> diff --git a/elf/Makefile b/elf/Makefile >> index bff94954c9..6e9c7c7167 100644 >> --- a/elf/Makefile >> +++ b/elf/Makefile > >> @@ -1071,6 +1074,11 @@ tests-special += \ >> $(objpfx)tst-initorder2-cmp.out \ >> $(objpfx)tst-unused-dep-cmp.out \ >> $(objpfx)tst-unused-dep.out \ >> + $(objpfx)tst-trace1.out \ >> + $(objpfx)tst-trace2.out \ >> + $(objpfx)tst-trace3.out \ >> + $(objpfx)tst-trace4.out \ >> + $(objpfx)tst-trace5.out \ >> # tests-special >> endif > > This is covered by $(run-built-tests); good. > >> @@ -2717,3 +2725,51 @@ $(objpfx)tst-p_align3: $(objpfx)tst-p_alignmod3.so >> $(objpfx)tst-p_align3.out: tst-p_align3.sh $(objpfx)tst-p_align3 >> $(SHELL) $< $(common-objpfx) '$(test-program-prefix)'; \ >> $(evaluate-test) >> + >> + >> +libtracemod-suffixes = 1 2 3 4 5 >> +# Move the library to a folder so it can be selected by --library-path >> +define libtracemod-mv >> + test -d $(objpfx)libtracemod$(1) || mkdir $(objpfx)libtracemod$(1) >> + test -f $(objpfx)libtracemod$(1).so \ >> + && mv $(objpfx)libtracemod$(1).so $(objpfx)libtracemod$(1) >> +endef >> +libtracemod-mv: $(objpfx)libtracemod1.so >> + $(call libtracemod-mv,2) >> + $(call libtracemod-mv,3) >> + $(call libtracemod-mv,4) >> + $(call libtracemod-mv,5) > > .PHONY: libtracemod-mv? Ack. > > Why do you have to use mv? Would cp more reliable? The library must be present only on the specified folder, since the base directory will used as well for tst-trace1. > >> +LDFLAGS-libtracemod1.so = -Wl,--no-as-needed \ >> + -L$(objpfx) -ltracemod2 -ltracemod3 >> +LDFLAGS-libtracemod2.so = -Wl,--no-as-needed \ >> + -L$(objpfx) -ltracemod4 -ltracemod5 >> +$(objpfx)libtracemod1.so: $(objpfx)libtracemod2.so \ >> + $(objpfx)libtracemod3.so >> + $(build-module-no-module-objlist) >> +$(objpfx)libtracemod2.so: $(objpfx)libtracemod4.so \ >> + $(objpfx)libtracemod5.so >> + $(build-module-no-module-objlist) > > I think I get now what you meant by embedding the full path. I think we > generally avoid that by setting a soname with -Wl,--soname=. Then the > link editor will use the soname instead of the path. This way, no -L > hackery with separate directories is necessary at build time. > > I think libmarkermod* would be a better model here. Yeah, it is simpler. I will change to use -soname. > >> diff --git a/elf/dl-deps.c b/elf/dl-deps.c >> index a2fc278256..2e3e739c5b 100644 >> --- a/elf/dl-deps.c >> +++ b/elf/dl-deps.c >> @@ -473,6 +473,8 @@ _dl_map_object_deps (struct link_map *map, >> >> for (nlist = 0, runp = known; runp; runp = runp->next) >> { >> + /* _dl_sort_maps ignores l_faked object, so it is save to not considere >> + them for nlist. */ >> if (__builtin_expect (trace_mode, 0) && runp->map->l_faked) >> /* This can happen when we trace the loading. */ >> --map->l_searchlist.r_nlist; > > Typo: sa[f]e > Ack. >> diff --git a/elf/dl-sort-maps.c b/elf/dl-sort-maps.c >> index 9e9d53ec47..2ed62da7dd 100644 >> --- a/elf/dl-sort-maps.c >> +++ b/elf/dl-sort-maps.c >> @@ -140,7 +140,9 @@ static void >> dfs_traversal (struct link_map ***rpo, struct link_map *map, >> bool *do_reldeps) >> { >> - if (map->l_visited) >> + /* _dl_map_object_deps filter l_faked objects when calculating the >> + number of maps before calling _dl_sort_maps, ignore them as well. */ >> + if (map->l_visited || map->l_faked) >> return; > > Typo: filter[s] (?) Ack.