From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 22F5CC433FE for ; Fri, 13 May 2022 23:06:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240537AbiEMXGW (ORCPT ); Fri, 13 May 2022 19:06:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59994 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242450AbiEMXGN (ORCPT ); Fri, 13 May 2022 19:06:13 -0400 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB8AC25559C for ; Fri, 13 May 2022 16:05:41 -0700 (PDT) Received: by mail-wm1-x32b.google.com with SMTP id o12-20020a1c4d0c000000b00393fbe2973dso7670217wmh.2 for ; Fri, 13 May 2022 16:05:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=mivRpjYlnos8QyfKIL0ZlkiTUotRjXBDBCX8TH+HQXY=; b=UdpAoUQiU4hPu5EZSLJ8meLqynbM8mfTp+3iZ4wqmp60lDxYlq+Dcw1+Ai9ZPbh8ZX U/Aq0aRqY/wfdxyeVYaddvYyhr6KOlKipGwchEWqzXXtwH+V1D/bwmimJaudRW74KvYi n7BcZtD0heaYjzouHmBVcq80K1BhxMVLRbJJK2vSosuf5Ngif2YKfjFcT51VRnKgunBb erAORUPdaJGYpkIL2cxy+KFLpeguRkmjCXl0VzUbty3RILRMx4FyPrKpl9iLwzRuXPaG 9alDHlC1KCZiMq7cx4G0Fojxg9XUTGxfcwoe93D6yJxceY2giRQBLPsIKFOVfUy+0kB4 ox2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=mivRpjYlnos8QyfKIL0ZlkiTUotRjXBDBCX8TH+HQXY=; b=Iqm8VZRZEsrm1Z/n2Kxo57xxe6oKsp5b6I3NtBw8ro+8ckH3qTbroBXK/cDsqONvV+ DQD/o2Y0rrdsskFiSmjf4QblRX7kubXAdzu62FkuEA024mrNdfWI0lgFGi0PZey4Ai1U Xbpi1R2+74N+ubnYiSEGoDJG4jkAoUHJbsLV4/kRYwo/E6zT/rNRaxi3Q7+o1nybrF8X KCMTVplY8Bqtus/H/rIV3DIjxuQJzznXGZyAUdndT1BEVXIIHGcy9HvdiHOQU9qNKmjO Qd72uHANid1HG+qQi4kfFiYo0uaWu9qjfAjrarcYKPoWbLyCgxUMkc2OhzHh+0bydg2I 6ytQ== X-Gm-Message-State: AOAM5326Gc3g6vvU78cgO4VyibqCnXM6NWzO2q1OHY/z0wP8C9gUEiiI vTniPJOxrvrDzrrzsgwoDVE3y4K6oCWxcsXeW6tXwg== X-Google-Smtp-Source: ABdhPJzikMn1ioZfFD/3RZTSrR9mKVOzqPyMJYhF22HzLQV38UOOS2ThlqrYZYhQ/gQg474rfsrRF934XUb40E0b8gU= X-Received: by 2002:a05:600c:4ecc:b0:394:790d:5f69 with SMTP id g12-20020a05600c4ecc00b00394790d5f69mr6625363wmq.196.1652483139965; Fri, 13 May 2022 16:05:39 -0700 (PDT) MIME-Version: 1.0 References: <20220513004117.364577-1-yosryahmed@google.com> In-Reply-To: From: Yosry Ahmed Date: Fri, 13 May 2022 16:05:03 -0700 Message-ID: Subject: Re: [PATCH bpf-next] selftests/bpf: fix building bpf selftests statically To: Andrii Nakryiko Cc: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Hao Luo , Networking , bpf , open list Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, May 13, 2022 at 3:57 PM Andrii Nakryiko wrote: > > On Thu, May 12, 2022 at 5:41 PM Yosry Ahmed wrote: > > > > bpf selftests can no longer be built with CFLAGS=-static with > > liburandom_read.so and its dependent target. > > > > Filter out -static for liburandom_read.so and its dependent target. > > > > Signed-off-by: Yosry Ahmed > > --- > > tools/testing/selftests/bpf/Makefile | 9 ++++++--- > > 1 file changed, 6 insertions(+), 3 deletions(-) > > > > diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile > > index 6bbc03161544..4eaefc187d5b 100644 > > --- a/tools/testing/selftests/bpf/Makefile > > +++ b/tools/testing/selftests/bpf/Makefile > > @@ -168,14 +168,17 @@ $(OUTPUT)/%:%.c > > $(call msg,BINARY,,$@) > > $(Q)$(LINK.c) $^ $(LDLIBS) -o $@ > > > > +# If the tests are being built statically, exclude dynamic libraries defined > > +# in this Makefile and their dependencies. > > +DYNAMIC_CFLAGS := $(filter-out -static,$(CFLAGS)) > > I don't particularly like yet another CFLAGS global variable, but also > you are not filtering out -static from LDFLAGS, which would be > problematic if you try to do > > make SAN_FLAGS=-static > > which otherwise would work (and is probably better than overriding all of CFLAGS > > How about something like this Yeah this looks good, thanks for pointing out the problem with LDFLAGS. > > diff --git a/tools/testing/selftests/bpf/Makefile > b/tools/testing/selftests/bpf/Makefile > index 6bbc03161544..2e8eddf240af 100644 > --- a/tools/testing/selftests/bpf/Makefile > +++ b/tools/testing/selftests/bpf/Makefile > @@ -170,11 +170,11 @@ $(OUTPUT)/%:%.c > > $(OUTPUT)/liburandom_read.so: urandom_read_lib1.c urandom_read_lib2.c > $(call msg,LIB,,$@) > - $(Q)$(CC) $(CFLAGS) -fPIC $(LDFLAGS) $^ $(LDLIBS) --shared -o $@ > + $(Q)$(CC) $(filter-out -static,$(CFLAGS) $(LDFLAGS)) $^ > $(LDLIBS) -fPIC -shared -o $@ > > $(OUTPUT)/urandom_read: urandom_read.c urandom_read_aux.c > $(OUTPUT)/liburandom_read.so > $(call msg,BINARY,,$@) > - $(Q)$(CC) $(CFLAGS) $(LDFLAGS) $(filter %.c,$^) \ > + $(Q)$(CC) $(filter-out -static,$(CFLAGS) $(LDFLAGS)) $(filter %.c,$^) \ > liburandom_read.so $(LDLIBS) \ > -Wl,-rpath=. -Wl,--build-id=sha1 -o $@ > > ? > > > But I also have a question, this leaves urandom_read relying on > system-wide shared libraries, isn't that still a problem for you? Or > you intend to just ignore urandom_read-related tests? > I wasn't running those tests, and I thought having most tests compile statically is better than nothing. Maybe this can be fixed by defining a static target for liburandom_read? I am honestly not sure, I have little experience with Makefiles/compilation. > > $ ldd urandom_read > linux-vdso.so.1 (0x00007ffd0d5e5000) > liburandom_read.so (0x00007fc7f7d76000) > libelf.so.1 => /lib64/libelf.so.1 (0x00007fc7f7937000) > libz.so.1 => /lib64/libz.so.1 (0x00007fc7f7720000) > librt.so.1 => /lib64/librt.so.1 (0x00007fc7f7518000) > libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fc7f72f8000) > libc.so.6 => /lib64/libc.so.6 (0x00007fc7f6f33000) > /lib64/ld-linux-x86-64.so.2 (0x00007fc7f7b50000) > > > > > > $(OUTPUT)/liburandom_read.so: urandom_read_lib1.c urandom_read_lib2.c > > $(call msg,LIB,,$@) > > - $(Q)$(CC) $(CFLAGS) -fPIC $(LDFLAGS) $^ $(LDLIBS) --shared -o $@ > > + $(Q)$(CC) $(DYNAMIC_CFLAGS) -fPIC $(LDFLAGS) $^ $(LDLIBS) --shared -o $@ > > > > $(OUTPUT)/urandom_read: urandom_read.c urandom_read_aux.c $(OUTPUT)/liburandom_read.so > > $(call msg,BINARY,,$@) > > - $(Q)$(CC) $(CFLAGS) $(LDFLAGS) $(filter %.c,$^) \ > > - liburandom_read.so $(LDLIBS) \ > > + $(Q)$(CC) $(DYNAMIC_CFLAGS) $(LDFLAGS) $(filter %.c,$^) \ > > + liburandom_read.so $(LDLIBS) \ > > -Wl,-rpath=. -Wl,--build-id=sha1 -o $@ > > > > $(OUTPUT)/bpf_testmod.ko: $(VMLINUX_BTF) $(wildcard bpf_testmod/Makefile bpf_testmod/*.[ch]) > > -- > > 2.36.0.550.gb090851708-goog > >