[FFmpeg-devel] [PATCH 03/11] Makefile: Redo duplicating object files in shared builds

Andreas Rheinhardt andreas.rheinhardt at outlook.com
Wed Dec 15 14:35:33 EET 2021


In case of shared builds, some object files containing tables
are currently duplicated into other libraries: log2_tab.c,
golomb.c, reverse.c. The check for whether this is duplicated
is simply whether CONFIG_SHARED is true. Yet this is crude:
E.g. libavdevice includes reverse.c for shared builds, but only
needs it for the decklink input device, which given that decklink
is not enabled by default will be unused in most libavdevice.so.

This commit changes this by making it more explicit about what
to duplicate from other libraries. To do this, two new Makefile
variables were added: SHLIBOBJS and STLIBOBJS. SHLIBOBJS contains
the objects that are duplicated from other libraries in case of
shared builds; STLIBOBJS contains stuff that a library has to
provide for other libraries in case of static builds. These new
variables provide a way to enable/disable with a finer granularity
than just whether shared builds are enabled or not. E.g. lavd's
Makefile now contains: SHLIBOBJS-$(CONFIG_DECKLINK_INDEV) += reverse.o

Another example is provided by the golomb tables. These are provided
by lavc for static builds, even if one uses a build configuration
that makes only lavf use them. Therefore lavc's Makefile contains
STLIBOBJS-$(CONFIG_MXF_MUXER) += golomb.o, whereas lavf's Makefile
has a corresponding SHLIBOBJS-$(CONFIG_MXF_MUXER) += golomb_tab.o.
E.g. in case the MXF muxer is the only component needing these tables
only libavformat.so will contain them for shared builds; currently
libavcodec.so does so, too.
(There is currently a CONFIG_EXTRA group for golomb. But actually
one would need two groups (golomb_avcodec and golomb_avformat) in
order to know when and where to include these tables. Therefore
this commit uses a Makefile-based approach for this and stops
using these groups for the users in libavformat.)

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>
---
 Makefile               |  2 +-
 configure              |  4 ++--
 ffbuild/common.mak     | 10 ++++++++--
 ffbuild/library.mak    | 22 +++++++++++++++++++---
 libavcodec/Makefile    | 10 ++++++++--
 libavdevice/Makefile   |  4 +++-
 libavfilter/Makefile   |  5 +++--
 libavformat/Makefile   |  6 +++++-
 libswresample/Makefile |  4 +++-
 libswscale/Makefile    |  3 ++-
 10 files changed, 54 insertions(+), 16 deletions(-)

diff --git a/Makefile b/Makefile
index 26c9107237..fd6a7f0230 100644
--- a/Makefile
+++ b/Makefile
@@ -89,7 +89,7 @@ SUBDIR_VARS := CLEANFILES FFLIBS HOSTPROGS TESTPROGS TOOLS               \
                ARMV5TE-OBJS ARMV6-OBJS ARMV8-OBJS VFP-OBJS NEON-OBJS     \
                ALTIVEC-OBJS VSX-OBJS MMX-OBJS X86ASM-OBJS                \
                MIPSFPU-OBJS MIPSDSPR2-OBJS MIPSDSP-OBJS MSA-OBJS         \
-               MMI-OBJS OBJS SLIBOBJS HOSTOBJS TESTOBJS
+               MMI-OBJS OBJS SLIBOBJS SHLIBOBJS STLIBOBJS HOSTOBJS TESTOBJS
 
 define RESET
 $(1) :=
diff --git a/configure b/configure
index a7593ec2db..ab1b9f6b66 100755
--- a/configure
+++ b/configure
@@ -3419,7 +3419,7 @@ mp4_muxer_select="mov_muxer"
 mpegts_demuxer_select="iso_media"
 mpegts_muxer_select="ac3_parser adts_muxer latm_muxer h264_mp4toannexb_bsf hevc_mp4toannexb_bsf"
 mpegtsraw_demuxer_select="mpegts_demuxer"
-mxf_muxer_select="golomb pcm_rechunk_bsf"
+mxf_muxer_select="pcm_rechunk_bsf"
 mxf_d10_muxer_select="mxf_muxer"
 mxf_opatom_muxer_select="mxf_muxer"
 nut_muxer_select="riffenc"
@@ -3432,7 +3432,7 @@ ogv_muxer_select="ogg_muxer"
 opus_muxer_select="ogg_muxer"
 psp_muxer_select="mov_muxer"
 rtp_demuxer_select="sdp_demuxer"
-rtp_muxer_select="golomb jpegtables"
+rtp_muxer_select="jpegtables"
 rtp_mpegts_muxer_select="mpegts_muxer rtp_muxer"
 rtpdec_select="asf_demuxer jpegtables mov_demuxer mpegts_demuxer rm_demuxer rtp_protocol srtp"
 rtsp_demuxer_select="http_protocol rtpdec"
