[4/5] configure: Use dllexport/dllimport for data symbols across DLLs with mingw

Message ID 1503647204-20460-4-git-send-email-martin@martin.st
State Committed
Headers show

Commit Message

Martin Storsjö Aug. 25, 2017, 7:46 a.m.
This avoids having to use pseudo relocations.

The version script used for exporting functions is skipped as soon
as the set of object files contains symbols marked with dllexport,
therefore we need to use makedef to produce the full list of symbols
to be exported.
---
Improved commit message, renamed makefile variables slightly.
---
 configure             | 11 +++++++++--
 libavcodec/internal.h |  2 +-
 2 files changed, 10 insertions(+), 3 deletions(-)

Comments

Diego Biurrun Sept. 2, 2017, 11:59 p.m. | #1
On Fri, Aug 25, 2017 at 10:46:43AM +0300, Martin Storsjö wrote:
> --- a/configure
> +++ b/configure
> @@ -4032,6 +4032,10 @@ case $target_os in
>          elif enabled arm; then
>              LIBTARGET=arm-wince
>          fi
> +        if enabled shared; then
> +            # Cannot build both shared and static libs when using dllexport.
> +            disable static
> +        fi
>          check_ldflags -Wl,--nxcompat
>          check_ldflags -Wl,--dynamicbase
>          shlibdir_default="$bindir_default"
> @@ -4039,12 +4043,13 @@ case $target_os in
>          SLIBSUF=".dll"
>          SLIBNAME_WITH_VERSION='$(SLIBPREF)$(NAME)-$(LIBVERSION)$(SLIBSUF)'
>          SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(NAME)-$(LIBMAJOR)$(SLIBSUF)'
> -        SLIB_EXTRA_CMD=-'sed -e "s/ @[^ ]*//" $$(@:$(SLIBSUF)=.orig.def) > $$(@:$(SLIBSUF)=.def); $(DLLTOOL) -m $(LIBTARGET) -d $$(@:$(SLIBSUF)=.def) -l $(SUBDIR)$(SLIBNAME:$(SLIBSUF)=.lib) -D $(SLIBNAME_WITH_MAJOR)'
> +        SLIB_EXTRA_CMD=-'$(DLLTOOL) -m $(LIBTARGET) -d $$(@:$(SLIBSUF)=.def) -l $(SUBDIR)$(SLIBNAME:$(SLIBSUF)=.lib) -D $(SLIBNAME_WITH_MAJOR)'
>          SLIB_INSTALL_NAME='$(SLIBNAME_WITH_MAJOR)'
>          SLIB_INSTALL_LINKS=
>          SLIB_INSTALL_EXTRA_SHLIB='$(SLIBNAME:$(SLIBSUF)=.lib)'
>          SLIB_INSTALL_EXTRA_LIB='lib$(SLIBNAME:$(SLIBSUF)=.dll.a) $(SLIBNAME_WITH_MAJOR:$(SLIBSUF)=.def)'
> -        SHFLAGS='-shared -Wl,--output-def,$$(@:$(SLIBSUF)=.orig.def) -Wl,--out-implib,$(SUBDIR)lib$(SLIBNAME:$(SLIBSUF)=.dll.a) -Wl,--enable-runtime-pseudo-reloc -Wl,--enable-auto-image-base'
> +        SLIB_CREATE_DEF_CMD='ARCH="$(ARCH)" AR="$(AR_CMD)" NM="$(NM_CMD)" $(SRC_PATH)/compat/windows/makedef $(SUBDIR)lib$(NAME).ver $(OBJS) > $$(@:$(SLIBSUF)=.def)'
> +        SHFLAGS='-shared -Wl,--out-implib,$(SUBDIR)lib$(SLIBNAME:$(SLIBSUF)=.dll.a) -Wl,--enable-auto-image-base $$(@:$(SLIBSUF)=.def)'
>          enabled x86_64 && objformat="win64" || objformat="win32"
>          dlltool="${cross_prefix}dlltool"
>          ranlib=:
> @@ -5438,6 +5443,8 @@ DEPX86ASMFLAGS=\$(X86ASMFLAGS)
>  AR=$ar
>  ARFLAGS=$arflags
>  AR_O=$ar_o
> +AR_CMD=$ar
> +NM_CMD=$nm

