[2/3] common/mlx5: fix build with -fno-common
diff mbox series

Message ID 20200210103216.1168439-3-thomas@monjalon.net
State Superseded, archived
Delegated to: Raslan Darawsheh
Headers show
  • mlx: fix build with -fno-common (gcc 10)
Related show


Context Check Description
ci/Intel-compilation success Compilation OK
ci/checkpatch warning coding style issues

Commit Message

Thomas Monjalon Feb. 10, 2020, 10:32 a.m. UTC
The variable storages of the same name are merged together
if compiled with -fcommon. This is the default.
This default behaviour allows to declare a variable in a header file
and share the variable in every .o binaries thanks to merge at link-time.

In the case of dlopen linking of the glue library, the pointer mlx5_glue
is referencing the glue functions struct and is set after calling dlopen.

If compiling with -fno-common (default in GCC 10), the variable
must be declared as extern to avoid multiple re-definitions.
In case the glue layer is split in glue library, the variable mlx5_glue
needs to have its own storage for the rest of the PMD.

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
 drivers/common/mlx5/mlx5_common.c | 3 +++
 drivers/common/mlx5/mlx5_glue.h   | 2 +-
 2 files changed, 4 insertions(+), 1 deletion(-)

diff mbox series

diff --git a/drivers/common/mlx5/mlx5_common.c b/drivers/common/mlx5/mlx5_common.c
index f96506c27a..6110cf49de 100644
--- a/drivers/common/mlx5/mlx5_common.c
+++ b/drivers/common/mlx5/mlx5_common.c
@@ -16,6 +16,9 @@ 
 int mlx5_common_logtype;
+#ifdef MLX5_GLUE
+const struct mlx5_glue *mlx5_glue = NULL;
  * Get PCI information by sysfs device path.
diff --git a/drivers/common/mlx5/mlx5_glue.h b/drivers/common/mlx5/mlx5_glue.h
index 6238b43946..29678623e4 100644
--- a/drivers/common/mlx5/mlx5_glue.h
+++ b/drivers/common/mlx5/mlx5_glue.h
@@ -300,6 +300,6 @@  struct mlx5_glue {
 			 size_t event_resp_len);
-const struct mlx5_glue *mlx5_glue;
+extern const struct mlx5_glue *mlx5_glue;
 #endif /* MLX5_GLUE_H_ */