[vlc-devel] [PATCH] apple: add support for partial linking
Alexandre Janniaux
ajanni at videolabs.io
Tue Feb 2 09:26:25 UTC 2021
Hi,
For Apple developers, this is the equivalent of the XCode setting
«Perform Single-Object Prelink», or as found in the project file
GENERATE_MASTER_OBJECT_FILE=YES.
By the way, I'm a bit out of idea for a clean integration of
the contribs into the plugins. We could extract the linking flag
from the libtool library, and add them in the partial linking call
but it's quite ugly, or probably even more than that, and we still
need to keep the flags for the libraries on the system. What I had
to do to achieve that in an experiment in apple buildscript was
something like this:
filter_ltlibs()
{
local flags=( "$@" )
local output=()
for flag in "${flags[@]}"; do
if [ "$(echo $flag | grep libvlccore.la)" = "" ]; then
if [ "$(echo $flag | grep libcompat.la)" = "" ]; then
if [ "$flag" != "-pthread" ]; then
if [ "$flag" != "-L${VLC_CONTRIB_INSTALL_DIR}/lib" ]; then
echo "$flag"
fi
fi
fi
fi
done
}
# Find all static contribs in build dir
while IFS= read -r -d $'\0' ltlib_plugin; do
ltdeps=( $(grep dependency_libs= "$ltlib_plugin" | head -n1 | cut -d"'" -f 2) ) #TODO: cut at = and remove ' instead ?
ltinheritdeps=( $(grep inherited_linker_flags= "$ltlib_plugin" | head -n1 | cut -d"'" -f 2) )
ltlib=$(grep old_library= "$ltlib_plugin" | cut -d"'" -f 2)
if [ "$(echo $ltlib | rev | cut -d"." -f1)" = "a" ]; then
# Plugin library archive
echo "${VLC_BUILD_DIR}/build/modules/.libs/$ltlib" \
>> "${VLC_STATIC_FILELIST_NAME}"
# Plugin dependencies and framework
echo "$(filter_ltlibs "${ltdeps[@]}" "${ltinheritdeps[@]}")" \
>> "${VLC_STATIC_FILELIST_NAME}"
fi
done < <(find "$VLC_BUILD_DIR/build/modules/" -name '*.la' -print0) \
Regards,
--
Alexandre Janniaux
Videolabs
On Tue, Feb 02, 2021 at 10:05:33AM +0100, Alexandre Janniaux wrote:
> Each plugin built as archive library will have its object partially
> linked before getting ar-chived. The work here is also partial since
> dependencies are not partially-linked into the plugin too. In the
> future, it will help prevent clashing of symbols between plugins and
> reduce bloats in the final library archive on the current iOS static
> build.
>
> Note that this trades optimization window for less object bloating and
> the guarantee that each plugin is only made of one object. Next step is
> to be able to include the contribs and properly localize the symbols
> that are not meant to be exposed for the VLC plugin ABI.
> ---
> extras/package/apple/ar.sh | 12 ++++++++++++
> extras/package/apple/build.sh | 10 +++++++++-
> 2 files changed, 21 insertions(+), 1 deletion(-)
> create mode 100755 extras/package/apple/ar.sh
>
> diff --git a/extras/package/apple/ar.sh b/extras/package/apple/ar.sh
> new file mode 100755
> index 0000000000..dc804305d9
> --- /dev/null
> +++ b/extras/package/apple/ar.sh
> @@ -0,0 +1,12 @@
> +#!/usr/bin/env sh
> +
> +set -eu
> +OPTIONS=$1; shift
> +TARGET=$1; shift
> +
> +if echo "${TARGET}" | grep "_plugin.a\$"; then
> + ${CC} ${CFLAGS} ${LDFLAGS} -r -o ${TARGET}.partial.o $@
> + ${AR} ${OPTIONS} ${TARGET} ${TARGET}.partial.o
> +else
> + ${AR} ${OPTIONS} ${TARGET} $@
> +fi
> diff --git a/extras/package/apple/build.sh b/extras/package/apple/build.sh
> index 1868c8f1f4..ba9728d456 100755
> --- a/extras/package/apple/build.sh
> +++ b/extras/package/apple/build.sh
> @@ -324,7 +324,7 @@ hostenv()
> CXX="${VLC_HOST_CXX}" \
> OBJC="${VLC_HOST_OBJC}" \
> LD="${VLC_HOST_LD}" \
> - AR="${VLC_HOST_AR}" \
> + AR="${VLC_BUILD_DIR}/build/ar.sh" \
> STRIP="${VLC_HOST_STRIP}" \
> RANLIB="${VLC_HOST_RANLIB}" \
> NM="${VLC_HOST_NM}" \
> @@ -674,6 +674,14 @@ fi
> mkdir -p "${VLC_BUILD_DIR}/build"
> cd "${VLC_BUILD_DIR}/build" || abort_err "Failed cd to VLC build dir"
>
> +echo "#!/usr/bin/env sh" > ar.sh
> +echo "export CFLAGS=\"${CFLAGS}\"" >> ar.sh
> +echo "export LDFLAGS=\"${LDFLAGS}\"" >> ar.sh
> +echo "export CC=\"${VLC_HOST_CC}\"" >> ar.sh
> +echo "export AR=\"${VLC_HOST_AR}\"" >> ar.sh
> +echo "${VLC_SCRIPT_DIR}/ar.sh \$@" >> ar.sh
> +chmod +x ar.sh
> +
> # Create VLC install dir if it does not already exist
> mkdir -p "$VLC_INSTALL_DIR"
>
> --
> 2.30.0
>
More information about the vlc-devel
mailing list