Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp1549398rwe; Sat, 27 Aug 2022 10:27:33 -0700 (PDT) X-Google-Smtp-Source: AA6agR7qQTKaBpGFhaAJAkkqu3WvVcIeKI42zbpsE6VbB2J8llBgqDlmRGlwIHXDd2A03hwfc4ER X-Received: by 2002:a17:907:2cce:b0:73d:6c93:e4a2 with SMTP id hg14-20020a1709072cce00b0073d6c93e4a2mr8551319ejc.390.1661621252906; Sat, 27 Aug 2022 10:27:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661621252; cv=none; d=google.com; s=arc-20160816; b=gAN2PfvPiOATCmwobTiUvWDXrmg4cnvyX8QQwr5UCey/KaY3+BfcoodCdhJQW8zDmp 7aoMeI8HgQvt6MIGJ7K0JYNPgo+6WLMaefNC/QA4aIkk8hnTjG8p1Sfs865TGhqhWhPw fULC4TNLTaRkxFo6GSJq64JmgK2iSc7tsqgqRUSu74Vj7IPlROLYzuNj6s5m4t8xrh2W DazwmPfDim1qQH8Wdm2QgD+dz2Vwaq8qO6+pVbgZynGdL6f8jMsXDN+K7RXLz/c8IRd7 1gF90EdELzxaJcFUQV5JwCLhrkm94zBf/MhydjXybYlwTA4lhQib1zrUUjtaYLgDkv66 sABw== 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=t4YmsgZLUK6Kxn6VegF+FGswxULfoRLmy+ksomEpPk4=; b=lm31c2DiAnvHnzzxx0rnxw+ao7/EC1gj/fAfEvmjEuM9pjCoUpKYcam4Pm7sXHwxdE 5w4CnCOq567tV1IYU1aDVf/riALl//swWPff8AWVeiQE8PtjBmAWpICvNHjw+g+4mop3 lKIFrGGO4oqDy+QpZrYcAg2qLE+4kz0hjPFaJbyOzFwWAU+ErzkpOOJCuls4R+RwwWWL Qr6y/HPSRbnNZBU+XuAow/LNrI39db5gUw1+6jlYQC14RYNA5H0Mm4WXr2PMN/cQAYg2 E7sI9uJAJ7lOJEeJejdEhh5LZ6LPwiEs3p3NHIh0Kz6pHv23NsDtjI/cg7Fhuq2thMPf BrvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=ZKU21Kdz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t1-20020a508d41000000b0043c158735ddsi3237811edt.109.2022.08.27.10.27.07; Sat, 27 Aug 2022 10:27:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=ZKU21Kdz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234100AbiH0RIw (ORCPT + 99 others); Sat, 27 Aug 2022 13:08:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39610 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233501AbiH0RIu (ORCPT ); Sat, 27 Aug 2022 13:08:50 -0400 Received: from mail-ej1-x62a.google.com (mail-ej1-x62a.google.com [IPv6:2a00:1450:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E9B3628E01; Sat, 27 Aug 2022 10:08:49 -0700 (PDT) Received: by mail-ej1-x62a.google.com with SMTP id p16so5208345ejb.9; Sat, 27 Aug 2022 10:08:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date; bh=t4YmsgZLUK6Kxn6VegF+FGswxULfoRLmy+ksomEpPk4=; b=ZKU21KdzTtXtLA9di6gzcMDcX2ETEJPS13mtDfhiEgM2J5DoIyyw9Wa9jPe2lSGavz L8eSIv5+gebaIX3er/lZ1kE5L8XRKV+F9QN6X1yBXLKS8qtuJp+ZpdAI63dOMJ4K73+7 KViv2t0utlkCvN8aavffv9NBJuzXDB+iUoR13pbSGJBYsOay41NAGdFni9xUK69tgTeK hY5T9EAkkjcBJt6WBJlFHPNNDKoUC5MM1u8IAnm/Vw5bQD3mj+wgJsCJNIqKhsHzcWcv BOEzoZl/v8bchmhyL4KrX9f/PZiBOSyNUu3D6lF+ltazStOlwZLIjY4lWrRkuojmW4OO bhuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date; bh=t4YmsgZLUK6Kxn6VegF+FGswxULfoRLmy+ksomEpPk4=; b=3zwDD7/K37PNwltOyBJQaqRlposehilIYUu7HeTHidCkhMaX8hkcq+Wk5iLedeiZoN fjpJrkLiiZh27lD9uueLZrG1wWSGmTvvCi/kddPayFO03A5j2XReXalrmYX4LlhX0UZ4 MddZBd3rCZpT4KE7t9TUI77XiP5FQsapCfFvrI/m5Cp+uM79PyQ0epvEI9KW5f9vWHmu lUoVghi+c3HuHtI/sQ16I09B6+ji+Hu3ry6w0nswQmt7PijanxYbkpmwZ7jnJJoORzlV OXOGEjUh+2SHciuAUHRbX/UMgcWyx2XHmpVklt2V/SjNfA3OunUW75ZzcgOpjCkQx5ZE QLXA== X-Gm-Message-State: ACgBeo0PqaPVrnBOf0Opv5eQaUQRY9PFGLd5AxEKE996CQlyBrsXUbMV C8lQe/+vWpbVimGM5Q8xegpzfsvzOwQY3Ki56X0= X-Received: by 2002:a17:907:2bdb:b0:73d:d7af:c133 with SMTP id gv27-20020a1709072bdb00b0073dd7afc133mr7496212ejc.545.1661620128476; Sat, 27 Aug 2022 10:08:48 -0700 (PDT) MIME-Version: 1.0 References: <20220826012614.552860-1-james.hilliard1@gmail.com> In-Reply-To: From: Andrii Nakryiko Date: Sat, 27 Aug 2022 10:08:37 -0700 Message-ID: Subject: Re: [PATCH] selftests/bpf: Fix conflicts with built-in functions in bpf_iter_ksym To: James Hilliard Cc: bpf@vger.kernel.org, Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Mykola Lysenko , Shuah Khan , Alan Maguire , linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,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 lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Aug 27, 2022 at 3:47 AM James Hilliard wrote: > > On Fri, Aug 26, 2022 at 10:55 PM Andrii Nakryiko > wrote: > > > > On Thu, Aug 25, 2022 at 6:26 PM James Hilliard > > wrote: > > > > > > Both tolower and toupper are built in c functions, we should not > > > > Really? How come? Can you point out where this is specified in C > > standard? From what I can tell you have to include to get > > toupper()/tolower(). > > See background on this sort of issue: > https://stackoverflow.com/a/20582607 > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=12213 > > (C99, 7.1.3p1) "All identifiers with external linkage in any of the following > subclauses (including the future library directions) are always reserved > for use as identifiers with external linkage." > Sigh, ok. Ghost functions: you can't use them without ctype.h, but you can't define your own either. Very nice. Can you please put all these details into a commit for the future? With that: Acked-by: Andrii Nakryiko > > > > This seems like yet another GCC-BPF quirk? > > Seems GCC takes a stricter interpretation of the standard here than > llvm. > > It's also documented behavior in GCC: > https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html#index-std-2 > > See: > The ISO C90 functions abort, abs, acos, asin, atan2, atan, calloc, ceil, > cosh, cos, exit, exp, fabs, floor, fmod, fprintf, fputs, free, frexp, fscanf, > isalnum, isalpha, iscntrl, isdigit, isgraph, islower, isprint, ispunct, isspace, > isupper, isxdigit, tolower, toupper, labs, ldexp, log10, log, malloc, memchr, > memcmp, memcpy, memset, modf, pow, printf, putchar, puts, realloc, > scanf, sinh, sin, snprintf, sprintf, sqrt, sscanf, strcat, strchr, > strcmp, strcpy, > strcspn, strlen, strncat, strncmp, strncpy, strpbrk, strrchr, strspn, strstr, > tanh, tan, vfprintf, vprintf and vsprintf are all recognized as > built-in functions > unless -fno-builtin is specified (or -fno-builtin-function is specified for an > individual function). > > We could disable builtin functions but it seems more correct to just > rename it so that it doesn't conflict. > > > > > > redefine them as this can result in a build error. > > > > > > Fixes the following errors: > > > progs/bpf_iter_ksym.c:10:20: error: conflicting types for built-in function 'tolower'; expected 'int(int)' [-Werror=builtin-declaration-mismatch] > > > 10 | static inline char tolower(char c) > > > | ^~~~~~~ > > > progs/bpf_iter_ksym.c:5:1: note: 'tolower' is declared in header '' > > > 4 | #include > > > +++ |+#include > > > 5 | > > > progs/bpf_iter_ksym.c:17:20: error: conflicting types for built-in function 'toupper'; expected 'int(int)' [-Werror=builtin-declaration-mismatch] > > > 17 | static inline char toupper(char c) > > > | ^~~~~~~ > > > progs/bpf_iter_ksym.c:17:20: note: 'toupper' is declared in header '' > > > > > > Signed-off-by: James Hilliard > > > --- > > > tools/testing/selftests/bpf/progs/bpf_iter_ksym.c | 6 +++--- > > > 1 file changed, 3 insertions(+), 3 deletions(-) > > > > > > diff --git a/tools/testing/selftests/bpf/progs/bpf_iter_ksym.c b/tools/testing/selftests/bpf/progs/bpf_iter_ksym.c > > > index 285c008cbf9c..9ba14c37bbcc 100644 > > > --- a/tools/testing/selftests/bpf/progs/bpf_iter_ksym.c > > > +++ b/tools/testing/selftests/bpf/progs/bpf_iter_ksym.c > > > @@ -7,14 +7,14 @@ char _license[] SEC("license") = "GPL"; > > > > > > unsigned long last_sym_value = 0; > > > > > > -static inline char tolower(char c) > > > +static inline char to_lower(char c) > > > { > > > if (c >= 'A' && c <= 'Z') > > > c += ('a' - 'A'); > > > return c; > > > } > > > > > > -static inline char toupper(char c) > > > +static inline char to_upper(char c) > > > { > > > if (c >= 'a' && c <= 'z') > > > c -= ('a' - 'A'); > > > @@ -54,7 +54,7 @@ int dump_ksym(struct bpf_iter__ksym *ctx) > > > type = iter->type; > > > > > > if (iter->module_name[0]) { > > > - type = iter->exported ? toupper(type) : tolower(type); > > > + type = iter->exported ? to_upper(type) : to_lower(type); > > > BPF_SEQ_PRINTF(seq, "0x%llx %c %s [ %s ] ", > > > value, type, iter->name, iter->module_name); > > > } else { > > > -- > > > 2.34.1 > > >