Skip to contentSkip to conversation

Fix compilation with -fno-common (gcc-10)

PATCH Superseded Petr Vorel 3 participants 13 messages Apr 15, 2020 Library code

lore
Share & tools
lore

Petr Vorel

author
#0 lore raw

v2 cover Fix compilation with -fno-common (gcc-10)

Hi,

I added 1st commit "Remove use of TCID in new API tests" which allows to remove extern const char *TCID;

https://travis-ci.org/github/pevik/ltp/builds/675251626

Kind regards,
Petr

Petr Vorel (9):
Remove use of TCID in new API tests
lib: Fix linking error multiple TCID definitions with -fno-common
controllers: Simplify fullpath definition
controllers: Fix linking with -fno-common
kernel/mem: Fix linking error with -fno-common
hugepage: Fix linking error with -fno-common
hugetlb: Fix linking error with -fno-common
realtime: Fix linking error with -fno-common
travis: Build with -fno-common

 build.sh                                      |  2 +-
 include/tst_hugepage.h                        |  4 +--
 include/tst_test.h                            |  4 ---
 lib/tst_hugepage.c                            |  2 ++
 lib/tst_test.c                                |  5 +++
 .../controllers/cpuctl/cpuctl_def_task01.c    |  2 --
 .../controllers/cpuctl/cpuctl_def_task02.c    |  2 --
 .../controllers/cpuctl/cpuctl_def_task03.c    |  2 --
 .../controllers/cpuctl/cpuctl_def_task04.c    |  2 --
 .../kernel/controllers/cpuctl/cpuctl_test01.c |  2 --
 .../kernel/controllers/cpuctl/cpuctl_test02.c |  1 -
 .../kernel/controllers/cpuctl/cpuctl_test03.c |  2 --
 .../kernel/controllers/cpuctl/cpuctl_test04.c |  2 --
 .../libcontrollers/libcontrollers.c           | 11 +++++++
 .../libcontrollers/libcontrollers.h           | 32 ++++++-------------
 testcases/kernel/mem/hugetlb/lib/hugetlb.c    |  2 ++
 testcases/kernel/mem/hugetlb/lib/hugetlb.h    |  2 +-
 testcases/kernel/mem/include/mem.h            |  2 +-
 .../kernel/mem/tunable/overcommit_memory.c    |  4 +--
 .../security/integrity/ima/src/ima_mmap.c     |  3 +-
 .../syscalls/memfd_create/memfd_create01.c    |  3 +-
 testcases/realtime/include/librttest.h        |  1 -
 testcases/realtime/lib/librttest.c            |  1 +
 23 files changed, 42 insertions(+), 51 deletions(-)
Signature · 1 line
2.26.0
author
#1 lore raw

PATCH v2 1/9 Remove use of TCID in new API tests

This is a preparation for build with -fno-common

---
New in v2.
Sorry for quashing it in a single commit.

 testcases/kernel/mem/tunable/overcommit_memory.c        | 4 ++--
 testcases/kernel/security/integrity/ima/src/ima_mmap.c  | 3 ++-
 testcases/kernel/syscalls/memfd_create/memfd_create01.c | 3 ++-
 3 files changed, 6 insertions(+), 4 deletions(-)
testcases/kernel/mem/tunable/overcommit_memory.c +2 -2
index 345764dfe..f77939908 100644
@@ -1,4 +1,5 @@
 /*
+ * Copyright (c) Linux Test Project, 2012-2020
  * Copyright (C) 2012-2017  Red Hat, Inc.
  *
  * This program is free software;  you can redistribute it and/or modify
@@ -101,8 +102,7 @@ static void setup(void)
 
 	if (access(PATH_SYSVM "overcommit_memory", F_OK) == -1 ||
 	    access(PATH_SYSVM "overcommit_ratio", F_OK) == -1)
-		tst_brk(TCONF, "The system "
-			 "can't support to test %s", TCID);
+		tst_brk(TCONF, "system doesn't support overcommit_memory");
 
 	if (R_opt)
 		overcommit_ratio = SAFE_STRTOL(R_opt, 0, LONG_MAX);
testcases/kernel/security/integrity/ima/src/ima_mmap.c +2 -1
index 0875aaeaf..c831be829 100644
@@ -1,5 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 /*
+ * Copyright (c) Linux Test Project, 2010-2020
  * Copyright (c) International Business Machines Corp., 2009
  *
  * Authors:
@@ -33,7 +34,7 @@ static void cleanup(void)
 static void run(void)
 {
 	if (!filename)
-		tst_brk(TBROK, "Usage: %s -f filename", TCID);
+		tst_brk(TBROK, "missing filename (-f filename)");
 
 	fd = SAFE_OPEN(filename, O_CREAT | O_RDWR, S_IRWXU);
 
testcases/kernel/syscalls/memfd_create/memfd_create01.c +2 -1
index fdd37f64b..e0db69dff 100644
@@ -1,5 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 /*
+ * Copyright (c) Linux Test Project, 2017-2020
  * Copyright (C) 2017  Red Hat, Inc.
  */
 
