Skip to contentSkip to conversation

autoconf: handle the standard --disable-shared flag

PATCH New Adam Joseph 2 participants 4 messages Sep 22, 2023 – Oct 13, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 autoconf: handle the standard --disable-shared flag

Since LVM 2.02 it appears that compiling LVM on a platform which lacks a shared library linker/loader will fail to produce any binaries (dmsetup, lvm2, etc).

This commit adds support for the standard --disable-shared flag, and uses it to disable attempts at building shared libraries.

---
 configure.ac               | 9 +++++++++
 libdm/Makefile.in          | 7 +++++++
 libdm/dm-tools/Makefile.in | 9 +++++++++
 libdm/make.tmpl.in         | 6 ++++++
 make.tmpl.in               | 4 ++++
 5 files changed, 35 insertions(+)
configure.ac +9 -0
index b43d8b9be..78aee5a9a 100644
@@ -185,6 +185,15 @@ AC_ARG_ENABLE(static_link,
 	      STATIC_LINK=$enableval, STATIC_LINK="no")
 AC_MSG_RESULT([$STATIC_LINK])
 
+AC_ARG_ENABLE(shared, AS_HELP_STRING([--enable-shared],[whether to build shared libraries [default=yes]]),
+  shared=$enableval, shared=yes)
+if test "$shared" = yes; then
+  AC_SUBST(ENABLE_SHARED, "yes", [whether to build shared libraries.])
+else
+  AC_SUBST(ENABLE_SHARED, "no", [whether to build shared libraries.])
+fi
+
+
 ################################################################################
 dnl -- Check if compiler/linker supports PIE and RELRO
 AC_TRY_CCFLAG([-pie], [HAVE_PIE], [], [])
libdm/Makefile.in +7 -0
index 2758648e6..30b2c798b 100644
@@ -47,7 +47,9 @@ endif
 
 LIB_SHARED = $(interface)/libdevmapper.$(LIB_SUFFIX)
 LIB_VERSION = $(LIB_VERSION_DM)
+ifeq ("@ENABLE_SHARED@", "yes")
 TARGETS = libdevmapper.$(LIB_SUFFIX) libdevmapper.$(LIB_SUFFIX).$(LIB_VERSION) .symver_check
+endif
 
 CFLOW_LIST = $(SOURCES)
 CFLOW_LIST_TARGET = libdevmapper.cflow
@@ -103,7 +105,12 @@ install_dynamic: install_ at interface@
 
 install_static: install_ at interface@_static
 
+ifeq ("@STATIC_LINK@", "yes")
+install_ioctl: install_ioctl_static
+endif
+ifeq ("@ENABLE_SHARED@", "yes")
 install_ioctl: install_lib_shared
+endif
 
 install_pkgconfig: libdevmapper.pc
 	@echo "    [INSTALL] $<"
libdm/dm-tools/Makefile.in +9 -0
index 78d2d719d..325f180c0 100644
@@ -19,13 +19,17 @@ top_builddir = @top_builddir@
 all: device-mapper
 
 SOURCES2 = dmsetup.c
+ifeq ("@ENABLE_SHARED@", "yes")
 TARGETS_DM = dmsetup
+endif
 
 CFLOW_SOURCES = $(addprefix $(srcdir)/, $(SOURCES2))
 CFLOW_TARGET := $(TARGETS_DM)
 -include $(top_builddir)/libdm/libdevmapper.cflow
 
+ifeq ("@ENABLE_SHARED@", "yes")
 install_device-mapper: install_dmsetup_dynamic
+endif
 
 ifeq ("@STATIC_LINK@", "yes")
   TARGETS_DM += dmsetup.static
@@ -99,6 +103,11 @@ install_dmfilemapd_static: dmfilemapd.static
 .PHONY: install_dmsetup_dynamic install_dmsetup_static
 .PHONY: install_dmfilemapd install_dmfilemapd_static
 
+ifeq ("@ENABLE_SHARED@", "yes")
 install: install_device-mapper install_dmfilemapd
+endif
+ifeq ("@STATIC_LINK@", "yes")
+install: install_dmsetup_static install_dmfilemapd_static
+endif
 
 device-mapper: $(TARGETS_DM)
libdm/make.tmpl.in +6 -0
index cc28e73cb..454e23512 100644
@@ -318,7 +318,11 @@ SUBDIRS.cflow := $(SUBDIRS:=.cflow)
 SUBDIRS.clean := $(SUBDIRS:=.clean)
 SUBDIRS.distclean := $(SUBDIRS:=.distclean)
 
+ifeq ("@ENABLE_SHARED@", "yes")
 TARGETS += $(LIB_SHARED) $(LIB_STATIC)
+else
+TARGETS += $(LIB_STATIC)
+endif
 
 all: $(SUBDIRS) $(TARGETS)
 
@@ -435,7 +439,9 @@ DEFS+=-D_FILE_OFFSET_BITS=64
 
 ifneq (,$(LIB_SHARED))
 
+ifeq ("@ENABLE_SHARED@", "yes")
 TARGETS += $(LIB_SHARED).$(LIB_VERSION)
+endif
 $(LIB_SHARED).$(LIB_VERSION): $(OBJECTS) $(LDDEPS)
 	@echo "    [CC] $@"
 ifeq ("@LIB_SUFFIX@","so")
