Skip to content

Commit 4d3f1d0

Browse files
committed
Merge bitcoin#29739: build: swap cctools otool for llvm-objdump
7f5ac45 build: swap otool for (llvm-)objdump (fanquake) Pull request description: This tool is used in GUI packaging on macOS, and also somewhat of a blocker for bitcoin#21778. The main issue is that some distros don't really ship this tool in a standard ways, i.e Ubuntu only ships `llvm-otool` with a version suffix, i.e `llvm-otool-17`, which makes it hard to find and use. Rather than trying to deal with that mess, switch to using the equivalent LLVM tool (objdump), which is a drop-in replacement. ACKs for top commit: TheCharlatan: ACK 7f5ac45 theuni: ACK 7f5ac45. Tested `make deploy` on native macOS. Looks good. hebasto: ACK 7f5ac45. Tree-SHA512: ac978043f14fb448010542a4a7ce8c6c74b4cbd90f83b4cb4d0bff55974010f10a70b5354f65b239a8bd961d7a3aca22ca165b42954ca87879b9e0524db5f879
2 parents 2cedb42 + 7f5ac45 commit 4d3f1d0

File tree

10 files changed

+31
-25
lines changed

10 files changed

+31
-25
lines changed

Makefile.am

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ $(OSX_ZIP): deploydir
126126
cd $(APP_DIST_DIR) && find . | sort | $(ZIP) -X@ $@
127127

128128
$(APP_DIST_DIR)/$(OSX_APP)/Contents/MacOS/Bitcoin-Qt: $(OSX_APP_BUILT) $(OSX_PACKAGING)
129-
OTOOL=$(OTOOL) $(PYTHON) $(OSX_DEPLOY_SCRIPT) $(OSX_APP) $(OSX_VOLNAME) -translations-dir=$(QT_TRANSLATION_DIR)
129+
OBJDUMP=$(OBJDUMP) $(PYTHON) $(OSX_DEPLOY_SCRIPT) $(OSX_APP) $(OSX_VOLNAME) -translations-dir=$(QT_TRANSLATION_DIR)
130130

131131
deploydir: $(APP_DIST_DIR)/$(OSX_APP)/Contents/MacOS/Bitcoin-Qt
132132
endif !BUILD_DARWIN

configure.ac

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ AC_PATH_PROG([GIT], [git])
125125
AC_PATH_PROG([CCACHE], [ccache])
126126
AC_PATH_PROG([XGETTEXT], [xgettext])
127127
AC_PATH_PROG([HEXDUMP], [hexdump])
128+
AC_PATH_TOOL([OBJDUMP], [objdump])
128129
AC_PATH_TOOL([OBJCOPY], [objcopy])
129130
AC_PATH_PROG([DOXYGEN], [doxygen])
130131
AM_CONDITIONAL([HAVE_DOXYGEN], [test -n "$DOXYGEN"])
@@ -760,7 +761,6 @@ case $host in
760761
;;
761762
*)
762763
AC_PATH_TOOL([DSYMUTIL], [dsymutil], [dsymutil])
763-
AC_PATH_TOOL([OTOOL], [otool], [otool])
764764
AC_PATH_PROG([ZIP], [zip], [zip])
765765

766766
dnl libtool will try to strip the static lib, which is a problem for

contrib/macdeploy/macdeployqtplus

+14-14
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class FrameworkInfo(object):
7777
bundleBinaryDirectory = "Contents/MacOS"
7878

7979
@classmethod
80-
def fromOtoolLibraryLine(cls, line: str) -> Optional['FrameworkInfo']:
80+
def fromLibraryLine(cls, line: str) -> Optional['FrameworkInfo']:
8181
# Note: line must be trimmed
8282
if line == "":
8383
return None
@@ -88,7 +88,7 @@ class FrameworkInfo(object):
8888

8989
m = cls.reOLine.match(line)
9090
if m is None:
91-
raise RuntimeError(f"otool line could not be parsed: {line}")
91+
raise RuntimeError(f"Line could not be parsed: {line}")
9292

9393
path = m.group(1)
9494

@@ -120,7 +120,7 @@ class FrameworkInfo(object):
120120
break
121121
i += 1
122122
if i == len(parts):
123-
raise RuntimeError(f"Could not find .framework or .dylib in otool line: {line}")
123+
raise RuntimeError(f"Could not find .framework or .dylib in line: {line}")
124124

