From 7f5ac4520d1553170b1053a9ffcd58179386a6d2 Mon Sep 17 00:00:00 2001 From: fanquake Date: Tue, 30 Jan 2024 09:37:37 +0000 Subject: [PATCH] build: swap otool for (llvm-)objdump Similar to libtool, (llvm-)otool only exists with a version suffix on some systems (Ubuntu), which makes it annoying to use/find. Avoid this, by switching to objdump. Which is a drop-in replacement. This is related to #21778, and the switchover to using vanilla LLVM for macOS. --- Makefile.am | 2 +- configure.ac | 2 +- contrib/macdeploy/macdeployqtplus | 28 ++++++++++++++-------------- depends/Makefile | 2 +- depends/builders/darwin.mk | 4 ++-- depends/builders/default.mk | 3 ++- depends/config.site.in | 6 +++--- depends/hosts/darwin.mk | 6 +++++- depends/hosts/default.mk | 2 +- depends/packages/native_llvm.mk | 1 + 10 files changed, 31 insertions(+), 25 deletions(-) diff --git a/Makefile.am b/Makefile.am index e79dc4e21b2..95d6a191cfc 100644 --- a/Makefile.am +++ b/Makefile.am @@ -126,7 +126,7 @@ $(OSX_ZIP): deploydir cd $(APP_DIST_DIR) && find . | sort | $(ZIP) -X@ $@ $(APP_DIST_DIR)/$(OSX_APP)/Contents/MacOS/Bitcoin-Qt: $(OSX_APP_BUILT) $(OSX_PACKAGING) - OTOOL=$(OTOOL) $(PYTHON) $(OSX_DEPLOY_SCRIPT) $(OSX_APP) $(OSX_VOLNAME) -translations-dir=$(QT_TRANSLATION_DIR) + OBJDUMP=$(OBJDUMP) $(PYTHON) $(OSX_DEPLOY_SCRIPT) $(OSX_APP) $(OSX_VOLNAME) -translations-dir=$(QT_TRANSLATION_DIR) deploydir: $(APP_DIST_DIR)/$(OSX_APP)/Contents/MacOS/Bitcoin-Qt endif !BUILD_DARWIN diff --git a/configure.ac b/configure.ac index ee4400f21aa..dfb7b997565 100644 --- a/configure.ac +++ b/configure.ac @@ -125,6 +125,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([OBJCOPY], [objcopy]) AC_PATH_PROG([DOXYGEN], [doxygen]) AM_CONDITIONAL([HAVE_DOXYGEN], [test -n "$DOXYGEN"]) @@ -760,7 +761,6 @@ case $host in ;; *) AC_PATH_TOOL([DSYMUTIL], [dsymutil], [dsymutil]) - AC_PATH_TOOL([OTOOL], [otool], [otool]) AC_PATH_PROG([ZIP], [zip], [zip]) dnl libtool will try to strip the static lib, which is a problem for diff --git a/contrib/macdeploy/macdeployqtplus b/contrib/macdeploy/macdeployqtplus index 4b1d72650d6..eaa7b896be9 100755 --- a/contrib/macdeploy/macdeployqtplus +++ b/contrib/macdeploy/macdeployqtplus @@ -77,7 +77,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 @@ -88,7 +88,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) @@ -120,7 +120,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]) @@ -182,24 +182,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, text=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 005d9696fb5..016c8f64ad5 100644 --- a/depends/Makefile +++ b/depends/Makefile @@ -233,7 +233,7 @@ $(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|@OTOOL@|$(host_OTOOL)|' \ + -e 's|@OBJDUMP@|$(host_OBJDUMP)|' \ -e 's|@DSYMUTIL@|$(host_DSYMUTIL)|' \ -e 's|@build_os@|$(build_os)|' \ -e 's|@host_os@|$(host_os)|' \ diff --git a/depends/builders/darwin.mk b/depends/builders/darwin.mk index 554bfd2c3e0..be04e1d8f3f 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_DSYMUTIL:=$(shell xcrun -f dsymutil) build_darwin_SHA256SUM=shasum -a 256 @@ -15,7 +15,7 @@ darwin_CXX:=$(shell xcrun -f clang++) -stdlib=libc++ -isysroot$(shell xcrun --sh darwin_AR:=$(shell xcrun -f ar) darwin_RANLIB:=$(shell xcrun -f ranlib) darwin_STRIP:=$(shell xcrun -f strip) -darwin_OTOOL:=$(shell xcrun -f otool) +darwin_OBJDUMP:=$(shell xcrun -f objdump) darwin_NM:=$(shell xcrun -f nm) darwin_DSYMUTIL:=$(shell xcrun -f dsymutil) darwin_native_binutils= diff --git a/depends/builders/default.mk b/depends/builders/default.mk index 50869cd8a26..2a1709d98ad 100644 --- a/depends/builders/default.mk +++ b/depends/builders/default.mk @@ -1,6 +1,7 @@ default_build_CC = gcc default_build_CXX = g++ default_build_AR = ar +default_build_OBJDUMP = objdump default_build_TAR = tar default_build_RANLIB = ranlib default_build_STRIP = strip @@ -12,7 +13,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 TAR RANLIB NM STRIP SHA256SUM DOWNLOAD OTOOL DSYMUTIL TOUCH,$(eval $(call add_build_tool_func,$(var)))) +$(foreach var,CC CXX AR TAR RANLIB NM STRIP SHA256SUM DOWNLOAD OBJDUMP DSYMUTIL TOUCH,$(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 81975f02b94..f6bed6a9d4c 100644 --- a/depends/config.site.in +++ b/depends/config.site.in @@ -118,9 +118,9 @@ if test -n "@STRIP@"; then fi if test "@host_os@" = darwin; then - if test -n "@OTOOL@"; then - OTOOL="@OTOOL@" - ac_cv_path_OTOOL="${OTOOL}" + if test -n "@OBJDUMP@"; then + OBJDUMP="@OBJDUMP@" + ac_cv_path_OBJDUMP="${OBJDUMP}" fi if test -n "@DSYMUTIL@"; then diff --git a/depends/hosts/darwin.mk b/depends/hosts/darwin.mk index 639259ace34..2c4ef0644d2 100644 --- a/depends/hosts/darwin.mk +++ b/depends/hosts/darwin.mk @@ -19,6 +19,8 @@ clang_prog=$(build_prefix)/bin/clang clangxx_prog=$(clang_prog)++ llvm_config_prog=$(build_prefix)/bin/llvm-config +darwin_OBJDUMP=$(build_prefix)/bin/$(host)-objdump + else # FORCE_USE_SYSTEM_CLANG is non-empty, so we use the clang from the user's # system @@ -37,9 +39,11 @@ clangxx_prog=$(shell $(SHELL) $(.SHELLFLAGS) "command -v clang++") llvm_config_prog=$(shell $(SHELL) $(.SHELLFLAGS) "command -v llvm-config") llvm_lib_dir=$(shell $(llvm_config_prog) --libdir) + +darwin_OBJDUMP=$(shell $(SHELL) $(.SHELLFLAGS) "command -v llvm-objdump") endif -cctools_TOOLS=AR RANLIB STRIP NM OTOOL DSYMUTIL +cctools_TOOLS=AR RANLIB STRIP NM DSYMUTIL # Make-only lowercase function lc = $(subst A,a,$(subst B,b,$(subst C,c,$(subst D,d,$(subst E,e,$(subst F,f,$(subst G,g,$(subst H,h,$(subst I,i,$(subst J,j,$(subst K,k,$(subst L,l,$(subst M,m,$(subst N,n,$(subst O,o,$(subst P,p,$(subst Q,q,$(subst R,r,$(subst S,s,$(subst T,t,$(subst U,u,$(subst V,v,$(subst W,w,$(subst X,x,$(subst Y,y,$(subst Z,z,$1)))))))))))))))))))))))))) diff --git a/depends/hosts/default.mk b/depends/hosts/default.mk index 6a6cab6cc67..d82c33f29ce 100644 --- a/depends/hosts/default.mk +++ b/depends/hosts/default.mk @@ -38,5 +38,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 OBJCOPY OTOOL DSYMUTIL,$(eval $(call add_host_tool_func,$(tool)))) +$(foreach tool,CC CXX AR RANLIB STRIP NM OBJCOPY OBJDUMP DSYMUTIL,$(eval $(call add_host_tool_func,$(tool)))) $(foreach flags,CFLAGS CXXFLAGS CPPFLAGS LDFLAGS, $(eval $(call add_host_flags_func,$(flags)))) diff --git a/depends/packages/native_llvm.mk b/depends/packages/native_llvm.mk index 09994eb0129..1953c91bf42 100644 --- a/depends/packages/native_llvm.mk +++ b/depends/packages/native_llvm.mk @@ -18,6 +18,7 @@ define $(package)_stage_cmds cp -P bin/clang++ $($(package)_staging_prefix_dir)/bin/ && \ cp bin/dsymutil $($(package)_staging_prefix_dir)/bin/$(host)-dsymutil && \ cp bin/llvm-config $($(package)_staging_prefix_dir)/bin/ && \ + cp bin/llvm-objdump $($(package)_staging_prefix_dir)/bin/$(host)-objdump && \ cp include/llvm-c/ExternC.h $($(package)_staging_prefix_dir)/include/llvm-c && \ cp include/llvm-c/lto.h $($(package)_staging_prefix_dir)/include/llvm-c && \ cp lib/libLTO.so $($(package)_staging_prefix_dir)/lib/ && \