Skip to content

Commit 38200b0

Browse files
committed
libyices: added option --without-gmp-embedded
This option will disable the partial linking that allows to embed GMP into libyices.a (only with --enable-static). For example, on Arch linux, the partial linking command ld -r -lgmp *.o -o libyices.o would fail even if libgmp.so is correclty installed. It seems that 'ld -r' would only work with a static libgmp.a (but the arch linux repo only installs the shared gmp library). Why this `ld -r`? This command is the only way I found to compile a static libyices.a from either a shared or a static libgmp and produce a gmp-depend-free libyices.a. Two solutions: 1. Drop the necessity for building a libyices.a free of gmp dependency. In this case, I could remove the `ld -r`. It would then create a libyices.a that depends on libgmp.a/so. 2. Separate the gmp-dependency-free libyices.a from the normal gmp-dependent libyices.a. For example, I could use the option `--without-gmp-embedded` So I did the solution (2).
1 parent 25d4a41 commit 38200b0

4 files changed

Lines changed: 45 additions & 4 deletions

File tree

ext/yices/Makefile

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -500,33 +500,42 @@ ifeq ($(enable_shared),yes)
500500
lib: $(builddir)/lib/libyices.la
501501
endif
502502
# Table of possibilities:
503-
# 1) static library
503+
# 1) static library with gmp embedded (= partially linked)
504504
# a) if libgmp.a has been found, create a libyices.a with gmp statically
505505
# linked. This uses partial linking offered by 'ld -r'.
506506
# Note: I think PIC should be disabled on libgmp.a for embeding it.
507507
# b) if libgmp.a has not been found, default to -lgmp. Most of the time,
508508
# this means that the gmp library will be dynamically linked.
509+
# 1b) static library with gmp not embedded (with --without-gmp-embedded)
510+
# a) and b) are the same except that 'ld -r' is not used.
509511
# 2) shared library
510512
# a) if libgmp.a has been found and contains PIC (position-independant code),
511513
# create a shared library that embeds the gmp library statically.
512514
# b) if libgmp.a has not been found, default to using -lgmp which means that
513515
# libyices.so (or .dylib or .dll) will also depend on the GMP shared library.
516+
514517
#
515-
# Static library.
518+
# Static library with and without GMP embedded.
516519
#
517520
# Precondition: STATIC_GMP and -lgmp most not be set simultanously. This
518521
# precondition is enforced in configure.ac.
519522
$(builddir)/lib/$(libyices_a): $(base_obj)
520523
$(MKDIR_P) $(dir $@)
524+
ifeq ($(GMP_EMBEDDED),yes)
525+
# 1) static library with gmp embedded (= partially linked)
521526
$(LD) -r -o $(builddir)/obj/libyices.o $(^:%.lo=%.o) $(LDFLAGS) $(STATIC_GMP) $(STATIC_LIBS) $(LIBS)
522527
$(AR) cru $@ $(builddir)/obj/libyices.o
528+
else
529+
# 1b) static library with gmp not embedded (with --without-gmp-embedded)
530+
$(LIBTOOL) $(LTFLAGS) --mode=link $(CC) -static -o $@ $^ $(STATIC_LIBS) $(LIBS)
531+
endif
523532
# NOTE: We use the variable libyices_a because on Windows, static and shared
524533
# both produce libyices.a. In this case, set libyices_a to something different
525534
# than libyices.a from the shared version.
526535
# NOTE: we cannot use libtool --mode=link instead of ld -r + ar cru because:
527-
# 1) for partially linking with 'ld -r', libtool --mode=link discards the arg
536+
# i) for partially linking with 'ld -r', libtool --mode=link discards the arg
528537
# 'libgmp.a' for some reason, even with the -Wl,libgmp.a trick.
529-
# 2) for archiving with 'ar cru', libtool --mode=link discards the *.o created
538+
# ii) for archiving with 'ar cru', libtool --mode=link discards the *.o created
530539
# in the previous stage. Some answers on these linker flags stripped:
531540
# https://www.gnu.org/software/libtool/manual/html_node/Stripped-link-flags.html
532541
#
@@ -537,6 +546,7 @@ $(builddir)/lib/$(libyices_a): $(base_obj)
537546
# Precondition: PIC_GMP and -lgmp most not be set simultanously
538547
RPATH ?= $(libdir)
539548
$(builddir)/lib/libyices.la: $(base_obj)
549+
# 2) shared library
540550
$(MKDIR_P) $(dir $@)
541551
$(LIBTOOL) $(LTFLAGS) --mode=link $(CC) -shared -o $@ $^ -rpath $(RPATH) \
542552
-version-number $(MAJOR):$(MINOR):$(PATCH_LEVEL) -no-undefined \

