All of lore.kernel.org
 help / color / mirror / Atom feed
From: Shuah Khan <skhan@linuxfoundation.org>
To: Fenghua Yu <fenghua.yu@intel.com>, Shuah Khan <shuah@kernel.org>,
	Tony Luck <tony.luck@intel.com>,
	Reinette Chatre <reinette.chatre@intel.com>,
	David Binderman <dcb314@hotmail.com>,
	Babu Moger <babu.moger@amd.com>,
	James Morse <james.morse@arm.com>,
	Ravi V Shankar <ravi.v.shankar@intel.com>,
	Shuah Khan <skhan@linuxfoundation.org>
Cc: linux-kernel <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v4 01/17] selftests/resctrl: Fix compilation issues for global variables
Date: Mon, 25 Jan 2021 18:22:25 -0700	[thread overview]
Message-ID: <f79c885b-b67f-09ca-69f9-726cd6211e53@linuxfoundation.org> (raw)
In-Reply-To: <20201130202010.178373-2-fenghua.yu@intel.com>

On 11/30/20 1:19 PM, Fenghua Yu wrote:
> Reinette reported following compilation issue on Fedora 32, gcc version
> 10.1.1
> 
> /usr/bin/ld: cqm_test.o:<src_dir>/cqm_test.c:22: multiple definition of
> `cache_size'; cat_test.o:<src_dir>/cat_test.c:23: first defined here
> 
> The same issue is reported for long_mask, cbm_mask, count_of_bits etc
> variables as well. Compiler isn't happy because these variables are
> defined globally in two .c files namely cqm_test.c and cat_test.c and
> the compiler during compilation finds that the variable is already
> defined (multiple definition error).
> 
> Taking a closer look at the usage of these variables reveals that these
> variables are used only locally to functions such as cqm_resctrl_val()
> (defined in cqm_test.c) and cat_perf_miss_val() (defined in cat_test.c).
> These variables are not shared between those functions. So, there is no
> need for these variables to be global. Hence, fix this issue by making
> them local variables to the functions where they are used.
> 

Easy fix to this problem would be making these variables static to
these files. I am not seeing any real advantage to changing these
variable to local variables.

diff --git a/tools/testing/selftests/resctrl/cat_test.c 
b/tools/testing/selftests/resctrl/cat_test.c
index 5da43767b973..360456b8a1b6 100644
--- a/tools/testing/selftests/resctrl/cat_test.c
+++ b/tools/testing/selftests/resctrl/cat_test.c
@@ -17,10 +17,10 @@
  #define MAX_DIFF_PERCENT       4
  #define MAX_DIFF               1000000

-int count_of_bits;
-char cbm_mask[256];
-unsigned long long_mask;
-unsigned long cache_size;
+static int count_of_bits;
+static cbm_mask[256];
+static unsigned long long_mask;
+static unsigned long cache_size;

Same changes made to tools/testing/selftests/resctrl/cqm_test.c

> To fix issues for other global variables (e.g: bm_pid, ppid, llc_occup_path
> and is_amd) that are used across .c files, declare them as extern.
> 

This change is fine. Make this a separate patch.

This way, we can take it as a fixes to stables.

With the above the test builds fine. There is a bigger problem that
needs fixing: (thix might have been fixed in later patches perhaps):

cqm_test.c: In function ‘check_results’:
cqm_test.c:89:9: warning: ‘fgets’ writing 1024 bytes into a region of 
size 512 overflows the destination [-Wstringop-overflow=]
    89 |  while (fgets(temp, 1024, fp)) {
       |         ^~~~~~~~~~~~~~~~~~~~~
In file included from resctrl.h:5,
                  from cqm_test.c:11:
/usr/include/stdio.h:568:14: note: in a call to function ‘fgets’ 
declared with attribute ‘write_only (1, 2)’
   568 | extern char *fgets (char *__restrict __s, int __n, FILE 
*__restrict __stream)
       |              ^~~~~


thanks,
-- Shuah

  reply	other threads:[~2021-01-26 10:30 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-30 20:19 [PATCH v4 00/17] Miscellaneous fixes for resctrl selftests Fenghua Yu
2020-11-30 20:19 ` [PATCH v4 01/17] selftests/resctrl: Fix compilation issues for global variables Fenghua Yu
2021-01-26  1:22   ` Shuah Khan [this message]
2020-11-30 20:19 ` [PATCH v4 02/17] selftests/resctrl: Clean up resctrl features check Fenghua Yu
2021-01-26  2:08   ` Shuah Khan
2020-11-30 20:19 ` [PATCH v4 03/17] selftests/resctrl: Rename CQM test as CMT test Fenghua Yu
2020-11-30 20:19 ` [PATCH v4 04/17] selftests/resctrl: Fix printed messages Fenghua Yu
2021-01-26  2:25   ` Shuah Khan
2020-11-30 20:19 ` [PATCH v4 05/17] selftests/resctrl: Add a few dependencies Fenghua Yu
2021-01-26  2:29   ` Shuah Khan
2020-11-30 20:19 ` [PATCH v4 06/17] selftests/resctrl: Check for resctrl mount point only if resctrl FS is supported Fenghua Yu
2021-01-26  2:32   ` Shuah Khan
2020-11-30 20:20 ` [PATCH v4 07/17] selftests/resctrl: Use resctrl/info for feature detection Fenghua Yu
2020-11-30 20:20 ` [PATCH v4 08/17] selftests/resctrl: Ensure sibling CPU is not same as original CPU Fenghua Yu
2021-01-26  2:35   ` Shuah Khan
2020-11-30 20:20 ` [PATCH v4 09/17] selftests/resctrl: Fix missing options "-n" and "-p" Fenghua Yu
2021-01-26  2:36   ` Shuah Khan
2020-11-30 20:20 ` [PATCH v4 10/17] selftests/resctrl: Fix MBA/MBM results reporting format Fenghua Yu
2021-01-26  2:38   ` Shuah Khan
2020-11-30 20:20 ` [PATCH v4 11/17] selftests/resctrl: Enable gcc checks to detect buffer overflows Fenghua Yu
2021-01-26  2:38   ` Shuah Khan
2020-11-30 20:20 ` [PATCH v4 12/17] selftests/resctrl: Don't hard code value of "no_of_bits" variable Fenghua Yu
2020-11-30 20:20 ` [PATCH v4 13/17] selftests/resctrl: Modularize resctrl test suite main() function Fenghua Yu
2020-11-30 20:20 ` [PATCH v4 14/17] selftests/resctrl: Skip the test if requested resctrl feature is not supported Fenghua Yu
2020-11-30 20:20 ` [PATCH v4 15/17] selftests/resctrl: Fix unmount resctrl FS Fenghua Yu
2020-11-30 20:20 ` [PATCH v4 16/17] selftests/resctrl: Fix incorrect parsing of iMC counters Fenghua Yu
2020-11-30 20:20 ` [PATCH v4 17/17] selftests/resctrl: Fix checking for < 0 for unsigned values Fenghua Yu
2020-12-11  0:21 ` [PATCH v4 00/17] Miscellaneous fixes for resctrl selftests Yu, Fenghua
2021-01-25 20:47 ` Fenghua Yu
2021-01-25 21:52   ` Shuah Khan
2021-01-25 21:54     ` Fenghua Yu
2021-01-26  1:22 ` Shuah Khan
2021-01-26 23:57 ` Shuah Khan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f79c885b-b67f-09ca-69f9-726cd6211e53@linuxfoundation.org \
    --to=skhan@linuxfoundation.org \
    --cc=babu.moger@amd.com \
    --cc=dcb314@hotmail.com \
    --cc=fenghua.yu@intel.com \
    --cc=james.morse@arm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ravi.v.shankar@intel.com \
    --cc=reinette.chatre@intel.com \
    --cc=shuah@kernel.org \
    --cc=tony.luck@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.