All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] tst_libext2fs: Avoid multiple definition of global variables
@ 2020-01-30 13:21 Lukas Czerner
  2020-02-06 17:52 ` Eric Sandeen
  2020-02-10 15:24 ` [PATCH v2] " Lukas Czerner
  0 siblings, 2 replies; 8+ messages in thread
From: Lukas Czerner @ 2020-01-30 13:21 UTC (permalink / raw)
  To: linux-ext4; +Cc: tytso

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(-)

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;
 
-- 
2.21.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH] tst_libext2fs: Avoid multiple definition of global variables
  2020-01-30 13:21 [PATCH] tst_libext2fs: Avoid multiple definition of global variables Lukas Czerner
@ 2020-02-06 17:52 ` Eric Sandeen
  2020-02-06 19:20   ` Lukas Czerner
  2020-02-10 15:24 ` [PATCH v2] " Lukas Czerner
  1 sibling, 1 reply; 8+ messages in thread
From: Eric Sandeen @ 2020-02-06 17:52 UTC (permalink / raw)
  To: Lukas Czerner, linux-ext4; +Cc: tytso

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] tst_libext2fs: Avoid multiple definition of global variables
  2020-02-06 17:52 ` Eric Sandeen
@ 2020-02-06 19:20   ` Lukas Czerner
  0 siblings, 0 replies; 8+ messages in thread
From: Lukas Czerner @ 2020-02-06 19:20 UTC (permalink / raw)
  To: Eric Sandeen; +Cc: linux-ext4, tytso

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
> 


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v2] tst_libext2fs: Avoid multiple definition of global variables
  2020-01-30 13:21 [PATCH] tst_libext2fs: Avoid multiple definition of global variables Lukas Czerner
  2020-02-06 17:52 ` Eric Sandeen
@ 2020-02-10 15:24 ` Lukas Czerner
  2020-02-11 20:22   ` Eric Sandeen
                     ` (2 more replies)
  1 sibling, 3 replies; 8+ messages in thread
From: Lukas Czerner @ 2020-02-10 15:24 UTC (permalink / raw)
  To: linux-ext4; +Cc: tytso, sandeen

gcc version 10 changed the default from -fcommon to -fno-common and as a
result e2fsprogs make check 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 using SKIP_GLOBDEFS macro to skip the variables
definition in debugfs.c. Note that debug_prog_name is also defined in
lib/ext2fs/extent.c when DEBUG macro is used, but this does not work even
with older gcc versions and is never used regardless so I am not going to
bother with it.

Signed-off-by: Lukas Czerner <lczerner@redhat.com>
---
v2: Previous fix wasn't really working properly

 debugfs/debugfs.c      | 6 ++++++
 debugfs/debugfs.h      | 2 ++
 lib/ext2fs/Makefile.in | 2 +-
 3 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/debugfs/debugfs.c b/debugfs/debugfs.c
index 9b701455..5e8f8bdd 100644
--- a/debugfs/debugfs.c
+++ b/debugfs/debugfs.c
@@ -48,8 +48,14 @@ extern char *optarg;
 int journal_enable_debug = -1;
 #endif
 
+/*
+ * There must be only one definition if we're hooking in extra commands or
+ * chaging default prompt. Use -DSKIP_GLOBDEF for that.
+ */
+#ifndef SKIP_GLOBDEFS
 ss_request_table *extra_cmds;
 const char *debug_prog_name;
+#endif
 int ss_sci_idx;
 
 ext2_filsys	current_fs;
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/Makefile.in b/lib/ext2fs/Makefile.in
index c2163bf5..f754b952 100644
--- a/lib/ext2fs/Makefile.in
+++ b/lib/ext2fs/Makefile.in
@@ -377,7 +377,7 @@ extent_cmds.c extent_cmds.h: $(top_srcdir)/debugfs/extent_cmds.ct
 
 debugfs.o: $(top_srcdir)/debugfs/debugfs.c
 	$(E) "	CC $<"
-	$(Q) $(CC) $(DEBUGFS_CFLAGS) -c $< -o $@
+	$(Q) $(CC) $(DEBUGFS_CFLAGS) -DSKIP_GLOBDEFS -c $< -o $@
 
 extent_inode.o: $(top_srcdir)/debugfs/extent_inode.c
 	$(E) "	CC $<"
-- 
2.21.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] tst_libext2fs: Avoid multiple definition of global variables
  2020-02-10 15:24 ` [PATCH v2] " Lukas Czerner
@ 2020-02-11 20:22   ` Eric Sandeen
  2020-02-11 21:08     ` Eric Sandeen
  2020-02-13 23:08   ` Eric Sandeen
  2020-02-28  3:34   ` Theodore Y. Ts'o
  2 siblings, 1 reply; 8+ messages in thread
From: Eric Sandeen @ 2020-02-11 20:22 UTC (permalink / raw)
  To: Lukas Czerner, linux-ext4; +Cc: tytso

