Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#4004 closed defect (fixed)

failing unit test when build time option --enable-static-link is used

Reported by: wlodekwencel Owned by: fdupont
Priority: low Milestone: Kea1.0-beta
Component: Unclassified Version: git
Keywords: Cc:
CVSS Scoring: Parent Tickets:
Sensitive: no Defect Severity: N/A
Sub-Project: DHCP Feature Depending on Ticket:
Estimated Difficulty: 0 Add Hours to Ticket: 0
Total Hours: 0 Internal?: no

Description (last modified by wlodekwencel)

If kea will be build with --enable-static-link unit test LibraryManagerTest?.libraryLoggerSetup is failing:

library_manager_unittest.cc:584
Value of: dict->getText("BCL_LOAD_START")
Actual: ""
Expected: "basic callout load %1"

Can be reproduced on any project at dev build farm.

Subtickets

Change History (17)

comment:1 Changed 4 years ago by wlodekwencel

  • Description modified (diff)

comment:2 Changed 4 years ago by hschempf

  • Milestone changed from Kea-proposed to Kea1.0
  • Priority changed from medium to low

comment:3 Changed 4 years ago by fdupont

The log library is loaded more than once so the singleton globalDictionary() fails to return one instance.
This code shows the problem:

const MessageDictionaryPtr&
MessageDictionary::globalDictionary() {
    static MessageDictionaryPtr global(new MessageDictionary());
 here:
    fprintf(stderr, "globalDictionary->%lx(%lx)", (unsigned long) &global,
                         (unsigned long) global.get());
    fprintf(stderr, " at %p\n", &&here);
    return (global);
}

(the GCC/CLANG specific &&tag returns the address of a tag. It is used usually the simulate a computed goto as for instance in a byte code virtual machine (this is why OCaml byte code execution is 40% slower when compiled by MSVC).

comment:4 Changed 4 years ago by fdupont

I found a way to solve this but it can conflicts with #3911 so I take the ticket and get instructions by jabber.

comment:5 Changed 4 years ago by fdupont

  • Owner set to fdupont
  • Status changed from new to accepted

comment:6 Changed 4 years ago by fdupont

The current src/lib/hooks/tests/Makefile.am is broken:

  • run_unittest must (re)export the symbols from libraries
  • the libtool -dlopen is a crazy idea: it leads for sure some libraries loaded twice so singletons not unique
  • the static link is in fact simpler (just don't use shared libraries: I repeat: don't use).
  • but there is an issue with hooksStaticLinkInit() function which must be explicitly exported.

Depends on #3911...

comment:7 Changed 4 years ago by fdupont

#3911 was merged so this ticket bumps!

comment:8 Changed 4 years ago by fdupont

I moved hooksStaticLinkInit() definition so it can be now cleanly referenced.
branch4004 works well on my OS X and on Jenkins.

I changed the enable/disable-shared/static behavior:

  • disable-shared and disable-static produce nothing (the configure machinery rejects this)
  • enable-shared and enable-static (default) work in all cases
  • enable-shared and disable-static work only with disable-static-link
  • disable-shared and enable-static require enable-static-link and of course unit tests on DSO do not pass (changed)

comment:9 Changed 4 years ago by fdupont

  • Owner changed from fdupont to UnAssigned
  • Status changed from accepted to reviewing

Branch trac4004 ready for review.

comment:10 Changed 4 years ago by stephen

  • Owner changed from UnAssigned to stephen

comment:11 follow-up: Changed 4 years ago by stephen

  • Owner changed from stephen to fdupont

Reviewed the branch from commit f8c2a7fb25efb27e52433d7918714c69b13dbf80 (where it branched from #4049) through to commit 8837571d29b276211d757ad7b9fc59b5bf78621a

src/lib/hooks/Makefile.am
One point: Although hooks.cc was removed and the function included in another module to ensure that the symbols is present, "hooks.h" should be included as a dependency in the Makefile.

Other Points
If I build with --enable-static-link then look at one of the images (kea-dhcp4 in this case) with "ldd", I see:

kea (trac4004):2064% cd src/bin/dhcp4
dhcp4 (trac4004):2065% file kea-dhcp4
kea-dhcp4: ELF 32-bit LSB executable, Intel 80386, version 1 (GNU/Linux), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=0xfff8f15b1dc5b7389e027da1b0c7a28a52d7abfe, not stripped
dhcp4 (trac4004):2066% ldd !$
ldd kea-dhcp4
	linux-gate.so.1 =>  (0x00b95000)
	libpthread.so.0 => /lib/i386-linux-gnu/libpthread.so.0 (0x00d4a000)
	liblog4cplus-1.0.so.4 => /opt/log4cplus-1.0.4/lib/liblog4cplus-1.0.so.4 (0x0016c000)
	libbotan-1.8.13.so => /usr/lib/libbotan-1.8.13.so (0x00744000)
	libdl.so.2 => /lib/i386-linux-gnu/libdl.so.2 (0x00f51000)
	libstdc++.so.6 => /usr/lib/i386-linux-gnu/libstdc++.so.6 (0x00272000)
	libgcc_s.so.1 => /lib/i386-linux-gnu/libgcc_s.so.1 (0x00110000)
	libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0x003de000)
	/lib/ld-linux.so.2 (0x00e27000)
	libm.so.6 => /lib/i386-linux-gnu/libm.so.6 (0x00ab9000)
	libbz2.so.1.0 => /lib/i386-linux-gnu/libbz2.so.1.0 (0x0012e000)
	libcrypto.so.1.0.0 => /lib/i386-linux-gnu/libcrypto.so.1.0.0 (0x00587000)
	libgmp.so.10 => /usr/lib/i386-linux-gnu/libgmp.so.10 (0x001cb000)
	librt.so.1 => /lib/i386-linux-gnu/librt.so.1 (0x00af9000)
	libz.so.1 => /lib/i386-linux-gnu/libz.so.1 (0x0013f000)

The same image, built without the --enable-static-link on the configure statement gives:

kea-1 (trac4004):2073% cd src/bin/dhcp4
dhcp4 (trac4004):2074% file kea-dhcp4
kea-dhcp4: Bourne-Again shell script, ASCII text executable, with very long lines
dhcp4 (trac4004):2075% file .libs/kea-dhcp4
.libs/kea-dhcp4: ELF 32-bit LSB executable, Intel 80386, version 1 (GNU/Linux), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=0xd2dce82a830ae028096cc5ad77051d5a89841c82, not stripped
dhcp4 (trac4004):2076% ldd .libs/kea-dhcp4
	linux-gate.so.1 =>  (0x00e92000)
	libkea-dhcpsrv.so.4 => not found
	libkea-dhcp_ddns.so.1 => not found
	libkea-stats.so.1 => not found
	libkea-cfgclient.so.2 => not found
	libkea-dhcp++.so.3 => not found
	libkea-asiolink.so.2 => not found
	libkea-cc.so.1 => not found
	libkea-cryptolink.so.1 => not found
	libkea-hooks.so.1 => not found
	libkea-log.so.0 => not found
	libkea-util.so.1 => not found
	libkea-exceptions.so.0 => not found
	libstdc++.so.6 => /usr/lib/i386-linux-gnu/libstdc++.so.6 (0x00af4000)
	libgcc_s.so.1 => /lib/i386-linux-gnu/libgcc_s.so.1 (0x00ef0000)
	libpthread.so.0 => /lib/i386-linux-gnu/libpthread.so.0 (0x00110000)
	libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0x0012b000)
	libm.so.6 => /lib/i386-linux-gnu/libm.so.6 (0x008ba000)
	/lib/ld-linux.so.2 (0x00f3f000)