ext/yices/configure

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,7 @@ PIC_GMP
655655
STATIC_GMP_HAS_PIC
656656
STATIC_GMP_INCLUDE_DIR
657657
STATIC_GMP
658+
GMP_EMBEDDED
658659
MCSAT_CPPFLAGS
659660
NO_STACK_PROTECTOR
660661
STATIC_CPPFLAGS
@@ -770,6 +771,7 @@ with_static_libpoly_include_dir
770771
with_pic_libpoly
771772
with_pic_libpoly_include_dir
772773
with_shared_gmp
774+
with_gmp_embedded
773775
with_mode
774776
with_static_name
775777
'
@@ -1440,6 +1442,12 @@ Optional Packages:
14401442
be searched. This option forces the use of the
14411443
shared version. This applies for both shared and
14421444
static libraries.
1445+
--without-gmp-embedded (Only when --enable-static) By default, the static
1446+
library libyices.a created will be partially linked
1447+
(ld -r) so that the GMP library is not needed
1448+
afterwards (i.e., only -lyices is needed). If you
1449+
want to disable the partial linking (and thus -lgmp
1450+
and -lyices will be needed), you can use this flag.
14431451
--with-mode=MODE The mode used during compilation/distribution. It
14441452
can be one of release, debug, devel, profile, gcov,
14451453
valgrind, purify, quantify or gperftools. (default:
@@ -12368,6 +12376,16 @@ else
1236812376
fi
1236912377

1237012378

12379+
12380+
# Check whether --with-gmp-embedded was given.
12381+
if test "${with_gmp_embedded+set}" = set; then :
12382+
withval=$with_gmp_embedded; GMP_EMBEDDED=no
12383+
else
12384+
GMP_EMBEDDED=yes
12385+
fi
12386+
12387+
12388+
1237112389
#
1237212390
# CHECK LIBRARIES
1237312391
# ---------------
@@ -17760,6 +17778,7 @@ For static library $libyices_a:
1776017778
Libgmp.a path: $STATIC_GMP
1776117779
Libgmp.a is pic: $STATIC_GMP_HAS_PIC (non-PIC is faster for the static library)
1776217780
Use shared gmp instead of libgmp.a: $STATIC_YICES_USES_SHARED_GMP
17781+
Embed gmp in libyices.a: $GMP_EMBEDDED
1776317782

1776417783
For shared library:
1776517784
Enable: $enable_shared

ext/yices/configure.ac

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,16 @@ AC_ARG_WITH([shared-gmp],[AS_HELP_STRING([--with-shared-gmp],
334334
[FORCE_SHARED_GMP=yes],
335335
[FORCE_SHARED_GMP=no])
336336

337+
AC_ARG_WITH([gmp-embedded],[AS_HELP_STRING([--without-gmp-embedded],
338+
[(Only when --enable-static) By default, the static library libyices.a
339+
created will be partially linked (ld -r) so that the GMP library is not
340+
needed afterwards (i.e., only -lyices is needed). If you want to disable
341+
the partial linking (and thus -lgmp and -lyices will be needed), you
342+
can use this flag.])],
343+
[GMP_EMBEDDED=no],
344+
[GMP_EMBEDDED=yes])
345+
AC_SUBST(GMP_EMBEDDED)
346+
337347
#
338348
# CHECK LIBRARIES
339349
# ---------------
@@ -854,6 +864,7 @@ For static library $libyices_a:
854864
Libgmp.a path: $STATIC_GMP
855865
Libgmp.a is pic: $STATIC_GMP_HAS_PIC (non-PIC is faster for the static library)
856866
Use shared gmp instead of libgmp.a: $STATIC_YICES_USES_SHARED_GMP
867+
Embed gmp in libyices.a: $GMP_EMBEDDED
857868

858869
For shared library:
859870
Enable: $enable_shared

ext/yices/make.include.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ STATIC_GMP_LIB_DIR = @STATIC_GMP_LIB_DIR@
6969
STATIC_GMP_HAS_PIC = @STATIC_GMP_HAS_PIC@
7070
HAS_STATIC_GMP = @HAS_STATIC_GMP@
7171
HAS_SHARED_GMP = @HAS_SHARED_GMP@
72+
GMP_EMBEDDED = @GMP_EMBEDDED@
7273

7374
libyices_a = @libyices_a@
7475

0 commit comments

Comments
 (0)