Skip to contentSkip to conversation

fix build with option -O1

PATCH Applied Thomas Monjalon 1 participant 7 messages Nov 16, 2018 – Nov 23, 2018 Network drivers

lore
Share & tools
lore
#1 lore raw

PATCH 1/5 eal: fix build with -O1

In reply to Thomas Monjalon

In case of optimized compilation, RTE_BUILD_BUG_ON use an external variable which is neither defined, nor used.
It seems not optimized out in case of OPDL compiled with clang -O1:
opdl_ring.c: undefined reference to `RTE_BUILD_BUG_ON_detected_error' clang-6.0: fatal error: linker command failed with exit code 1

Fixes af75078fece3 ("first public release")
---
 lib/librte_eal/common/include/rte_common.h | 9 ---------
 1 file changed, 9 deletions(-)
lib/librte_eal/common/include/rte_common.h +0 -9
index 87f0f6302..57acb8485 100644
@@ -270,16 +270,7 @@ rte_is_aligned(void *ptr, unsigned align)
 /**
  * Triggers an error at compilation time if the condition is true.
  */
-#ifndef __OPTIMIZE__
 #define RTE_BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
-#else
-extern int RTE_BUILD_BUG_ON_detected_error;
-#define RTE_BUILD_BUG_ON(condition) do {             \
-	((void)sizeof(char[1 - 2*!!(condition)]));   \
-	if (condition)                               \
-		RTE_BUILD_BUG_ON_detected_error = 1; \
-} while(0)
-#endif
 
 /**
  * Combines 32b inputs most significant set bits into the least
Signature · 1 line
2.19.0
#2 lore raw

PATCH 2/5 kni: fix possible uninitialized variable

In reply to Thomas Monjalon

This error can be raised:

	lib/librte_kni/rte_kni.c:531:15: error:
	'req' may be used uninitialized in this function

It should not happen because kni_fifo_get() would return 0 if req is not initialized, so the function would return before using req. But GCC complains about it in -O1 optimization,
and a NULL initialization is harmless here.

Fixes 3fc5ca2f6352 ("kni: initial import")
---
 lib/librte_kni/rte_kni.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/librte_kni/rte_kni.c +1 -1
index c9726d4f8..73aeccccf 100644
@@ -483,7 +483,7 @@ int
 rte_kni_handle_request(struct rte_kni *kni)
 {
 	unsigned ret;
-	struct rte_kni_request *req;
+	struct rte_kni_request *req = NULL;
 
 	if (kni == NULL)
 		return -1;
Signature · 1 line
2.19.0
#3 lore raw

PATCH 3/5 net/mlx4: fix possible uninitialized variable

In reply to Thomas Monjalon

When compiling with gcc -O1, this error appears:
drivers/net/mlx4/mlx4_ethdev.c: In function ‘mlx4_rxmode_toggle’:
rte_log.h:321:3: error:
‘mode’ may be used uninitialized in this function

The function mlx4_rxmode_toggle is never called with a value which is not in the switch block, but GCC complains about it with -O1. So the default case is "fixed" by setting string "undefined".

Fixes eacaac7bae36 ("net/mlx4: restore promisc and allmulti support")
---
 drivers/net/mlx4/mlx4_ethdev.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/net/mlx4/mlx4_ethdev.c +2 -0
index 30deb3ef0..195a1b6df 100644
@@ -360,6 +360,8 @@ mlx4_rxmode_toggle(struct rte_eth_dev *dev, enum rxmode_toggle toggle)
 		mode = "all multicast";
 		dev->data->all_multicast = toggle & 1;
 		break;
+	default:
+		mode = "undefined";
 	}
 	if (!mlx4_flow_sync(priv, &error))
 		return;
Signature · 1 line
2.19.0
#0 lore raw

cover fix build with option -O1

When trying to compile with -O1, the compiler shows some errors. Some are justified, others look like compiler bug. Anyway, it's better to fix all of them.

Thomas Monjalon (5):
eal: fix build with -O1
kni: fix possible uninitialized variable net/mlx4: fix possible uninitialized variable
eventdev: fix possible uninitialized variable app/eventdev: fix possible uninitialized variable

 app/test-eventdev/test_pipeline_common.c       | 2 +-
 drivers/net/mlx4/mlx4_ethdev.c                 | 2 ++
 lib/librte_eal/common/include/rte_common.h     | 9 ---------
 lib/librte_eventdev/rte_event_eth_tx_adapter.c | 2 +-
 lib/librte_kni/rte_kni.c                       | 2 +-
 5 files changed, 5 insertions(+), 12 deletions(-)
Signature · 1 line
2.19.0
#4 lore raw

PATCH 4/5 eventdev: fix possible uninitialized variable

When compiling with -O1, this error can appear:

	lib/librte_eventdev/rte_event_eth_tx_adapter.c:705:6: error:
	‘ret’ may be used uninitialized in this function

If tx_queue_id is -1 and nb_queues is 0, then ret is returned without being initialized.
It is fixed by setting 0 as initial value.

Fixes a3bbf2e09756 ("eventdev: add eth Tx adapter implementation")
---
 lib/librte_eventdev/rte_event_eth_tx_adapter.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/librte_eventdev/rte_event_eth_tx_adapter.c +1 -1
index 3a21defba..ccf8a7550 100644
@@ -702,7 +702,7 @@ txa_service_queue_add(uint8_t id,
 	struct txa_service_queue_info *tqi;
 	struct rte_eth_dev_tx_buffer *tb;
 	struct txa_retry *txa_retry;
-	int ret;
+	int ret = 0;
 
 	txa = txa_service_id_to_data(id);
 
Signature · 1 line
2.19.0
#5 lore raw

PATCH 5/5 app/eventdev: fix possible uninitialized variable

In reply to Thomas Monjalon

When compiling with -O1, this error can appear:

	app/test-eventdev/test_pipeline_common.c:332:6: error:
	‘ret’ may be used uninitialized in this function

If there is no device, then ret is returned without being initialized. It is fixed by setting 0 as initial value.

Fixes 032a965a8f1d ("app/eventdev: support Tx adapter")
---
 app/test-eventdev/test_pipeline_common.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
app/test-eventdev/test_pipeline_common.c +1 -1
index d07fa8826..5db3ffde1 100644
@@ -329,7 +329,7 @@ int
 pipeline_event_tx_adapter_setup(struct evt_options *opt,
 		struct rte_event_port_conf port_conf)
 {
-	int ret;
+	int ret = 0;
 	uint16_t consm;
 
 	RTE_ETH_FOREACH_DEV(consm) {
Signature · 1 line
2.19.0
author Applied
#6 lore raw
In reply to Thomas Monjalon
Quoted 6 lines

Thomas Monjalon (5):
eal: fix build with -O1
kni: fix possible uninitialized variable net/mlx4: fix possible uninitialized variable
eventdev: fix possible uninitialized variable app/eventdev: fix possible uninitialized variable

Applied