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.
pull/29739/head
fanquake 9 months ago
parent 43a66c55ec
commit 7f5ac4520d
No known key found for this signature in database
GPG Key ID: 2EEB9F5CC09526C1

@ -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

@ -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

@ -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:")

@ -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)|' \

@ -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=

@ -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)

@ -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

@ -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))))))))))))))))))))))))))

@ -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))))

@ -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/ && \

Loading…
Cancel
Save