diff mbox series

tst_libext2fs: Avoid multiple definition of global variables

Message ID 20200130132122.21150-1-lczerner@redhat.com
State Superseded
Headers show
Series tst_libext2fs: Avoid multiple definition of global variables | expand

Commit Message

Lukas Czerner Jan. 30, 2020, 1:21 p.m. UTC
gcc version 10 changed the default from -fcommon to -fno-common and as a
result e2fsprogs unit tests fail because tst_libext2fs.c end up with a
build error.

This is because it defines two global variables debug_prog_name and
extra_cmds that are already defined in debugfs/debugfs.c. With -fcommon
linker was able to resolve those into the same object, however with
-fno-common it's no longer able to do it and we end up with
multiple definition errors.

Fix the problem by creating an extern declaration of said variables in
debugfs.h and just setting them in tst_libext2fs.c without additional
declaration.

Signed-off-by: Lukas Czerner <lczerner@redhat.com>
---
 debugfs/debugfs.h          | 2 ++
 lib/ext2fs/tst_libext2fs.c | 5 +++--
 2 files changed, 5 insertions(+), 2 deletions(-)

Comments

Eric Sandeen Feb. 6, 2020, 5:52 p.m. UTC | #1
On 1/30/20 7:21 AM, Lukas Czerner wrote:
> gcc version 10 changed the default from -fcommon to -fno-common and as a
> result e2fsprogs unit tests fail because tst_libext2fs.c end up with a
> build error.
> 
> This is because it defines two global variables debug_prog_name and
> extra_cmds that are already defined in debugfs/debugfs.c. With -fcommon
> linker was able to resolve those into the same object, however with
> -fno-common it's no longer able to do it and we end up with
> multiple definition errors.
> 
> Fix the problem by creating an extern declaration of said variables in
> debugfs.h and just setting them in tst_libext2fs.c without additional
> declaration.
> 
> Signed-off-by: Lukas Czerner <lczerner@redhat.com>

This looks fine to me.

Reviewed-by: Eric Sandeen <sandeen@redhat.com>

Is there any need to fix the one in lib/ext2fs/extent.c ?  It's only there
under #ifdef DEBUG though.

Thanks,
-Eric
Lukas Czerner Feb. 6, 2020, 7:20 p.m. UTC | #2
On Thu, Feb 06, 2020 at 11:52:17AM -0600, Eric Sandeen wrote:
> On 1/30/20 7:21 AM, Lukas Czerner wrote:
> > gcc version 10 changed the default from -fcommon to -fno-common and as a
> > result e2fsprogs unit tests fail because tst_libext2fs.c end up with a
> > build error.
> > 
> > This is because it defines two global variables debug_prog_name and
> > extra_cmds that are already defined in debugfs/debugfs.c. With -fcommon
> > linker was able to resolve those into the same object, however with
> > -fno-common it's no longer able to do it and we end up with
> > multiple definition errors.
> > 
> > Fix the problem by creating an extern declaration of said variables in
> > debugfs.h and just setting them in tst_libext2fs.c without additional
> > declaration.
> > 
> > Signed-off-by: Lukas Czerner <lczerner@redhat.com>
> 
> This looks fine to me.
> 
> Reviewed-by: Eric Sandeen <sandeen@redhat.com>
> 
> Is there any need to fix the one in lib/ext2fs/extent.c ?  It's only there
> under #ifdef DEBUG though.

Yeah, but if we ever want to use DEBUG macro it would fail with
-fno-common. Uff, I guess I have to fix this one as well.

Thanks Eric,
-Lukas

> 
> Thanks,
> -Eric
>
diff mbox series

Patch

diff --git a/debugfs/debugfs.h b/debugfs/debugfs.h
index 477d9bbb..956517bc 100644
--- a/debugfs/debugfs.h
+++ b/debugfs/debugfs.h
@@ -123,6 +123,8 @@  extern void do_set_block_group_descriptor(int argc, char **, int sci_idx, void *
 extern void do_dump_unused(int argc, char **argv, int sci_idx, void *infop);
 
 /* debugfs.c */
+extern ss_request_table *extra_cmds;
+extern const char *debug_prog_name;
 extern void internal_dump_inode(FILE *, const char *, ext2_ino_t,
 				struct ext2_inode *, int);
 
diff --git a/lib/ext2fs/tst_libext2fs.c b/lib/ext2fs/tst_libext2fs.c
index 3e7497cd..43f0d153 100644
--- a/lib/ext2fs/tst_libext2fs.c
+++ b/lib/ext2fs/tst_libext2fs.c
@@ -28,9 +28,7 @@ 
  * Hook in new commands into debugfs
  * Override debugfs's prompt
  */
-const char *debug_prog_name = "tst_libext2fs";
 extern ss_request_table libext2fs_cmds;
-ss_request_table *extra_cmds = &libext2fs_cmds;
 
 static int print_blocks_proc(ext2_filsys fs EXT2FS_ATTR((unused)),
 			     blk64_t *blocknr, e2_blkcnt_t blockcnt,
@@ -51,6 +49,9 @@  void do_block_iterate(int argc, char **argv, int sci_idx EXT2FS_ATTR((unused)),
 	int		err = 0;
 	int		flags = 0;
 
+	debug_prog_name = "tst_libext2fs";
+	extra_cmds = &libext2fs_cmds;
+
 	if (common_args_process(argc, argv, 2, 3, argv[0], usage, 0))
 		return;