On 2/10/20 9:24 AM, Lukas Czerner wrote:
> gcc version 10 changed the default from -fcommon to -fno-common and as a
> result e2fsprogs make check 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 using SKIP_GLOBDEFS macro to skip the variables
> definition in debugfs.c. Note that debug_prog_name is also defined in
> lib/ext2fs/extent.c when DEBUG macro is used, but this does not work even
> with older gcc versions and is never used regardless so I am not going to
> bother with it.
> 
> Signed-off-by: Lukas Czerner <lczerner@redhat.com>
> ---
> v2: Previous fix wasn't really working properly

What was not working properly?

It seemed reasonable to me.  The new mechanism looks like it would work,
but the first patch seemed more obvious, so I'd like to know what the problem
was.

Thanks,
-Eric


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] tst_libext2fs: Avoid multiple definition of global variables
  2020-02-11 20:22   ` Eric Sandeen
@ 2020-02-11 21:08     ` Eric Sandeen
  0 siblings, 0 replies; 8+ messages in thread
From: Eric Sandeen @ 2020-02-11 21:08 UTC (permalink / raw)
  To: Lukas Czerner, linux-ext4; +Cc: tytso

On 2/11/20 2:22 PM, Eric Sandeen wrote:
> On 2/10/20 9:24 AM, Lukas Czerner wrote:
>> gcc version 10 changed the default from -fcommon to -fno-common and as a
>> result e2fsprogs make check 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 using SKIP_GLOBDEFS macro to skip the variables
>> definition in debugfs.c. Note that debug_prog_name is also defined in
>> lib/ext2fs/extent.c when DEBUG macro is used, but this does not work even
>> with older gcc versions and is never used regardless so I am not going to
>> bother with it.
>>
>> Signed-off-by: Lukas Czerner <lczerner@redhat.com>
>> ---
>> v2: Previous fix wasn't really working properly
> 
> What was not working properly?
> 
> It seemed reasonable to me.  The new mechanism looks like it would work,
> but the first patch seemed more obvious, so I'd like to know what the problem
> was.

I built e2fsprogs & ran make check from git on Fedora Rawhide w/ your first patch,
and it all seemed to work fine so I'll just stand by for more info.  :)

-Eric


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] tst_libext2fs: Avoid multiple definition of global variables
  2020-02-10 15:24 ` [PATCH v2] " Lukas Czerner
  2020-02-11 20:22   ` Eric Sandeen
@ 2020-02-13 23:08   ` Eric Sandeen
  2020-02-28  3:34   ` Theodore Y. Ts'o
  2 siblings, 0 replies; 8+ messages in thread
From: Eric Sandeen @ 2020-02-13 23:08 UTC (permalink / raw)
  To: Lukas Czerner, linux-ext4; +Cc: tytso, sandeen

On 2/10/20 9:24 AM, Lukas Czerner wrote:
> gcc version 10 changed the default from -fcommon to -fno-common and as a
> result e2fsprogs make check 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 using SKIP_GLOBDEFS macro to skip the variables
> definition in debugfs.c. Note that debug_prog_name is also defined in
> lib/ext2fs/extent.c when DEBUG macro is used, but this does not work even
> with older gcc versions and is never used regardless so I am not going to
> bother with it.
> 
> Signed-off-by: Lukas Czerner <lczerner@redhat.com>
> ---
> v2: Previous fix wasn't really working properly


Lukas explained the problem to me - wow the test binaries are tricky.  ;)

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] tst_libext2fs: Avoid multiple definition of global variables
  2020-02-10 15:24 ` [PATCH v2] " Lukas Czerner
  2020-02-11 20:22   ` Eric Sandeen
  2020-02-13 23:08   ` Eric Sandeen
@ 2020-02-28  3:34   ` Theodore Y. Ts'o
  2 siblings, 0 replies; 8+ messages in thread
From: Theodore Y. Ts'o @ 2020-02-28  3:34 UTC (permalink / raw)
  To: Lukas Czerner; +Cc: linux-ext4, sandeen

On Mon, Feb 10, 2020 at 04:24:59PM +0100, Lukas Czerner wrote:
> gcc version 10 changed the default from -fcommon to -fno-common and as a
> result e2fsprogs make check 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 using SKIP_GLOBDEFS macro to skip the variables
> definition in debugfs.c. Note that debug_prog_name is also defined in
> lib/ext2fs/extent.c when DEBUG macro is used, but this does not work even
> with older gcc versions and is never used regardless so I am not going to
> bother with it.
> 
> Signed-off-by: Lukas Czerner <lczerner@redhat.com>

Applied, thanks.

						- Ted

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2020-02-28  3:34 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-30 13:21 [PATCH] tst_libext2fs: Avoid multiple definition of global variables Lukas Czerner
2020-02-06 17:52 ` Eric Sandeen
2020-02-06 19:20   ` Lukas Czerner
2020-02-10 15:24 ` [PATCH v2] " Lukas Czerner
2020-02-11 20:22   ` Eric Sandeen
2020-02-11 21:08     ` Eric Sandeen
2020-02-13 23:08   ` Eric Sandeen
2020-02-28  3:34   ` Theodore Y. Ts'o

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.