From 481852fc90a7da0a0c67336b1aeb98fa5720f9c7 Mon Sep 17 00:00:00 2001 From: div72 Date: Sat, 7 Sep 2024 18:47:49 +0300 Subject: [PATCH] build: use objdump instead of otool See bitcoin/bitcoin#7f5ac4520d1553170b1053a9ffcd58179386a6d2. --- Makefile.am | 2 +- configure.ac | 2 +- contrib/macdeploy/macdeployqtplus | 28 ++++++++++++++-------------- depends/Makefile | 2 ++ depends/builders/darwin.mk | 4 ++-- depends/builders/default.mk | 4 ++-- depends/config.site.in | 17 +++++++++++++++++ depends/hosts/default.mk | 3 +-- 8 files changed, 40 insertions(+), 22 deletions(-) diff --git a/Makefile.am b/Makefile.am index c438625fb8..44166bd3b5 100644 --- a/Makefile.am +++ b/Makefile.am @@ -150,7 +150,7 @@ $(APP_DIST_DIR)/.background/$(OSX_BACKGROUND_IMAGE): $(OSX_BACKGROUND_IMAGE_DPIF $(TIFFCP) -c none $(OSX_BACKGROUND_IMAGE_DPIFILES) $@ $(APP_DIST_DIR)/$(OSX_APP)/Contents/MacOS/gridcoinresearch: $(OSX_APP_BUILT) $(OSX_PACKAGING) - INSTALLNAMETOOL=$(INSTALLNAMETOOL) OTOOL=$(OTOOL) STRIP=$(STRIP) $(PYTHON) $(OSX_DEPLOY_SCRIPT) $(OSX_APP) $(OSX_VOLNAME) -translations-dir=$(QT_TRANSLATION_DIR) -verbose 2 + OBJDUMP=$(OBJDUMP) STRIP=$(STRIP) $(PYTHON) $(OSX_DEPLOY_SCRIPT) $(OSX_APP) $(OSX_VOLNAME) -translations-dir=$(QT_TRANSLATION_DIR) -verbose 2 deploydir: $(APP_DIST_EXTRAS) endif diff --git a/configure.ac b/configure.ac index 8ba13ccb59..e26a505664 100755 --- a/configure.ac +++ b/configure.ac @@ -90,6 +90,7 @@ AC_PATH_PROG([GIT], [git]) AC_PATH_PROG(CCACHE,ccache) AC_PATH_PROG(XGETTEXT,xgettext) AC_PATH_PROG(HEXDUMP,hexdump) +AC_PATH_TOOL([OBJDUMP], [objdump]) AC_PATH_TOOL(READELF, readelf) AC_PATH_TOOL(CPPFILT, c++filt) AC_PATH_TOOL(OBJCOPY, objcopy) @@ -559,7 +560,6 @@ case $host in *) AC_PATH_TOOL([DSYMUTIL], [dsymutil], dsymutil) AC_PATH_TOOL([INSTALLNAMETOOL], [install_name_tool], install_name_tool) - AC_PATH_TOOL([OTOOL], [otool], otool) AC_PATH_PROGS([XORRISOFS], [xorrisofs], xorrisofs) AC_PATH_PROGS([DMG], [dmg], dmg) AC_PATH_PROGS([RSVG_CONVERT], [rsvg-convert rsvg],rsvg-convert) diff --git a/contrib/macdeploy/macdeployqtplus b/contrib/macdeploy/macdeployqtplus index 1b357e691b..16c1fe6677 100755 --- a/contrib/macdeploy/macdeployqtplus +++ b/contrib/macdeploy/macdeployqtplus @@ -79,7 +79,7 @@ class FrameworkInfo(object): bundleBinaryDirectory = "Contents/MacOS" @classmethod - def fromOtoolLibraryLine(cls, line: str) -> Optional['FrameworkInfo']: + def fromLibraryLine(cls, line: str) -> Optional['FrameworkInfo']: # Note: line must be trimmed if line == "": return None @@ -90,7 +90,7 @@ class FrameworkInfo(object): m = cls.reOLine.match(line) if m is None: - raise RuntimeError(f"otool line could not be parsed: {line}") + raise RuntimeError(f"Line could not be parsed: {line}") path = m.group(1) @@ -122,7 +122,7 @@ class FrameworkInfo(object): break i += 1 if i == len(parts): - raise RuntimeError(f"Could not find .framework or .dylib in otool line: {line}") + raise RuntimeError(f"Could not find .framework or .dylib in line: {line}") info.frameworkName = parts[i] info.frameworkDirectory = "/".join(parts[:i]) @@ -184,24 +184,24 @@ class DeploymentInfo(object): return False def getFrameworks(binaryPath: str, verbose: int) -> List[FrameworkInfo]: + objdump = os.getenv("OBJDUMP", "objdump") if verbose: - print(f"Inspecting with otool: {binaryPath}") - otoolbin=os.getenv("OTOOL", "otool") - otool = run([otoolbin, "-L", binaryPath], stdout=PIPE, stderr=PIPE, universal_newlines=True) - if otool.returncode != 0: - sys.stderr.write(otool.stderr) + print(f"Inspecting with {objdump}: {binaryPath}") + output = run([objdump, "--macho", "--dylibs-used", binaryPath], stdout=PIPE, stderr=PIPE, text=True) + if output.returncode != 0: + sys.stderr.write(output.stderr) sys.stderr.flush() - raise RuntimeError(f"otool failed with return code {otool.returncode}") + raise RuntimeError(f"{objdump} failed with return code {output.returncode}") - otoolLines = otool.stdout.split("\n") - otoolLines.pop(0) # First line is the inspected binary + lines = output.stdout.split("\n") + lines.pop(0) # First line is the inspected binary if ".framework" in binaryPath or binaryPath.endswith(".dylib"): - otoolLines.pop(0) # Frameworks and dylibs list themselves as a dependency. + lines.pop(0) # Frameworks and dylibs list themselves as a dependency. libraries = [] - for line in otoolLines: + for line in lines: line = line.replace("@loader_path", os.path.dirname(binaryPath)) - info = FrameworkInfo.fromOtoolLibraryLine(line.strip()) + info = FrameworkInfo.fromLibraryLine(line.strip()) if info is not None: if verbose: print("Found framework:") diff --git a/depends/Makefile b/depends/Makefile index 92235d5c84..9eb7864d90 100644 --- a/depends/Makefile +++ b/depends/Makefile @@ -152,6 +152,8 @@ $(host_prefix)/share/config.site : config.site.in $(host_prefix)/.stamp_$(final_ -e 's|@RANLIB@|$(host_RANLIB)|' \ -e 's|@NM@|$(host_NM)|' \ -e 's|@STRIP@|$(host_STRIP)|' \ + -e 's|@OBJDUMP@|$(host_OBJDUMP)|' \ + -e 's|@DSYMUTIL@|$(host_DSYMUTIL)|' \ -e 's|@build_os@|$(build_os)|' \ -e 's|@host_os@|$(host_os)|' \ -e 's|@CFLAGS@|$(strip $(host_CFLAGS) $(host_$(release_type)_CFLAGS))|' \ diff --git a/depends/builders/darwin.mk b/depends/builders/darwin.mk index 2c3227da65..2a6055da55 100644 --- a/depends/builders/darwin.mk +++ b/depends/builders/darwin.mk @@ -3,7 +3,7 @@ build_darwin_CXX:=$(shell xcrun -f clang++) -isysroot$(shell xcrun --show-sdk-pa build_darwin_AR:=$(shell xcrun -f ar) build_darwin_RANLIB:=$(shell xcrun -f ranlib) build_darwin_STRIP:=$(shell xcrun -f strip) -build_darwin_OTOOL:=$(shell xcrun -f otool) +build_darwin_OBJDUMP:=$(shell xcrun -f objdump) build_darwin_NM:=$(shell xcrun -f nm) build_darwin_INSTALL_NAME_TOOL:=$(shell xcrun -f install_name_tool) build_darwin_SHA256SUM=shasum -a 256 @@ -16,7 +16,7 @@ darwin_AR:=$(shell xcrun -f ar) darwin_RANLIB:=$(shell xcrun -f ranlib) darwin_STRIP:=$(shell xcrun -f strip) darwin_LIBTOOL:=$(shell xcrun -f libtool) -darwin_OTOOL:=$(shell xcrun -f otool) +darwin_OBJDUMP:=$(shell xcrun -f objdump) darwin_NM:=$(shell xcrun -f nm) darwin_INSTALL_NAME_TOOL:=$(shell xcrun -f install_name_tool) darwin_native_toolchain= diff --git a/depends/builders/default.mk b/depends/builders/default.mk index f097db65d6..e29bc663a2 100644 --- a/depends/builders/default.mk +++ b/depends/builders/default.mk @@ -1,10 +1,10 @@ default_build_CC = gcc default_build_CXX = g++ default_build_AR = ar +default_build_OBJDUMP = objdump default_build_RANLIB = ranlib default_build_STRIP = strip default_build_NM = nm -default_build_OTOOL = otool default_build_INSTALL_NAME_TOOL = install_name_tool define add_build_tool_func @@ -12,7 +12,7 @@ build_$(build_os)_$1 ?= $$(default_build_$1) build_$(build_arch)_$(build_os)_$1 ?= $$(build_$(build_os)_$1) build_$1=$$(build_$(build_arch)_$(build_os)_$1) endef -$(foreach var,CC CXX AR RANLIB NM STRIP SHA256SUM DOWNLOAD OTOOL INSTALL_NAME_TOOL,$(eval $(call add_build_tool_func,$(var)))) +$(foreach var,CC CXX AR RANLIB NM STRIP SHA256SUM DOWNLOAD OBJDUMP INSTALL_NAME_TOOL,$(eval $(call add_build_tool_func,$(var)))) define add_build_flags_func build_$(build_arch)_$(build_os)_$1 += $(build_$(build_os)_$1) build_$1=$$(build_$(build_arch)_$(build_os)_$1) diff --git a/depends/config.site.in b/depends/config.site.in index ef05bb1681..ce20c676f8 100644 --- a/depends/config.site.in +++ b/depends/config.site.in @@ -80,6 +80,23 @@ if test -n "@NM@"; then ac_cv_path_ac_pt_NM=${NM} fi +if test -n "@STRIP@"; then + STRIP="@STRIP@" + ac_cv_path_ac_pt_STRIP="${STRIP}" +fi + +if test "@host_os@" = darwin; then + if test -n "@OBJDUMP@"; then + OBJDUMP="@OBJDUMP@" + ac_cv_path_OBJDUMP="${OBJDUMP}" + fi + + if test -n "@DSYMUTIL@"; then + DSYMUTIL="@DSYMUTIL@" + ac_cv_path_DSYMUTIL="${DSYMUTIL}" + fi +fi + if test -n "@debug@"; then enable_reduce_exports=no fi diff --git a/depends/hosts/default.mk b/depends/hosts/default.mk index 258619a9d0..5fe77c1985 100644 --- a/depends/hosts/default.mk +++ b/depends/hosts/default.mk @@ -9,7 +9,6 @@ default_host_RANLIB = $(host_toolchain)ranlib default_host_STRIP = $(host_toolchain)strip default_host_LIBTOOL = $(host_toolchain)libtool default_host_INSTALL_NAME_TOOL = $(host_toolchain)install_name_tool -default_host_OTOOL = $(host_toolchain)otool default_host_NM = $(host_toolchain)nm define add_host_tool_func @@ -35,5 +34,5 @@ host_$1 = $$($(host_arch)_$(host_os)_$1) host_$(release_type)_$1 = $$($(host_arch)_$(host_os)_$(release_type)_$1) endef -$(foreach tool,CC CXX AR RANLIB STRIP NM LIBTOOL OTOOL INSTALL_NAME_TOOL,$(eval $(call add_host_tool_func,$(tool)))) +$(foreach tool,CC CXX AR RANLIB STRIP NM LIBTOOL OBJDUMP INSTALL_NAME_TOOL,$(eval $(call add_host_tool_func,$(tool)))) $(foreach flags,CFLAGS CXXFLAGS CPPFLAGS LDFLAGS, $(eval $(call add_host_flags_func,$(flags))))