From: Antoni Date: Thu, 16 Jan 2025 14:50:40 +0000 (+0100) Subject: upgrade-apply: Make binary fully static X-Git-Tag: accepted/tizen/unified/20250221.111441~8 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8f55b8ed2d320af7384f6f5cb4acb1431f2862ca;p=platform%2Fcore%2Fsystem%2Fupgrade.git upgrade-apply: Make binary fully static This change ensures that `upgrade-apply` binary provided in a delta will run on a system with an older GLib version. Building with this change produces following warnings: [ 12s] /usr/lib64/gcc/aarch64-tizen-linux-gnu/14.2.0/../../../../aarch64-tizen-linux-gnu/bin/ld: /lib/../lib64/libtar.a(encode.o): in function `th_set_group': [ 12s] (.text.th_set_group+0x18): warning: Using 'getgrgid' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking [ 12s] /usr/lib64/gcc/aarch64-tizen-linux-gnu/14.2.0/../../../../aarch64-tizen-linux-gnu/bin/ld: /lib/../lib64/libtar.a(decode.o): in function `th_get_gid': [ 12s] (.text.th_get_gid+0x58): warning: Using 'getgrnam_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking [ 12s] /usr/lib64/gcc/aarch64-tizen-linux-gnu/14.2.0/../../../../aarch64-tizen-linux-gnu/bin/ld: /lib/../lib64/libtar.a(decode.o): in function `th_get_uid': [ 12s] (.text.th_get_uid+0x58): warning: Using 'getpwnam_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking [ 12s] /usr/lib64/gcc/aarch64-tizen-linux-gnu/14.2.0/../../../../aarch64-tizen-linux-gnu/bin/ld: /lib/../lib64/libtar.a(encode.o): in function `th_set_user': [ 12s] (.text.th_set_user+0x18): warning: Using 'getpwuid' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking I have verified that this binary does not call these functions, nor does it access libc dynamically at runtime. Change-Id: Ib9d8834af38f57acfb7f3260bb8142197b35f819 --- diff --git a/packaging/upgrade.spec b/packaging/upgrade.spec index 4c1ee7d..d596887 100644 --- a/packaging/upgrade.spec +++ b/packaging/upgrade.spec @@ -19,6 +19,8 @@ Buildrequires: pkgconfig(glib-2.0) BuildRequires: pkgconfig(hal-api-device) BuildRequires: libtar-devel BuildRequires: gtest-devel +BuildRequires: glibc-devel-static +BuildRequires: zlib-devel-static Requires: upgrade-engine = %{version}-%{release} Requires: parse-dynparts = %{version}-%{release} diff --git a/src/upgrade-apply/CMakeLists.txt b/src/upgrade-apply/CMakeLists.txt index d42afa8..b01d6b0 100644 --- a/src/upgrade-apply/CMakeLists.txt +++ b/src/upgrade-apply/CMakeLists.txt @@ -1,7 +1,6 @@ find_package(PkgConfig) -pkg_check_modules(DEPS REQUIRED IMPORTED_TARGET zlib) -ADD_DEFINITIONS("-D_FILE_OFFSET_BITS=64") +add_definitions("-D_FILE_OFFSET_BITS=64") set( upgrade-apply_SRCS @@ -10,24 +9,21 @@ set( patch/brotli.c sha1/sha1.c ) + add_executable(upgrade-apply ${upgrade-apply_SRCS}) -target_link_libraries(upgrade-apply PRIVATE PkgConfig::DEPS) -# Unfortunately, libtar is neither CMake- nor pkgconfig-aware. -# Even more unfortunately, pkgconfig detection of static libraries is broken for all version of CMake before 3.24, -# and as of writing 3.24 is not even released yet (see https://gitlab.kitware.com/cmake/cmake/-/merge_requests/7070). -# This would require a bit of hacking (but also libc.a) if we wanted full static linking, -# but here we need something even different: static linking for all but libc. -# This requires especially brutal hacks. Maybe we should use Meson next time? ;) -# In the meantime, TODO: make this better. -# Also, note that zlib has been used in the normal way (i.e. with dynamic linking). -# That's because the current setup does have libz.so in the execution environment. -# Though in the future, it might be good to make it consistent (TODO). if(DEFINE_HOST_BUILD) -set(ADD_LIBS libbrotlidec.a libbrotlicommon.a) + target_link_libraries(upgrade-apply PRIVATE libtar.a libz.a libbrotlidec.a libbrotlicommon.a) else() -set(ADD_LIBS libbrotlidec-static.a libbrotlicommon-static.a) + # Without this cmake inserts `-Bdynamic` at the end of link command, and the binary isn't fully static + set_target_properties(upgrade-apply PROPERTIES + LINK_SEARCH_START_STATIC ON + LINK_SEARCH_END_STATIC ON + ) + + target_link_options(upgrade-apply PRIVATE "-static") + + target_link_libraries(upgrade-apply PRIVATE libtar.a libz.a libbrotlidec-static.a libbrotlicommon-static.a) endif() -target_link_libraries(upgrade-apply PRIVATE libtar.a ${ADD_LIBS}) -install(TARGETS upgrade-apply) +install(TARGETS upgrade-apply) \ No newline at end of file