Skip to contentSkip to conversation

mk: fix objects/library order when linking

PATCH Superseded David Marchand 3 participants 4 messages Dec 4, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mk: fix objects/library order when linking

It is safer to specify libraries we depend on after the objects we are linking into a shared library, especially when the linker is invoked with options like --as-needed.

Fixes bef06a8a0655 ("mk: set library dependencies in shared object file")
---
 mk/rte.lib.mk |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mk/rte.lib.mk +1 -1
index 06a1519..1f1b6e1 100644
@@ -82,7 +82,7 @@ O_TO_A_DO = @set -e; \
 	$(O_TO_A) && \
 	echo $(O_TO_A_CMD) > $(call exe2cmd,$(@))
 
-O_TO_S = $(LD) $(_CPU_LDFLAGS) $(EXTRA_LDFLAGS) $(LDLIBS) -shared $(OBJS-y) \
+O_TO_S = $(LD) $(_CPU_LDFLAGS) $(EXTRA_LDFLAGS) -shared $(OBJS-y) $(LDLIBS) \
 	 -Wl,-soname,$(LIB) -o $(LIB)
 O_TO_S_STR = $(subst ','\'',$(O_TO_S)) #'# fix syntax highlight
 O_TO_S_DISP = $(if $(V),"$(O_TO_S_STR)","  LD $(@)")
Signature · 1 line
1.7.10.4
#1 lore raw

PATCH v2 1/1 mk: fix objects/library order when linking

The initial problem has been seen while building mlx4 pmd as a shared library on Ubuntu 14.04 (gcc 4.8.4-2ubuntu1~14.04).

Resulting .so will lack the DT_NEEDED entry for libibverbs:

marchand@ubuntu1404:~/dpdk$ ldd ./build/lib/librte_pmd_mlx4.so
	linux-vdso.so.1 =>  (0x00007fff87ebb000)
	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f2ced21a000)
	/lib64/ld-linux-x86-64.so.2 (0x00007f2ced821000)

And trying to load it in testpmd triggers this error:

[...]
EAL: librte_pmd_mlx4.so: undefined symbol: ibv_query_port [...]

After some strace, the problem comes from the --as-needed option passed to the linker.

It is safer to specify libraries we depend on after the objects we are linking into a shared library, especially when the linker is invoked with options like --as-needed.

Fixes bef06a8a0655 ("mk: set library dependencies in shared object file")

---

Changes since v1:
- added some details in commitlog since Thomas does not like "safer" argument :-)

---

 mk/rte.lib.mk |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mk/rte.lib.mk +1 -1
index 06a1519..1f1b6e1 100644
@@ -82,7 +82,7 @@ O_TO_A_DO = @set -e; \
 	$(O_TO_A) && \
 	echo $(O_TO_A_CMD) > $(call exe2cmd,$(@))
 
-O_TO_S = $(LD) $(_CPU_LDFLAGS) $(EXTRA_LDFLAGS) $(LDLIBS) -shared $(OBJS-y) \
+O_TO_S = $(LD) $(_CPU_LDFLAGS) $(EXTRA_LDFLAGS) -shared $(OBJS-y) $(LDLIBS) \
 	 -Wl,-soname,$(LIB) -o $(LIB)
 O_TO_S_STR = $(subst ','\'',$(O_TO_S)) #'# fix syntax highlight
 O_TO_S_DISP = $(if $(V),"$(O_TO_S_STR)","  LD $(@)")
Signature · 1 line
1.7.10.4
Acked-by on v2 1/1
#2 lore raw
Quoted 23 lines · David Marchand

The initial problem has been seen while building mlx4 pmd as a shared library on Ubuntu 14.04 (gcc 4.8.4-2ubuntu1~14.04).

Resulting .so will lack the DT_NEEDED entry for libibverbs:

marchand@ubuntu1404:~/dpdk$ ldd ./build/lib/librte_pmd_mlx4.so
	linux-vdso.so.1 =>  (0x00007fff87ebb000)
	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f2ced21a000)
	/lib64/ld-linux-x86-64.so.2 (0x00007f2ced821000)

And trying to load it in testpmd triggers this error:

[...]
EAL: librte_pmd_mlx4.so: undefined symbol: ibv_query_port [...]

After some strace, the problem comes from the --as-needed option passed to the linker.

It is safer to specify libraries we depend on after the objects we are linking into a shared library, especially when the linker is invoked with options like --as-needed.

Quoted 8 lines
Fixes bef06a8a0655 ("mk: set library dependencies in shared object file")

---

Changes since v1:
- added some details in commitlog since Thomas does not like "safer" argument :-)

Obvious issue that did not show up in our tests under Debian.

Signature · 2 lines
Adrien Mazarguil
6WIND
#3 lore raw

2015-12-04 18:31, Adrien Mazarguil:

Quoted 24 lines · David Marchand
Quoted 23 lines

The initial problem has been seen while building mlx4 pmd as a shared library on Ubuntu 14.04 (gcc 4.8.4-2ubuntu1~14.04).

Resulting .so will lack the DT_NEEDED entry for libibverbs:

marchand@ubuntu1404:~/dpdk$ ldd ./build/lib/librte_pmd_mlx4.so
	linux-vdso.so.1 =>  (0x00007fff87ebb000)
	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f2ced21a000)
	/lib64/ld-linux-x86-64.so.2 (0x00007f2ced821000)

And trying to load it in testpmd triggers this error:

[...]
EAL: librte_pmd_mlx4.so: undefined symbol: ibv_query_port [...]

After some strace, the problem comes from the --as-needed option passed to the linker.

It is safer to specify libraries we depend on after the objects we are linking into a shared library, especially when the linker is invoked with options like --as-needed.

Quoted 8 lines
Quoted 8 lines
Fixes bef06a8a0655 ("mk: set library dependencies in shared object file")

---

Changes since v1:
- added some details in commitlog since Thomas does not like "safer" argument :-)

Yes, that's better justified with these details :)

Quoted 3 lines

Obvious issue that did not show up in our tests under Debian.

Applied, thanks