@@ -241,7 +242,7 @@ static void verify_memfd_create(unsigned int n)
 
 	tst_res(TINFO, "%s", tc->desc);
 
-	fd = CHECK_MFD_NEW(TCID, MFD_DEF_SIZE, tc->flags);
+	fd = CHECK_MFD_NEW("ltp_memfd_create01", MFD_DEF_SIZE, tc->flags);
 
 	tc->func(fd);
 
Signature · 1 line
2.26.0
author
#2 lore raw

PATCH v2 2/9 lib: Fix linking error multiple TCID definitions with -fno-common

In reply to Petr Vorel

-fno-common is a default for gcc-10 and if not used on many targets implies a speed and code size penalty on global variable references. It requires either defining variable in header as extern or moving it to C source.

https://gcc.gnu.org/gcc-10/porting_to.html

Due different TCID handling in legacy API (which defines TCID in the test source) and new API (TCID defined in the library header) it's not enough to simply move that definition into tst_test.c because that would mean that old API test would end up with multiple definitions one in the corresponding test and one in the new library library code. To workaround this added definition in tst_test.c with weak linker attribute.

---
 include/tst_test.h | 4 ----
 lib/tst_test.c     | 5 +++++
 2 files changed, 5 insertions(+), 4 deletions(-)
include/tst_test.h +0 -4
index 42c02b549..484842e59 100644
@@ -319,9 +319,5 @@ int main(int argc, char *argv[])
 
 #define TST_TEST_TCONF(message)                                 \
         static struct tst_test test = { .tconf_msg = message  } \
-/*
- * This is a hack to make the testcases link without defining TCID
- */
-const char *TCID;
 
 #endif	/* TST_TEST_H__ */
lib/tst_test.c +5 -0
index e502c2c1a..64cd3ac33 100644
@@ -32,6 +32,11 @@
 #include "old_device.h"
 #include "old_tmpdir.h"
 
+/*
+ * Hack to get TCID defined in newlib tests
+ */
+const char *TCID __attribute__((weak));
+
 #define LINUX_GIT_URL "https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id="
 #define CVE_DB_URL "https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-"
 
Signature · 1 line
2.26.0
author
#3 lore raw

PATCH v2 3/9 controllers: Simplify fullpath definition

In reply to Petr Vorel

PATH_MAX has been in <limits.h> in all libc for a long time.

---
 testcases/kernel/controllers/libcontrollers/libcontrollers.h | 4 ----
 1 file changed, 4 deletions(-)
testcases/kernel/controllers/libcontrollers/libcontrollers.h +0 -4
index cdde9f9e6..f999f705e 100644
@@ -42,11 +42,7 @@
 #include <sys/types.h>
 #include <unistd.h>
 
-#ifdef PATH_MAX
 char fullpath[PATH_MAX];
-#else
-char fullpath[1024]; /* Guess */
-#endif
 
 int FLAG;
 volatile int timer_expired;
Signature · 1 line
2.26.0
author
#4 lore raw

PATCH v2 4/9 controllers: Fix linking with -fno-common

In reply to Petr Vorel

by moving definitions to libcontrollers.c and adding extern declarations to libcontrollers.h.

---
 .../controllers/cpuctl/cpuctl_def_task01.c    |  2 --
 .../controllers/cpuctl/cpuctl_def_task02.c    |  2 --
 .../controllers/cpuctl/cpuctl_def_task03.c    |  2 --
 .../controllers/cpuctl/cpuctl_def_task04.c    |  2 --
 .../kernel/controllers/cpuctl/cpuctl_test01.c |  2 --
 .../kernel/controllers/cpuctl/cpuctl_test02.c |  1 -
 .../kernel/controllers/cpuctl/cpuctl_test03.c |  2 --
 .../kernel/controllers/cpuctl/cpuctl_test04.c |  2 --
 .../libcontrollers/libcontrollers.c           | 11 ++++++++
 .../libcontrollers/libcontrollers.h           | 28 +++++++------------
 10 files changed, 21 insertions(+), 33 deletions(-)
testcases/kernel/controllers/cpuctl/cpuctl_def_task01.c +0 -2
index 90119e4ad..578c60c89 100644
@@ -81,8 +81,6 @@ extern void cleanup(void)
 	/* Report exit status */
 }
 
-volatile int timer_expired = 0;
-
 int main(int argc, char *argv[])
 {
 
testcases/kernel/controllers/cpuctl/cpuctl_def_task02.c +0 -2
index dc1546e88..658c6fd3f 100644
@@ -76,8 +76,6 @@ extern void cleanup(void)
 	/* Report exit status */
 }
 
