Skip to content

Commit

Permalink
build: use objdump instead of otool
Browse files Browse the repository at this point in the history
See bitcoin/bitcoin#7f5ac4520d1553170b1053a9ffcd58179386a6d2.
  • Loading branch information
div72 committed Sep 23, 2024
1 parent b675c87 commit 481852f
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
28 changes: 14 additions & 14 deletions contrib/macdeploy/macdeployqtplus
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand Down Expand Up @@ -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])
Expand Down Expand Up @@ -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:")
Expand Down
2 changes: 2 additions & 0 deletions depends/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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))|' \
Expand Down
4 changes: 2 additions & 2 deletions depends/builders/darwin.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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=
Expand Down
4 changes: 2 additions & 2 deletions depends/builders/default.mk
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
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
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)
Expand Down
17 changes: 17 additions & 0 deletions depends/config.site.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions depends/hosts/default.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))))

0 comments on commit 481852f

Please sign in to comment.