lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lwip-users] lwip has errors with linker optimization enabled


From: star keeper
Subject: [lwip-users] lwip has errors with linker optimization enabled
Date: Fri, 18 Jan 2019 07:59:16 +0100

Hi,
I have lwip running in a rather large project which uses the IAR compiler for ARM Cortex. The whole project is compiler using optimization level "low" and additionally the linker optimization option "merge_duplicate_sections" is enabled.
That means: merge_duplicate_sections => Merges equivalent read-only sections
 
That causes problems with lwip and the netconn_api. That api uses pointers to send them as events thru the mbox mechanism. Have a look at the variables whichs pointers will be send:
const u8_t netconn_aborted = 0;
const u8_t netconn_reset = 0;
const u8_t netconn_closed = 0;
 
These are three const varaibles with the same content, the linker optimizes this to one single variable and let them point to the same address. That is fatal because functions like "lwip_netconn_is_err_msg" will not work anymore:
int
lwip_netconn_is_err_msg(void *msg, err_t *err)
{
  LWIP_ASSERT("err != NULL", err != NULL);
  if (msg == &netconn_aborted) {
    *err = ERR_ABRT;
    return 1;
  } else if (msg == &netconn_reset) {
    *err = ERR_RST;
    return 1;
  } else if (msg == &netconn_closed) {
    *err = ERR_CLSD;
    return 1;
  }
  return 0;
}
 
The function "lwip_netconn_is_err_msg" will give me always ERR_ABRT even if the netconn was normaly closed.
 
For sure it is possible to disable the optimization for the lwip code parts. But in my opinion this is also a bad coding habit and can easily be fixed by giving the constants different values.
 
What is your opinion on that?

reply via email to

[Prev in Thread] Current Thread [Next in Thread]