Skip to contentSkip to conversation

fix multiple definition linking error due to missing extern

PATCH In review Dirk Müller 3 participants 4 messages Feb 6, 2022 – Feb 8, 2022 MD RAID

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fix multiple definition linking error due to missing extern

GCC 10+ defaults to -fno-common, which enforces proper declaration of external references using "extern". without this change a link would fail with:

lib/raid6/test/algos.c:28: multiple definition of `raid6_call'; lib/raid6/test/test.c:22: first defined here

---
 lib/raid6/test/test.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/raid6/test/test.c +1 -1
index a3cf071941ab..ab0459150a61 100644
@@ -19,7 +19,7 @@
 #define NDISKS		16	/* Including P and Q */
 
 const char raid6_empty_zero_page[PAGE_SIZE] __attribute__((aligned(PAGE_SIZE)));
-struct raid6_calls raid6_call;
+extern struct raid6_calls raid6_call;
 
 char *dataptrs[NDISKS];
 char data[NDISKS][PAGE_SIZE] __attribute__((aligned(PAGE_SIZE)));
Signature · 1 line
2.35.1
Reviewed-by on v1 1/1
#1 lore raw

Dear Dirk,

Am 06.02.22 um 21:51 schrieb Dirk Müller:

It’d be great of you added a prefix in the commit message summary. Maybe:

Quoted 4 lines

lib/raid6/test: fix multiple definition linking error due to missing extern

GCC 10+ defaults to -fno-common, which enforces proper declaration of external references using "extern". without this change a link would

Nit: Without

Quoted 6 lines

fail with:

lib/raid6/test/algos.c:28: multiple definition of `raid6_call'; lib/raid6/test/test.c:22: first defined here

Thank you for properly analyzing and fixing it in a better way than my (non-working) attempt [1].

Should it be tagged for the stable series, that means CC’ed to <[email protected]>?

Quoted 9 lines
---
  lib/raid6/test/test.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
lib/raid6/test/test.c +0 -0
index a3cf071941ab..ab0459150a61 100644

lib/raid6/test/test.c line 25

Quoted 8 lines
lib/raid6/test/test.c +1 -1
@@ -19,7 +19,7 @@
  #define NDISKS		16	/* Including P and Q */
 
  const char raid6_empty_zero_page[PAGE_SIZE] __attribute__((aligned(PAGE_SIZE)));
-struct raid6_calls raid6_call;
+extern struct raid6_calls raid6_call;
 
  char *dataptrs[NDISKS];
  char data[NDISKS][PAGE_SIZE] __attribute__((aligned(PAGE_SIZE)));

Kind regards,

Paul

[1]: https://lore.kernel.org/linux-raid/[email protected]/T/#u

maintainer
#2 lore raw
In reply to Dirk Müller
Quoted 18 lines · Dirk Müller

GCC 10+ defaults to -fno-common, which enforces proper declaration of external references using "extern". without this change a link would fail with:

lib/raid6/test/algos.c:28: multiple definition of `raid6_call'; lib/raid6/test/test.c:22: first defined here

---
 lib/raid6/test/test.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/raid6/test/test.c +0 -0
index a3cf071941ab..ab0459150a61 100644

lib/raid6/test/test.c line 22

Quoted 5 lines
lib/raid6/test/test.c +1 -1
@@ -19,7 +19,7 @@
 #define NDISKS         16      /* Including P and Q */
 
 const char raid6_empty_zero_page[PAGE_SIZE] __attribute__((aligned(PAGE_SIZE)));
-struct raid6_calls raid6_call;
+extern struct raid6_calls raid6_call;

Can we just remove this line?

Thanks,
Song

#3 lore raw

On Dienstag, 8. Februar 2022 06:45:45 CET Song Liu wrote:

Hi Song,

Quoted 4 lines

lib/raid6/test/test.c line 22

Quoted 2 lines
lib/raid6/test/test.c +1 -1
-struct raid6_calls raid6_call;
+extern struct raid6_calls raid6_call;

Can we just remove this line?

oh yes indeed, it is already declared in the header file. that is much simpler. I've sent a PATCH v2 just now.

Thank you,
Dirk