diff --git a/ffbuild/common.mak b/ffbuild/common.mak
index 268ae61154..616d39ddba 100644
--- a/ffbuild/common.mak
+++ b/ffbuild/common.mak
@@ -140,6 +140,8 @@ include $(SRC_PATH)/ffbuild/arch.mak
 
 OBJS      += $(OBJS-yes)
 SLIBOBJS  += $(SLIBOBJS-yes)
+SHLIBOBJS += $(SHLIBOBJS-yes)
+STLIBOBJS += $(STLIBOBJS-yes)
 FFLIBS    := $($(NAME)_FFLIBS) $(FFLIBS-yes) $(FFLIBS)
 TESTPROGS += $(TESTPROGS-yes)
 
@@ -148,6 +150,8 @@ FFEXTRALIBS := $(LDLIBS:%=$(LD_LIB)) $(foreach lib,EXTRALIBS-$(NAME) $(FFLIBS:%=
 
 OBJS      := $(sort $(OBJS:%=$(SUBDIR)%))
 SLIBOBJS  := $(sort $(SLIBOBJS:%=$(SUBDIR)%))
+SHLIBOBJS := $(sort $(SHLIBOBJS:%=$(SUBDIR)%))
+STLIBOBJS := $(sort $(STLIBOBJS:%=$(SUBDIR)%))
 TESTOBJS  := $(TESTOBJS:%=$(SUBDIR)tests/%) $(TESTPROGS:%=$(SUBDIR)tests/%.o)
 TESTPROGS := $(TESTPROGS:%=$(SUBDIR)tests/%$(EXESUF))
 HOSTOBJS  := $(HOSTPROGS:%=$(SUBDIR)%.o)
@@ -183,10 +187,12 @@ $(OBJS):     | $(sort $(dir $(OBJS)))
 $(HOBJS):    | $(sort $(dir $(HOBJS)))
 $(HOSTOBJS): | $(sort $(dir $(HOSTOBJS)))
 $(SLIBOBJS): | $(sort $(dir $(SLIBOBJS)))
+$(SHLIBOBJS): | $(sort $(dir $(SHLIBOBJS)))
+$(STLIBOBJS): | $(sort $(dir $(STLIBOBJS)))
 $(TESTOBJS): | $(sort $(dir $(TESTOBJS)))
 $(TOOLOBJS): | tools
 
-OUTDIRS := $(OUTDIRS) $(dir $(OBJS) $(HOBJS) $(HOSTOBJS) $(SLIBOBJS) $(TESTOBJS))
+OUTDIRS := $(OUTDIRS) $(dir $(OBJS) $(HOBJS) $(HOSTOBJS) $(SLIBOBJS) $(SHLIBOBJS) $(STLIBOBJS) $(TESTOBJS))
 
 CLEANSUFFIXES     = *.d *.gcda *.gcno *.h.c *.ho *.map *.o *.pc *.ptx *.ptx.gz *.ptx.c *.ver *.version *$(DEFAULT_X86ASMD).asm *~ *.ilk *.pdb
 LIBSUFFIXES       = *.a *.lib *.so *.so.* *.dylib *.dll *.def *.dll.a
@@ -198,4 +204,4 @@ endef
 
 $(eval $(RULES))
 
--include $(wildcard $(OBJS:.o=.d) $(HOSTOBJS:.o=.d) $(TESTOBJS:.o=.d) $(HOBJS:.o=.d) $(SLIBOBJS:.o=.d)) $(OBJS:.o=$(DEFAULT_X86ASMD).d)
+-include $(wildcard $(OBJS:.o=.d) $(HOSTOBJS:.o=.d) $(TESTOBJS:.o=.d) $(HOBJS:.o=.d) $(SHLIBOBJS:.o=.d) $(STLIBOBJS:.o=.d) $(SLIBOBJS:.o=.d)) $(OBJS:.o=$(DEFAULT_X86ASMD).d)
diff --git a/ffbuild/library.mak b/ffbuild/library.mak
index 612bacb980..ad09f20da9 100644
--- a/ffbuild/library.mak
+++ b/ffbuild/library.mak
@@ -14,10 +14,26 @@ INSTHEADERS := $(INSTHEADERS) $(HEADERS:%=$(SUBDIR)%)
 all-$(CONFIG_STATIC): $(SUBDIR)$(LIBNAME)  $(SUBDIR)lib$(FULLNAME).pc
 all-$(CONFIG_SHARED): $(SUBDIR)$(SLIBNAME) $(SUBDIR)lib$(FULLNAME).pc
 
-LIBOBJS := $(OBJS) $(SUBDIR)%.h.o $(TESTOBJS)
+LIBOBJS := $(OBJS) $(SHLIBOBJS) $(STLIBOBJS) $(SUBDIR)%.h.o $(TESTOBJS)
 $(LIBOBJS) $(LIBOBJS:.o=.s) $(LIBOBJS:.o=.i):   CPPFLAGS += -DHAVE_AV_CONFIG_H
 
-$(SUBDIR)$(LIBNAME): $(OBJS)
+ifdef CONFIG_SHARED
+# In case both shared libs and static libs are enabled, it can happen
+# that a user might want to link e.g. libavformat statically, but
+# libavcodec and the other libs dynamically. In this case
+# libavformat won't be able to access libavcodec's internal symbols,
+# so that they have to be duplicated into the archive just like
+# for purely shared builds.
+# Test programs are always statically linked against their library
+# to be able to access their library's internals, even with shared builds.
+# Yet linking against dependend libraries still uses dynamic linking.
+# This means that we are in the scenario described above.
+# In case only static libs are used, the linker will only use
+# one of these copies; this depends on the duplicated object files
+# containing exactly the same symbols.
+OBJS += $(SHLIBOBJS)
+endif
+$(SUBDIR)$(LIBNAME): $(OBJS) $(STLIBOBJS)
 	$(RM) $@
 	$(AR) $(ARFLAGS) $(AR_O) $^
 	$(RANLIB) $@
@@ -48,7 +64,7 @@ $(SUBDIR)lib$(NAME).ver: $(SUBDIR)lib$(NAME).v $(OBJS)
 $(SUBDIR)$(SLIBNAME): $(SUBDIR)$(SLIBNAME_WITH_MAJOR)
 	$(Q)cd ./$(SUBDIR) && $(LN_S) $(SLIBNAME_WITH_MAJOR) $(SLIBNAME)
 
-$(SUBDIR)$(SLIBNAME_WITH_MAJOR): $(OBJS) $(SLIBOBJS) $(SUBDIR)lib$(NAME).ver
+$(SUBDIR)$(SLIBNAME_WITH_MAJOR): $(OBJS) $(SHLIBOBJS) $(SLIBOBJS) $(SUBDIR)lib$(NAME).ver
 	$(SLIB_CREATE_DEF_CMD)
 	$$(LD) $(SHFLAGS) $(LDFLAGS) $(LDSOFLAGS) $$(LD_O) $$(filter %.o,$$^) $(FFEXTRALIBS)
 	$(SLIB_EXTRA_CMD)
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index fb90ecea84..d855f5a229 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -139,7 +139,6 @@ OBJS-$(CONFIG_QSVENC)                  += qsvenc.o
 OBJS-$(CONFIG_RANGECODER)              += rangecoder.o
 OBJS-$(CONFIG_RDFT)                    += rdft.o
 OBJS-$(CONFIG_RV34DSP)                 += rv34dsp.o
-OBJS-$(CONFIG_SHARED)                  += log2_tab.o reverse.o
 OBJS-$(CONFIG_SINEWIN)                 += sinewin.o
 OBJS-$(CONFIG_SNAPPY)                  += snappy.o
 OBJS-$(CONFIG_STARTCODE)               += startcode.o
@@ -979,7 +978,10 @@ OBJS-$(CONFIG_VP9_VDPAU_HWACCEL)          += vdpau_vp9.o
 OBJS-$(CONFIG_VP9_VIDEOTOOLBOX_HWACCEL)   += videotoolbox_vp9.o
 OBJS-$(CONFIG_VP8_QSV_HWACCEL)            += qsvdec.o
 
-# libavformat dependencies
+# Objects duplicated from other libraries for shared builds
+SHLIBOBJS                              += log2_tab.o reverse.o
+
+# General libavformat dependencies
 OBJS-$(CONFIG_ISO_MEDIA)               += mpeg4audio.o mpegaudiodata.o
 
 OBJS-$(CONFIG_ADTS_MUXER)              += mpeg4audio.o
@@ -995,6 +997,10 @@ OBJS-$(CONFIG_SPDIF_MUXER)             += dca.o
 OBJS-$(CONFIG_TAK_DEMUXER)             += tak.o
 OBJS-$(CONFIG_WEBM_MUXER)              += mpeg4audio.o
 
+# libavformat dependencies for static builds
+STLIBOBJS-$(CONFIG_MXF_MUXER)          += golomb.o
+STLIBOBJS-$(CONFIG_RTP_MUXER)          += golomb.o
+
 # libavfilter dependencies
 OBJS-$(CONFIG_ELBG_FILTER)             += elbg.o
 
diff --git a/libavdevice/Makefile b/libavdevice/Makefile
index 0dfe47a1f4..53efda0514 100644
--- a/libavdevice/Makefile
+++ b/libavdevice/Makefile
@@ -9,7 +9,6 @@ OBJS    = alldevices.o                                                  \
           utils.o                                                       \
 
 OBJS-$(HAVE_LIBC_MSVCRT)                 += file_open.o
-OBJS-$(CONFIG_SHARED)                    += reverse.o
 
 # input/output devices
 OBJS-$(CONFIG_ALSA_INDEV)                += alsa_dec.o alsa.o timefilter.o
@@ -54,6 +53,9 @@ OBJS-$(CONFIG_XV_OUTDEV)                 += xv.o
 OBJS-$(CONFIG_LIBCDIO_INDEV)             += libcdio.o
 OBJS-$(CONFIG_LIBDC1394_INDEV)           += libdc1394.o
 
+# Objects duplicated from other libraries for shared builds
+SHLIBOBJS-$(CONFIG_DECKLINK_INDEV)       += reverse.o
+
 # Windows resource file
 SLIBOBJS-$(HAVE_GNU_WINDRES)             += avdeviceres.o
 
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 2fe495df28..f4f077af46 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -572,13 +572,14 @@ OBJS-$(CONFIG_SPECTRUMSYNTH_FILTER)          += vaf_spectrumsynth.o
 OBJS-$(CONFIG_AMOVIE_FILTER)                 += src_movie.o
 OBJS-$(CONFIG_MOVIE_FILTER)                  += src_movie.o
 
+# Objects duplicated from other libraries for shared builds
+SHLIBOBJS                                    += log2_tab.o
+
 # Windows resource file
 SLIBOBJS-$(HAVE_GNU_WINDRES)                 += avfilterres.o
 
 SKIPHEADERS-$(CONFIG_LIBVIDSTAB)             += vidstabutils.h
 
-OBJS-$(CONFIG_SHARED)                        += log2_tab.o
-
 SKIPHEADERS-$(CONFIG_QSVVPP)                 += qsvvpp.h
 SKIPHEADERS-$(CONFIG_OPENCL)                 += opencl.h
 SKIPHEADERS-$(CONFIG_VAAPI)                  += vaapi_vpp.h
diff --git a/libavformat/Makefile b/libavformat/Makefile
index 2b5caf9d33..2b5bb43745 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -61,7 +61,6 @@ OBJS-$(CONFIG_RTPDEC)                    += rdt.o                       \
                                             rtpdec_vp9.o                \
                                             rtpdec_xiph.o
 OBJS-$(CONFIG_RTPENC_CHAIN)              += rtpenc_chain.o rtp.o
-OBJS-$(CONFIG_SHARED)                    += log2_tab.o golomb_tab.o
 OBJS-$(CONFIG_SRTP)                      += srtp.o
 
 # muxers/demuxers
@@ -677,6 +676,11 @@ OBJS-$(CONFIG_LIBSRT_PROTOCOL)           += libsrt.o
 OBJS-$(CONFIG_LIBSSH_PROTOCOL)           += libssh.o
 OBJS-$(CONFIG_LIBZMQ_PROTOCOL)           += libzmq.o
 
+# Objects duplicated from other libraries for shared builds
+SHLIBOBJS                                += log2_tab.o
+SHLIBOBJS-$(CONFIG_MXF_MUXER)            += golomb_tab.o
+SHLIBOBJS-$(CONFIG_RTP_MUXER)            += golomb_tab.o
+
 # libavdevice dependencies
 OBJS-$(CONFIG_IEC61883_INDEV)            += dv.o
 
diff --git a/libswresample/Makefile b/libswresample/Makefile
index 42666e4dd2..f528427f55 100644
--- a/libswresample/Makefile
+++ b/libswresample/Makefile
@@ -15,7 +15,9 @@ OBJS = audioconvert.o                        \
        swresample_frame.o                    \
 
 OBJS-$(CONFIG_LIBSOXR) += soxr_resample.o
-OBJS-$(CONFIG_SHARED)  += log2_tab.o
+
+# Objects duplicated from other libraries for shared builds
+SHLIBOBJS              += log2_tab.o
 
 # Windows resource file
 SLIBOBJS-$(HAVE_GNU_WINDRES) += swresampleres.o
diff --git a/libswscale/Makefile b/libswscale/Makefile
index 4b8f9de425..a0ec71e06f 100644
--- a/libswscale/Makefile
+++ b/libswscale/Makefile
@@ -19,7 +19,8 @@ OBJS = alphablend.o                                     \
        yuv2rgb.o                                        \
        vscale.o                                         \
 
-OBJS-$(CONFIG_SHARED)        += log2_tab.o
+# Objects duplicated from other libraries for shared builds
+SHLIBOBJS                    += log2_tab.o
 
 # Windows resource file
 SLIBOBJS-$(HAVE_GNU_WINDRES) += swscaleres.o
-- 
2.32.0



More information about the ffmpeg-devel mailing list