-volatile int timer_expired = 0;
-
 int main(int argc, char *argv[])
 {
 
testcases/kernel/controllers/cpuctl/cpuctl_def_task03.c +0 -2
index 92b451793..a700ca515 100644
@@ -76,8 +76,6 @@ extern void cleanup(void)
 	/* Report exit status */
 }
 
-volatile int timer_expired = 0;
-
 int main(int argc, char *argv[])
 {
 
testcases/kernel/controllers/cpuctl/cpuctl_def_task04.c +0 -2
index 108e576e1..1726f810d 100644
@@ -76,8 +76,6 @@ extern void cleanup(void)
 	/* Report exit status */
 }
 
-volatile int timer_expired = 0;
-
 int main(int argc, char *argv[])
 {
 
testcases/kernel/controllers/cpuctl/cpuctl_test01.c +0 -2
index d7be1c80c..8f6d11de0 100644
@@ -79,8 +79,6 @@ extern void cleanup(void)
 	tst_exit();		/* Report exit status */
 }
 
-volatile int timer_expired = 0;
-
 int main(int argc, char *argv[])
 {
 
testcases/kernel/controllers/cpuctl/cpuctl_test02.c +0 -1
index 2a5cd4a11..52ad8aa2f 100644
@@ -78,7 +78,6 @@ extern void cleanup(void)
 }
 
 int migrate_task();
-volatile int timer_expired = 0;
 
 int main(void)
 {
testcases/kernel/controllers/cpuctl/cpuctl_test03.c +0 -2
index 8a80d6932..0e0a26dc3 100644
@@ -76,8 +76,6 @@ extern void cleanup(void)
 	tst_exit();		/* Report exit status */
 }
 
-volatile int timer_expired = 0;
-
 int main(int argc, char *argv[])
 {
 
testcases/kernel/controllers/cpuctl/cpuctl_test04.c +0 -2
index 791a58dd2..dae0d4c05 100644
@@ -77,8 +77,6 @@ extern void cleanup(void)
 	tst_exit();		/* Report exit status */
 }
 