125125
info.frameworkName = parts[i]
126126
info.frameworkDirectory = "/".join(parts[:i])
@@ -182,24 +182,24 @@ class DeploymentInfo(object):
182182
return False
183183

184184
def getFrameworks(binaryPath: str, verbose: int) -> list[FrameworkInfo]:
185+
objdump = os.getenv("OBJDUMP", "objdump")
185186
if verbose:
186-
print(f"Inspecting with otool: {binaryPath}")
187-
otoolbin=os.getenv("OTOOL", "otool")
188-
otool = run([otoolbin, "-L", binaryPath], stdout=PIPE, stderr=PIPE, text=True)
189-
if otool.returncode != 0:
190-
sys.stderr.write(otool.stderr)
187+
print(f"Inspecting with {objdump}: {binaryPath}")
188+
output = run([objdump, "--macho", "--dylibs-used", binaryPath], stdout=PIPE, stderr=PIPE, text=True)
189+
if output.returncode != 0:
190+
sys.stderr.write(output.stderr)
191191
sys.stderr.flush()
192-
raise RuntimeError(f"otool failed with return code {otool.returncode}")
192+
raise RuntimeError(f"{objdump} failed with return code {output.returncode}")
193193

194-
otoolLines = otool.stdout.split("\n")
195-
otoolLines.pop(0) # First line is the inspected binary
194+
lines = output.stdout.split("\n")
195+
lines.pop(0) # First line is the inspected binary
196196
if ".framework" in binaryPath or binaryPath.endswith(".dylib"):
197-
otoolLines.pop(0) # Frameworks and dylibs list themselves as a dependency.
197+
lines.pop(0) # Frameworks and dylibs list themselves as a dependency.
198198

199199
libraries = []
200-
for line in otoolLines:
200+
for line in lines:
201201
line = line.replace("@loader_path", os.path.dirname(binaryPath))
202-
info = FrameworkInfo.fromOtoolLibraryLine(line.strip())
202+
info = FrameworkInfo.fromLibraryLine(line.strip())
203203
if info is not None:
204204
if verbose:
205205
print("Found framework:")