You need these extra indirections over the AR and NM variables in the
Makefile because ... ?

Diego
Martin Storsjö Sept. 3, 2017, 10:02 a.m. | #2
On Sun, 3 Sep 2017, Diego Biurrun wrote:

> On Fri, Aug 25, 2017 at 10:46:43AM +0300, Martin Storsjö wrote:
>> --- a/configure
>> +++ b/configure
>> @@ -4032,6 +4032,10 @@ case $target_os in
>>          elif enabled arm; then
>>              LIBTARGET=arm-wince
>>          fi
>> +        if enabled shared; then
>> +            # Cannot build both shared and static libs when using dllexport.
>> +            disable static
>> +        fi
>>          check_ldflags -Wl,--nxcompat
>>          check_ldflags -Wl,--dynamicbase
>>          shlibdir_default="$bindir_default"
>> @@ -4039,12 +4043,13 @@ case $target_os in
>>          SLIBSUF=".dll"
>>          SLIBNAME_WITH_VERSION='$(SLIBPREF)$(NAME)-$(LIBVERSION)$(SLIBSUF)'
>>          SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(NAME)-$(LIBMAJOR)$(SLIBSUF)'
>> -        SLIB_EXTRA_CMD=-'sed -e "s/ @[^ ]*//" $$(@:$(SLIBSUF)=.orig.def) > $$(@:$(SLIBSUF)=.def); $(DLLTOOL) -m $(LIBTARGET) -d $$(@:$(SLIBSUF)=.def) -l $(SUBDIR)$(SLIBNAME:$(SLIBSUF)=.lib) -D $(SLIBNAME_WITH_MAJOR)'
>> +        SLIB_EXTRA_CMD=-'$(DLLTOOL) -m $(LIBTARGET) -d $$(@:$(SLIBSUF)=.def) -l $(SUBDIR)$(SLIBNAME:$(SLIBSUF)=.lib) -D $(SLIBNAME_WITH_MAJOR)'
>>          SLIB_INSTALL_NAME='$(SLIBNAME_WITH_MAJOR)'
>>          SLIB_INSTALL_LINKS=
>>          SLIB_INSTALL_EXTRA_SHLIB='$(SLIBNAME:$(SLIBSUF)=.lib)'
>>          SLIB_INSTALL_EXTRA_LIB='lib$(SLIBNAME:$(SLIBSUF)=.dll.a) $(SLIBNAME_WITH_MAJOR:$(SLIBSUF)=.def)'
>> -        SHFLAGS='-shared -Wl,--output-def,$$(@:$(SLIBSUF)=.orig.def) -Wl,--out-implib,$(SUBDIR)lib$(SLIBNAME:$(SLIBSUF)=.dll.a) -Wl,--enable-runtime-pseudo-reloc -Wl,--enable-auto-image-base'
>> +        SLIB_CREATE_DEF_CMD='ARCH="$(ARCH)" AR="$(AR_CMD)" NM="$(NM_CMD)" $(SRC_PATH)/compat/windows/makedef $(SUBDIR)lib$(NAME).ver $(OBJS) > $$(@:$(SLIBSUF)=.def)'
>> +        SHFLAGS='-shared -Wl,--out-implib,$(SUBDIR)lib$(SLIBNAME:$(SLIBSUF)=.dll.a) -Wl,--enable-auto-image-base $$(@:$(SLIBSUF)=.def)'
>>          enabled x86_64 && objformat="win64" || objformat="win32"
>>          dlltool="${cross_prefix}dlltool"
>>          ranlib=:
>> @@ -5438,6 +5443,8 @@ DEPX86ASMFLAGS=\$(X86ASMFLAGS)
>>  AR=$ar
>>  ARFLAGS=$arflags
>>  AR_O=$ar_o
>> +AR_CMD=$ar
>> +NM_CMD=$nm
>
> You need these extra indirections over the AR and NM variables in the
> Makefile because ... ?

In quiet builds (the default), AR gets prepened with @printf stuff, which 
doesn't work when this is passed onto a shellscript that it supposed to 
execute it. And NM isn't exported into the makefiles at all yet (it's only 
used during configure so far) - I opted to add _CMD for consistency since 
it's supposed to be the raw command just like for AR_CMD, not something 
with potential extra makefile stuff in it.

