Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp1056257iob; Fri, 13 May 2022 21:23:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw+qzMQnk1mKXsXNqBKlx5MaVgr+jqL/n4AcZLT+0gJfo/OhBPuTh4780sbEI5nd6NaLc5n X-Received: by 2002:adf:fe12:0:b0:20c:fdac:74c9 with SMTP id n18-20020adffe12000000b0020cfdac74c9mr703211wrr.490.1652502196420; Fri, 13 May 2022 21:23:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652502196; cv=none; d=google.com; s=arc-20160816; b=woRaikqYh7ad3j0i5dO/t1Rj7l0guY2V1R2H2ZZOP4ASGGZxdSDmKjeQlUm41dbaXb WONNJnJ89k0pygXZ4gn0UBV6gkdLKcDcWS48l7OkGSjdpi7tH3hTynxkv9nFm7WCvkCF 0YsipcEvRjRnlv/yPH+lTOEkKlp2NUfduiJMwsGaCliSyWmT+MlW8XBiZKVoPSd4F13E N4eZGJccrM/5Vf9Cj7AqKB6fkMN0rUmQqwU9wrKYqrUyPyGGaBbyOFrY0px22MqmCqKv jlymk42yDE4r5YIvijzzI4iHaz4t7f8p3hKjZKiZVjzqvDYjF1bWhFgrSvY1DmF7hEDX NtuQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=mivRpjYlnos8QyfKIL0ZlkiTUotRjXBDBCX8TH+HQXY=; b=jpywauACp0SCvCV/r+GsKR/jRkheMqlwHJR+3DCklE2s1nwZ3uAOeWR3b9WOz0Xqq3 uOQDPTz2esrBmYS8DHpE2wqFxzk5WeK9ZH2eyPXxtNYHN8fEplTx90G6PWLtaOt48Kki eXGS6UaAIsiBFcSfwNrtvn6rpImjAqg4yblz+5m4Id83yIoJiXeTN2zs0rlGnJIghCcO 4u4v/uaS0KWQZFdQL2P0U72b+6XooU++/RovgBLmP37mpqjhdZN47HIvEnyOacLdFw3X NMhvnRjl1exji9axT+Yf6hcJYJnkKt9Wg9aC9HQZxBGJo90WQGeHCRA/R1/TKqeZmVV1 7a5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=UdpAoUQi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id n6-20020adffe06000000b0020acf016d1bsi3860548wrr.200.2022.05.13.21.23.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 May 2022 21:23:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=UdpAoUQi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0B60234B1AC; Fri, 13 May 2022 17:53:15 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238181AbiEMXGV (ORCPT + 99 others); Fri, 13 May 2022 19:06:21 -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-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" X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 > >