In other words, --enable-static-link statically links against the Kea libraries, but not against libraries outside the Kea build tree. (There is also the issue that without --enable-static-link, libraries like libbotan are included in the ldd output, but not when Kea is linked dynamically. However, this may be due to the fact that Kea libraries are linked against it.)

comment:12 in reply to: ↑ 11 Changed 4 years ago by fdupont

  • Owner changed from fdupont to stephen

Replying to stephen:

Reviewed the branch from commit f8c2a7fb25efb27e52433d7918714c69b13dbf80 (where it branched from #4049) through to commit 8837571d29b276211d757ad7b9fc59b5bf78621a

src/lib/hooks/Makefile.am
One point: Although hooks.cc was removed and the function included in another module to ensure that the symbols is present, "hooks.h" should be included as a dependency in the Makefile.

=> fixed.

Other Points
If I build with --enable-static-link then look at one of the images (kea-dhcp4 in this case) with "ldd", I see:

kea (trac4004):2064% cd src/bin/dhcp4
dhcp4 (trac4004):2065% file kea-dhcp4
kea-dhcp4: ELF 32-bit LSB executable, Intel 80386, version 1 (GNU/Linux), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=0xfff8f15b1dc5b7389e027da1b0c7a28a52d7abfe, not stripped
dhcp4 (trac4004):2066% ldd !$
ldd kea-dhcp4
	linux-gate.so.1 =>  (0x00b95000)
	libpthread.so.0 => /lib/i386-linux-gnu/libpthread.so.0 (0x00d4a000)
	liblog4cplus-1.0.so.4 => /opt/log4cplus-1.0.4/lib/liblog4cplus-1.0.so.4 (0x0016c000)
	libbotan-1.8.13.so => /usr/lib/libbotan-1.8.13.so (0x00744000)
	libdl.so.2 => /lib/i386-linux-gnu/libdl.so.2 (0x00f51000)
	libstdc++.so.6 => /usr/lib/i386-linux-gnu/libstdc++.so.6 (0x00272000)
	libgcc_s.so.1 => /lib/i386-linux-gnu/libgcc_s.so.1 (0x00110000)
	libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0x003de000)
	/lib/ld-linux.so.2 (0x00e27000)
	libm.so.6 => /lib/i386-linux-gnu/libm.so.6 (0x00ab9000)
	libbz2.so.1.0 => /lib/i386-linux-gnu/libbz2.so.1.0 (0x0012e000)
	libcrypto.so.1.0.0 => /lib/i386-linux-gnu/libcrypto.so.1.0.0 (0x00587000)
	libgmp.so.10 => /usr/lib/i386-linux-gnu/libgmp.so.10 (0x001cb000)
	librt.so.1 => /lib/i386-linux-gnu/librt.so.1 (0x00af9000)
	libz.so.1 => /lib/i386-linux-gnu/libz.so.1 (0x0013f000)