make.tmpl.in +4 -0
index fcb62f78a..f61307b31 100644
@@ -372,7 +372,11 @@ SUBDIRS.cflow := $(SUBDIRS:=.cflow)
 SUBDIRS.clean := $(SUBDIRS:=.clean)
 SUBDIRS.distclean := $(SUBDIRS:=.distclean)
 
+ifeq ("@ENABLE_SHARED@", "yes")
 TARGETS += $(LIB_SHARED) $(LIB_STATIC)
+else
+TARGETS += $(LIB_STATIC)
+endif
 
 INTERNAL_LIBS = \
 	$(top_builddir)/libdaemon/client/libdaemonclient.a \
Signature · 1 line
2.41.0
#1 lore raw

PATCH 1/1 autoconf: handle the standard --disable-shared flag

Dne 22. 09. 23 v 8:47 Adam Joseph napsal(a):

Quoted 6 lines

Since LVM 2.02 it appears that compiling LVM on a platform which lacks a shared library linker/loader will fail to produce any binaries (dmsetup, lvm2, etc).

This commit adds support for the standard --disable-shared flag, and uses it to disable attempts at building shared libraries.

Quoted 8 lines
---
  configure.ac               | 9 +++++++++
  libdm/Makefile.in          | 7 +++++++
  libdm/dm-tools/Makefile.in | 9 +++++++++
  libdm/make.tmpl.in         | 6 ++++++
  make.tmpl.in               | 4 ++++
  5 files changed, 35 insertions(+)

Hi

The main problem with supporting anything for 'static' linkage is rather a lack of 'known' system that can be build with 'static' library of all other used libraries - and actually be usable.

I.e. static udev or static systemd must be some kind of unicorn I'd like to see myself.

So what is the system you are using ?

How is the lvm2 usable there ?

What libraries are present for usage ?

Do you purly target to have 'libdm' portion to be linked as static (aka only 'dmsetup' resulting binary - or do you need 'dmeventd' , or mayby libdevmapper.a ?)

Regards

Zdenek

#2 lore raw

PATCH 1/1 autoconf: handle the standard --disable-shared flag

Quoting Zdenek Kabelac (2023-09-26 12:53:59)

Quoted 3 lines

The main problem with supporting anything for 'static' linkage is rather a lack of 'known' system that can be build with 'static' library of all other used libraries - and actually be usable.

Oh it's quite usable; I've been using it on both my laptop and workstations for over a year. See below. Until recently I was using LVM 2.02 where all of this just worked with no patches; the submitted patch is necessary in order to fix a regression in LVM 2.03.

Quoted 1 line

I.e. static udev or static systemd

I don't use either of those. They are absent at compile time; lvm's configury notices this and disables them correctly.

Quoted 1 line

What libraries are present for usage ?

There are no .so files at runtime. None whatsoever. Anywhere.

Quoted 1 line

So what is the system you are using ?

At build time, nixpkgs (not nixos), statically linked against musl libc:

https://github.com/NixOS/nixpkgs/blob/master/pkgs/os-specific/linux/lvm2/common.nix

At runtime, ownerboot:

https://sr.ht/~amjoseph/ownerboot/

The kernel, lvm2, and cryptsetup are all stored on the SPI flash chip, allowing to completely encrypt the *entire* disk -- which UEFI is not capable of doing. The SPI flash chip is hardware write-protected (another thing most UEFIs can't tolerate) by shorting the WE# pin. This leaves no unencrypted writeable media anywhere on the system.

The minimal early system kexec()s another long-lived kernel loaded from the decrypted disk. It's very similar to what powerpc64 users do with petitboot, except that it's for amd64 and arm64.

Quoted 3 lines

Do you purly target to have 'libdm' portion to be linked as static (aka only 'dmsetup' resulting binary - or do you need 'dmeventd' , or mayby libdevmapper.a ?)

I personally need only dmsetup and lvm2 (within the dm-crypt volume is an lvm2 pv). I don't use dmeventd. However I do also include a statically-linked cryptsetup, which I believe links against libdevmapper.a (I would have to check to be sure).

However it's qute difficult to build a small cryptsetup binary -- their build process does not provide any way to compile out unnecessary things like bitlocker and veracrypt. Even using kernel crypto instead of openssl it's still 1.8Mbytes. I intend to move towards using dmsetup directly in order to save space.

- a

#3 lore raw

PATCH 1/1 autoconf: handle the standard --disable-shared flag

Dne 27. 09. 23 v 6:14 Adam Joseph napsal(a):

Quoted 10 lines

Quoting Zdenek Kabelac (2023-09-26 12:53:59)

Quoted 3 lines

The main problem with supporting anything for 'static' linkage is rather a lack of 'known' system that can be build with 'static' library of all other used libraries - and actually be usable.

Oh it's quite usable; I've been using it on both my laptop and workstations for over a year. See below. Until recently I was using LVM 2.02 where all of this just worked with no patches; the submitted patch is necessary in order to fix a regression in LVM 2.03.

Hi

Ok - so I've pushed some patches to immprove the static build support. Added also couple '--without-blkid|systemd|udev' options - (libaio.a has to exist as it's currently mandatory for lvm)

So please check the upstream main HEAD whether it's now fixed for your case.

There are possibly couple more enhancement around automatic combination of flags possibly be added.

Regards

Zdenek