[dpdk-dev,v2,4/6] mk: prevent overlinking in applications

Message ID 1465564749-1405-5-git-send-email-thomas.monjalon@6wind.com (mailing list archive)
State Accepted, archived
Headers

Commit Message

Thomas Monjalon June 10, 2016, 1:19 p.m. UTC
  From: Ferruh Yigit <ferruh.yigit@intel.com>

Replace --no-as-needed linker flag with --as-needed flag, which will
only link libraries directly called by application.
It can be achieved now that the libraries dependencies are handled
properly.

Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>
Signed-off-by: Thomas Monjalon <thomas.monjalon@6wind.com>
---
v2: remove workarounds and workaround comment
---
 mk/exec-env/linuxapp/rte.vars.mk | 3 ---
 mk/rte.app.mk                    | 3 +++
 2 files changed, 3 insertions(+), 3 deletions(-)
  

Comments

Ferruh Yigit June 10, 2016, 2:56 p.m. UTC | #1
On 6/10/2016 2:19 PM, Thomas Monjalon wrote:
> From: Ferruh Yigit <ferruh.yigit@intel.com>
> 
> Replace --no-as-needed linker flag with --as-needed flag, which will
> only link libraries directly called by application.
> It can be achieved now that the libraries dependencies are handled
> properly.
> 
> Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>
> Signed-off-by: Thomas Monjalon <thomas.monjalon@6wind.com>
> ---
...
>  endif
>  
> +# Link only the libraries used in the application
> +LDFLAGS += --as-needed

For the case we need to have workaround for application, this doesn't
let because last argument wins.

Can we say as following :
LDFLAGS = --as-needed $(LDFLAGS)


> +
>  # default path for libs
>  _LDLIBS-y += -L$(RTE_SDK_BIN)/lib
>  
>
  
Thomas Monjalon June 10, 2016, 3:15 p.m. UTC | #2
2016-06-10 15:56, Ferruh Yigit:
> On 6/10/2016 2:19 PM, Thomas Monjalon wrote:
> > From: Ferruh Yigit <ferruh.yigit@intel.com>
> > 
> > Replace --no-as-needed linker flag with --as-needed flag, which will
> > only link libraries directly called by application.
> > It can be achieved now that the libraries dependencies are handled
> > properly.
[...]
> > +# Link only the libraries used in the application
> > +LDFLAGS += --as-needed
> 
> For the case we need to have workaround for application, this doesn't
> let because last argument wins.
> 
> Can we say as following :
> LDFLAGS = --as-needed $(LDFLAGS)

It should be LDFLAGS := --as-needed $(LDFLAGS)
But I would prefer we avoid workarounds.
  

Patch

diff --git a/mk/exec-env/linuxapp/rte.vars.mk b/mk/exec-env/linuxapp/rte.vars.mk
index d51bd17..a8a1ee4 100644
--- a/mk/exec-env/linuxapp/rte.vars.mk
+++ b/mk/exec-env/linuxapp/rte.vars.mk
@@ -45,9 +45,6 @@  else
 EXECENV_CFLAGS  = -pthread
 endif
 
-# Workaround lack of DT_NEEDED entry
-EXECENV_LDFLAGS = --no-as-needed
-
 EXECENV_LDLIBS  =
 EXECENV_ASFLAGS =
 
diff --git a/mk/rte.app.mk b/mk/rte.app.mk
index 9306b30..d01a79f 100644
--- a/mk/rte.app.mk
+++ b/mk/rte.app.mk
@@ -50,6 +50,9 @@  ifeq ($(NO_LDSCRIPT),)
 LDSCRIPT = $(RTE_LDSCRIPT)
 endif
 
+# Link only the libraries used in the application
+LDFLAGS += --as-needed
+
 # default path for libs
 _LDLIBS-y += -L$(RTE_SDK_BIN)/lib