-volatile int timer_expired = 0;
-
 int main(int argc, char *argv[])
 {
 
testcases/kernel/controllers/libcontrollers/libcontrollers.c +11 -0
index 75766fc19..e9917271c 100644
@@ -35,6 +35,17 @@
 
 #include "libcontrollers.h"
 
+char fullpath[PATH_MAX];
+int FLAG;
+volatile int timer_expired = 0;
+int retval;
+unsigned int num_line;
+unsigned int current_shares;
+unsigned int total_shares;
+unsigned int *shares_pointer;
+char target[LINE_MAX];
+struct dirent *dir_pointer;
+
 /*
  * Function: scan_shares_file()
  * This function scans all the shares files under the mountpoint
testcases/kernel/controllers/libcontrollers/libcontrollers.h +10 -18
index f999f705e..7d7b8324b 100644
@@ -42,24 +42,16 @@
 #include <sys/types.h>
 #include <unistd.h>
 
-char fullpath[PATH_MAX];
-
-int FLAG;
-volatile int timer_expired;
-
-int retval;
-
-unsigned int num_line;//??
-
-unsigned int current_shares;
-
-unsigned int total_shares;
-
-unsigned int *shares_pointer;//??
-
-char target[LINE_MAX];
-
-struct dirent 	*dir_pointer;
+extern char fullpath[PATH_MAX];
+extern int FLAG;
+extern volatile int timer_expired;
+extern int retval;
+extern unsigned int num_line;
+extern unsigned int current_shares;
+extern unsigned int total_shares;
+extern unsigned int *shares_pointer;
+extern char target[LINE_MAX];
+extern struct dirent *dir_pointer;
 
 enum{
 	GET_SHARES	=1,
Signature · 1 line
2.26.0
author
#5 lore raw

PATCH v2 5/9 kernel/mem: Fix linking error with -fno-common

In reply to Petr Vorel

Adding missing extern.

---
 testcases/kernel/mem/include/mem.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
testcases/kernel/mem/include/mem.h +1 -1
index a12c2231f..cce9c0497 100644
@@ -37,7 +37,7 @@ static inline void clean_node(unsigned long *array)
 #define MLOCK			2
 #define KSM			3
 
-long overcommit;
+extern long overcommit;
 void oom(int testcase, int lite, int retcode, int allow_sigkill);
 void testoom(int mempolicy, int lite, int retcode, int allow_sigkill);
 
Signature · 1 line
2.26.0
author
#6 lore raw

PATCH v2 6/9 hugepage: Fix linking error with -fno-common

In reply to Petr Vorel

by moving definitions to tst_hugepage.c and adding extern declarations to tst_hugepage.h.

Fixes 156f91396 ("hugetlb: move nr_opt to tst_hugepage.h")
---
 include/tst_hugepage.h | 4 ++--
 lib/tst_hugepage.c     | 2 ++
 2 files changed, 4 insertions(+), 2 deletions(-)
include/tst_hugepage.h +2 -2
index 30e00a377..60c03c5c5 100644
@@ -9,8 +9,8 @@
 #define PATH_HUGEPAGES	"/sys/kernel/mm/hugepages/"
 #define PATH_NR_HPAGES	"/proc/sys/vm/nr_hugepages"
 
-char *nr_opt; /* -s num   Set the number of the been allocated hugepages */
-char *Hopt;   /* -H /..   Location of hugetlbfs, i.e.  -H /var/hugetlbfs */
+extern char *nr_opt; /* -s num   Set the number of the been allocated hugepages */
+extern char *Hopt;   /* -H /..   Location of hugetlbfs, i.e.  -H /var/hugetlbfs */
 
 /*
  * Try the best to request a specified number of huge pages from system,
lib/tst_hugepage.c +2 -0
index 34fd27ede..52667a14e 100644
@@ -9,6 +9,8 @@
 #include "tst_hugepage.h"
 
 unsigned long tst_hugepages;
+char *nr_opt;
+char *Hopt;
 
 unsigned long tst_request_hugepages(unsigned long hpages)
 {
Signature · 1 line
2.26.0
author
#7 lore raw

PATCH v2 7/9 hugetlb: Fix linking error with -fno-common

In reply to Petr Vorel

Adding missing extern.

---
 testcases/kernel/mem/hugetlb/lib/hugetlb.c | 2 ++
 testcases/kernel/mem/hugetlb/lib/hugetlb.h | 2 +-
 2 files changed, 3 insertions(+), 1 deletion(-)
testcases/kernel/mem/hugetlb/lib/hugetlb.c +2 -0
index cd1b27eb3..4bb2d500e 100644
@@ -39,6 +39,8 @@
 #include <pwd.h>
 #include "hugetlb.h"
 
+key_t shmkey;
+
 /*
  * getipckey() - generates and returns a message key used by the "get"
  *		 calls to create an IPC resource.
testcases/kernel/mem/hugetlb/lib/hugetlb.h +1 -1
index 88890ebfb..f75109f3e 100644
@@ -34,7 +34,7 @@
  */
 #define MODE_MASK	0x01FF
 
-key_t shmkey;			/* an IPC key generated by ftok() */
+extern key_t shmkey;			/* an IPC key generated by ftok() */
 
 int getipckey(void);
 int getuserid(char *user);
Signature · 1 line
2.26.0
author
#8 lore raw

PATCH v2 8/9 realtime: Fix linking error with -fno-common

In reply to Petr Vorel

by declaring iters_per_us as static and moving from header into C source.

---
 testcases/realtime/include/librttest.h | 1 -
 testcases/realtime/lib/librttest.c     | 1 +
 2 files changed, 1 insertion(+), 1 deletion(-)
testcases/realtime/include/librttest.h +0 -1
index c18236200..b829f4089 100644
@@ -66,7 +66,6 @@ extern char *optarg;
 
 #define _MAXTHREADS 256
 #define CALIBRATE_LOOPS 100000
-unsigned long iters_per_us;
 
 #define NS_PER_MS 1000000
 #define NS_PER_US 1000
testcases/realtime/lib/librttest.c +1 -0
index 36790581e..722d99d50 100644
@@ -63,6 +63,7 @@
 
 static LIST_HEAD(_threads);
 static atomic_t _thread_count = { -1 };
+static unsigned long iters_per_us;
 
 pthread_mutex_t _buffer_mutex;
 char *_print_buffer = NULL;
Signature · 1 line
2.26.0
author
#9 lore raw

PATCH v2 9/9 travis: Build with -fno-common

In reply to Petr Vorel

This is the default with gcc-10, but use it with all compilers.

---
 build.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
build.sh +1 -1
index e3d268c83..50fb527e4 100755
@@ -9,7 +9,7 @@
 
 set -e
 
-CFLAGS="${CFLAGS:--Werror=implicit-function-declaration}"
+CFLAGS="${CFLAGS:--Werror=implicit-function-declaration -fno-common}"
 CC="${CC:-gcc}"
 
 DEFAULT_PREFIX="$HOME/ltp-install"
Signature · 1 line
2.26.0
author
#12 lore raw

v2 cover Fix compilation with -fno-common (gcc-10)

Hi Jan, Cyril,

Quoted 2 lines

Hi!
Acked as well.

Thanks both for a review, merged.

Kind regards,
Petr