=> this seems good, in particular there is no kea dynamic library.

The same image, built without the --enable-static-link on the configure statement gives:

> kea-1 (trac4004):2073% cd src/bin/dhcp4
> dhcp4 (trac4004):2074% file kea-dhcp4
> kea-dhcp4: Bourne-Again shell script, ASCII text executable, with very long lines

=> yes, libtool leaves a shell script which fixes the LD_LIBRARY_PATH for instance.

> dhcp4 (trac4004):2075% file .libs/kea-dhcp4
> .libs/kea-dhcp4: ELF 32-bit LSB executable, Intel 80386, version 1 (GNU/Linux), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=0xd2dce82a830ae028096cc5ad77051d5a89841c82, not stripped
> dhcp4 (trac4004):2076% ldd .libs/kea-dhcp4
> 	linux-gate.so.1 =>  (0x00e92000)
> 	libkea-dhcpsrv.so.4 => not found
> 	libkea-dhcp_ddns.so.1 => not found
> 	libkea-stats.so.1 => not found
> 	libkea-cfgclient.so.2 => not found
> 	libkea-dhcp++.so.3 => not found
> 	libkea-asiolink.so.2 => not found
> 	libkea-cc.so.1 => not found
> 	libkea-cryptolink.so.1 => not found
> 	libkea-hooks.so.1 => not found
> 	libkea-log.so.0 => not found
> 	libkea-util.so.1 => not found
> 	libkea-exceptions.so.0 => not found
> 	libstdc++.so.6 => /usr/lib/i386-linux-gnu/libstdc++.so.6 (0x00af4000)
> 	libgcc_s.so.1 => /lib/i386-linux-gnu/libgcc_s.so.1 (0x00ef0000)
> 	libpthread.so.0 => /lib/i386-linux-gnu/libpthread.so.0 (0x00110000)
> 	libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0x0012b000)
> 	libm.so.6 => /lib/i386-linux-gnu/libm.so.6 (0x008ba000)
> 	/lib/ld-linux.so.2 (0x00f3f000)

=> you should use libtool --mode=execute ldd kea-dhcp4 to get something really usable.

In other words, --enable-static-link statically links against the Kea libraries, but not against libraries outside the Kea build tree.

=> it is what is expected. BTW if you want to link with a static system or external library there should be not dynamic version. It is the way libtool -static works. Note you have libtool -all-static too but in general it doesn't do what you want... and the only system where you can really choose between static and dynamic versions is WIN32 (.lib file format is used for both so there can't be any ambiguity).

(There is also the issue that without --enable-static-link, libraries like libbotan are included in the ldd output, but not when Kea is linked dynamically. However, this may be due to the fact that Kea libraries are linked against it.)

=> just use ldd in the correct way to check the issue is a side effect of file vs ldd (otool -L on OS X).

comment:13 Changed 4 years ago by stephen

  • Owner changed from stephen to fdupont

In other words, --enable-static-link statically links against the Kea libraries, but not against libraries outside the Kea build tree.

it is what is expected. BTW if you want to link with a static system or external library there should be not dynamic version. It is the way libtool -static works. Note you have libtool -all-static too but in general it doesn't do what you want... and the only system where you can really choose between static and dynamic versions is WIN32 (.lib file format is used for both so there can't be any ambiguity).

OK.

All OK, please merge.

I think a ChangeLog is needed for this, perhaps something like:

Fixed problems when --enable-static-link is specified as a "configure" option.
With this switch present, no shared Kea libraries are built; all code Kea code
is included in the image.  However, note that Kea will still be linked dynamically
to the system libraries.

comment:14 Changed 4 years ago by fdupont

Merged (with a different ChangeLog, e.g., --enable-static-link still builds shared libraries). Jenkins is checking it (and if he is happy I'll close).

comment:15 Changed 4 years ago by wlodekwencel

Jenkins is in deed happy, good work

comment:16 Changed 4 years ago by fdupont

  • Resolution set to fixed
  • Status changed from reviewing to closed

Closing!

comment:17 Changed 4 years ago by tomek

  • Milestone changed from Kea1.0 to Kea1.0-beta

Milestone renamed

Note: See TracTickets for help on using tickets.