depends/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ $(host_prefix)/share/config.site : config.site.in $(host_prefix)/.stamp_$(final_
233233
-e 's|@RANLIB@|$(host_RANLIB)|' \
234234
-e 's|@NM@|$(host_NM)|' \
235235
-e 's|@STRIP@|$(host_STRIP)|' \
236-
-e 's|@OTOOL@|$(host_OTOOL)|' \
236+
-e 's|@OBJDUMP@|$(host_OBJDUMP)|' \
237237
-e 's|@DSYMUTIL@|$(host_DSYMUTIL)|' \
238238
-e 's|@build_os@|$(build_os)|' \
239239
-e 's|@host_os@|$(host_os)|' \

depends/builders/darwin.mk

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ build_darwin_CXX:=$(shell xcrun -f clang++) -isysroot$(shell xcrun --show-sdk-pa
33
build_darwin_AR:=$(shell xcrun -f ar)
44
build_darwin_RANLIB:=$(shell xcrun -f ranlib)
55
build_darwin_STRIP:=$(shell xcrun -f strip)
6-
build_darwin_OTOOL:=$(shell xcrun -f otool)
6+
build_darwin_OBJDUMP:=$(shell xcrun -f objdump)
77
build_darwin_NM:=$(shell xcrun -f nm)
88
build_darwin_DSYMUTIL:=$(shell xcrun -f dsymutil)
99
build_darwin_SHA256SUM=shasum -a 256
@@ -15,7 +15,7 @@ darwin_CXX:=$(shell xcrun -f clang++) -stdlib=libc++ -isysroot$(shell xcrun --sh
1515
darwin_AR:=$(shell xcrun -f ar)
1616
darwin_RANLIB:=$(shell xcrun -f ranlib)
1717
darwin_STRIP:=$(shell xcrun -f strip)
18-
darwin_OTOOL:=$(shell xcrun -f otool)
18+
darwin_OBJDUMP:=$(shell xcrun -f objdump)
1919
darwin_NM:=$(shell xcrun -f nm)
2020
darwin_DSYMUTIL:=$(shell xcrun -f dsymutil)
2121
darwin_native_binutils=

depends/builders/default.mk

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
default_build_CC = gcc
22
default_build_CXX = g++
33
default_build_AR = ar
4+
default_build_OBJDUMP = objdump
45
default_build_TAR = tar
56
default_build_RANLIB = ranlib
67
default_build_STRIP = strip
@@ -12,7 +13,7 @@ build_$(build_os)_$1 ?= $$(default_build_$1)
1213
build_$(build_arch)_$(build_os)_$1 ?= $$(build_$(build_os)_$1)
1314
build_$1=$$(build_$(build_arch)_$(build_os)_$1)
1415
endef
15-
$(foreach var,CC CXX AR TAR RANLIB NM STRIP SHA256SUM DOWNLOAD OTOOL DSYMUTIL TOUCH,$(eval $(call add_build_tool_func,$(var))))
16+
$(foreach var,CC CXX AR TAR RANLIB NM STRIP SHA256SUM DOWNLOAD OBJDUMP DSYMUTIL TOUCH,$(eval $(call add_build_tool_func,$(var))))
1617
define add_build_flags_func
1718
build_$(build_arch)_$(build_os)_$1 += $(build_$(build_os)_$1)
1819
build_$1=$$(build_$(build_arch)_$(build_os)_$1)

depends/config.site.in

+3-3
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,9 @@ if test -n "@STRIP@"; then
118118
fi
119119

120120
if test "@host_os@" = darwin; then
121-
if test -n "@OTOOL@"; then
122-
OTOOL="@OTOOL@"
123-
ac_cv_path_OTOOL="${OTOOL}"
121+
if test -n "@OBJDUMP@"; then
122+
OBJDUMP="@OBJDUMP@"
123+
ac_cv_path_OBJDUMP="${OBJDUMP}"
124124
fi
125125

126126
if test -n "@DSYMUTIL@"; then

depends/hosts/darwin.mk

+5-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ clang_prog=$(build_prefix)/bin/clang
1919
clangxx_prog=$(clang_prog)++
2020
llvm_config_prog=$(build_prefix)/bin/llvm-config
2121

22+
darwin_OBJDUMP=$(build_prefix)/bin/$(host)-objdump
23+
2224
else
2325
# FORCE_USE_SYSTEM_CLANG is non-empty, so we use the clang from the user's
2426
# system
@@ -37,9 +39,11 @@ clangxx_prog=$(shell $(SHELL) $(.SHELLFLAGS) "command -v clang++")
3739
llvm_config_prog=$(shell $(SHELL) $(.SHELLFLAGS) "command -v llvm-config")
3840

3941
llvm_lib_dir=$(shell $(llvm_config_prog) --libdir)
42+
43+
darwin_OBJDUMP=$(shell $(SHELL) $(.SHELLFLAGS) "command -v llvm-objdump")
4044
endif
4145

42-
cctools_TOOLS=AR RANLIB STRIP NM OTOOL DSYMUTIL
46+
cctools_TOOLS=AR RANLIB STRIP NM DSYMUTIL
4347

4448
# Make-only lowercase function
4549
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))))))))))))))))))))))))))

depends/hosts/default.mk

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,5 @@ host_$1 = $$($(host_arch)_$(host_os)_$1)
3838
host_$(release_type)_$1 = $$($(host_arch)_$(host_os)_$(release_type)_$1)
3939
endef
4040

41-
$(foreach tool,CC CXX AR RANLIB STRIP NM OBJCOPY OTOOL DSYMUTIL,$(eval $(call add_host_tool_func,$(tool))))
41+
$(foreach tool,CC CXX AR RANLIB STRIP NM OBJCOPY OBJDUMP DSYMUTIL,$(eval $(call add_host_tool_func,$(tool))))
4242
$(foreach flags,CFLAGS CXXFLAGS CPPFLAGS LDFLAGS, $(eval $(call add_host_flags_func,$(flags))))

depends/packages/native_llvm.mk

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ define $(package)_stage_cmds
1818
cp -P bin/clang++ $($(package)_staging_prefix_dir)/bin/ && \
1919
cp bin/dsymutil $($(package)_staging_prefix_dir)/bin/$(host)-dsymutil && \
2020
cp bin/llvm-config $($(package)_staging_prefix_dir)/bin/ && \
21+
cp bin/llvm-objdump $($(package)_staging_prefix_dir)/bin/$(host)-objdump && \
2122
cp include/llvm-c/ExternC.h $($(package)_staging_prefix_dir)/include/llvm-c && \
2223
cp include/llvm-c/lto.h $($(package)_staging_prefix_dir)/include/llvm-c && \
2324
cp lib/libLTO.so $($(package)_staging_prefix_dir)/lib/ && \

0 commit comments

Comments
 (0)