// Martin

Patch

diff --git a/configure b/configure
index 3e5784f..6f7af32 100755
--- a/configure
+++ b/configure
@@ -4032,6 +4032,10 @@  case $target_os in
         elif enabled arm; then
             LIBTARGET=arm-wince
         fi
+        if enabled shared; then
+            # Cannot build both shared and static libs when using dllexport.
+            disable static
+        fi
         check_ldflags -Wl,--nxcompat
         check_ldflags -Wl,--dynamicbase
         shlibdir_default="$bindir_default"
@@ -4039,12 +4043,13 @@  case $target_os in
         SLIBSUF=".dll"
         SLIBNAME_WITH_VERSION='$(SLIBPREF)$(NAME)-$(LIBVERSION)$(SLIBSUF)'
         SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(NAME)-$(LIBMAJOR)$(SLIBSUF)'
-        SLIB_EXTRA_CMD=-'sed -e "s/ @[^ ]*//" $$(@:$(SLIBSUF)=.orig.def) > $$(@:$(SLIBSUF)=.def); $(DLLTOOL) -m $(LIBTARGET) -d $$(@:$(SLIBSUF)=.def) -l $(SUBDIR)$(SLIBNAME:$(SLIBSUF)=.lib) -D $(SLIBNAME_WITH_MAJOR)'
+        SLIB_EXTRA_CMD=-'$(DLLTOOL) -m $(LIBTARGET) -d $$(@:$(SLIBSUF)=.def) -l $(SUBDIR)$(SLIBNAME:$(SLIBSUF)=.lib) -D $(SLIBNAME_WITH_MAJOR)'
         SLIB_INSTALL_NAME='$(SLIBNAME_WITH_MAJOR)'
         SLIB_INSTALL_LINKS=
         SLIB_INSTALL_EXTRA_SHLIB='$(SLIBNAME:$(SLIBSUF)=.lib)'
         SLIB_INSTALL_EXTRA_LIB='lib$(SLIBNAME:$(SLIBSUF)=.dll.a) $(SLIBNAME_WITH_MAJOR:$(SLIBSUF)=.def)'
-        SHFLAGS='-shared -Wl,--output-def,$$(@:$(SLIBSUF)=.orig.def) -Wl,--out-implib,$(SUBDIR)lib$(SLIBNAME:$(SLIBSUF)=.dll.a) -Wl,--enable-runtime-pseudo-reloc -Wl,--enable-auto-image-base'
+        SLIB_CREATE_DEF_CMD='ARCH="$(ARCH)" AR="$(AR_CMD)" NM="$(NM_CMD)" $(SRC_PATH)/compat/windows/makedef $(SUBDIR)lib$(NAME).ver $(OBJS) > $$(@:$(SLIBSUF)=.def)'
+        SHFLAGS='-shared -Wl,--out-implib,$(SUBDIR)lib$(SLIBNAME:$(SLIBSUF)=.dll.a) -Wl,--enable-auto-image-base $$(@:$(SLIBSUF)=.def)'
         enabled x86_64 && objformat="win64" || objformat="win32"
         dlltool="${cross_prefix}dlltool"
         ranlib=:
@@ -5438,6 +5443,8 @@  DEPX86ASMFLAGS=\$(X86ASMFLAGS)
 AR=$ar
 ARFLAGS=$arflags
 AR_O=$ar_o
+AR_CMD=$ar
+NM_CMD=$nm
 RANLIB=$ranlib
 STRIP=$strip
 LN_S=$ln_s
diff --git a/libavcodec/internal.h b/libavcodec/internal.h
index 0efe34f..da1b2fa 100644
--- a/libavcodec/internal.h
+++ b/libavcodec/internal.h
@@ -285,7 +285,7 @@  int ff_decode_frame_props(AVCodecContext *avctx, AVFrame *frame);
  */
 AVCPBProperties *ff_add_cpb_side_data(AVCodecContext *avctx);
 
-#if defined(_MSC_VER) && CONFIG_SHARED
+#if defined(_WIN32) && CONFIG_SHARED
 #ifdef BUILDING_avcodec
 #    define av_export_avcodec __declspec(dllexport)
 #else