Fix compilation with -fno-common (gcc-10)
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
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
@@ -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
@@ -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
@@ -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
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
@@ -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
@@ -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
PATCH v2 3/9 controllers: Simplify fullpath definition
In reply to Petr VorelPATH_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
@@ -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
PATCH v2 4/9 controllers: Fix linking with -fno-common
In reply to Petr Vorelby 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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
PATCH v2 5/9 kernel/mem: Fix linking error with -fno-common
In reply to Petr VorelAdding missing extern.
--- testcases/kernel/mem/include/mem.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
testcases/kernel/mem/include/mem.h +1 -1
@@ -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
PATCH v2 6/9 hugepage: Fix linking error with -fno-common
In reply to Petr Vorelby moving definitions to tst_hugepage.c and adding extern declarations 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
@@ -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
@@ -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
PATCH v2 7/9 hugetlb: Fix linking error with -fno-common
In reply to Petr VorelAdding 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
@@ -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
@@ -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
PATCH v2 8/9 realtime: Fix linking error with -fno-common
In reply to Petr Vorelby 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
@@ -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
@@ -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
PATCH v2 9/9 travis: Build with -fno-common
In reply to Petr VorelThis 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
@@ -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
v2 cover Fix compilation with -fno-common (gcc-10)
In reply to Petr Vorel----- Original Message -----
Quoted 9 lines
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
Looks good, ack.
v2 cover Fix compilation with -fno-common (gcc-10)
Hi!
Acked as well.
Signature · 1 line
[email protected]
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