Bug 1841567 - Stop running check_binary on host binaries. r=firefox-build-system-reviewers,sergesanspaille

Back when this was added, we weren't using sysroots, and we did end up
with host binaries that couldn't run on the host because libstdc++ came
along the host compiler, and was newer than the system libstdc++. These
concerns are long gone (libstdc++ in the sysroots is older than any
supported linux host build system), so we don't need to run those checks
anymore.

Differential Revision: https://phabricator.services.mozilla.com/D182691
This commit is contained in:
Mike Hommey 2023-07-05 07:50:50 +00:00
parent 5171fa8e4d
commit eada0e7fc8
3 changed files with 30 additions and 59 deletions

View File

@ -447,7 +447,7 @@ ifeq ($(OS_ARCH), Linux)
ifeq (,$(rustflags_sancov)$(MOZ_ASAN)$(MOZ_TSAN)$(MOZ_UBSAN))
ifndef MOZ_LTO_RUST_CROSS
ifneq (,$(filter -Clto,$(cargo_rustc_flags)))
$(call py_action,check_binary,--target --networking $@)
$(call py_action,check_binary,--networking $@)
endif
endif
endif

View File

@ -422,7 +422,7 @@ ifeq (_WINNT,$(GNU_CC)_$(OS_ARCH))
$(LINKER) -OUT:$@ -PDB:$(LINK_PDBFILE) -IMPLIB:$(basename $(@F)).lib $(WIN32_EXE_LDFLAGS) $(LDFLAGS) $(MOZ_PROGRAM_LDFLAGS) $($(notdir $@)_OBJS) $(filter %.res,$^) $(STATIC_LIBS) $(SHARED_LIBS) $(OS_LIBS)
else # !WINNT || GNU_CC
$(call EXPAND_CC_OR_CXX,$@) -o $@ $(COMPUTED_CXX_LDFLAGS) $(PGO_CFLAGS) $($(notdir $@)_OBJS) $(filter %.res,$^) $(WIN32_EXE_LDFLAGS) $(LDFLAGS) $(STATIC_LIBS) $(MOZ_PROGRAM_LDFLAGS) $(SHARED_LIBS) $(OS_LIBS)
$(call py_action,check_binary,--target $@)
$(call py_action,check_binary,$@)
endif # WINNT && !GNU_CC
ifdef ENABLE_STRIP
@ -443,9 +443,6 @@ else
$(HOST_CC) -o $@ $(HOST_C_LDFLAGS) $(HOST_LDFLAGS) $($(notdir $@)_OBJS) $(HOST_LIBS) $(HOST_EXTRA_LIBS)
endif # HOST_CPP_PROG_LINK
endif
ifndef CROSS_COMPILE
$(call py_action,check_binary,--host $@)
endif
#
# This is an attempt to support generation of multiple binaries
@ -466,7 +463,7 @@ ifeq (_WINNT,$(GNU_CC)_$(OS_ARCH))
$(LINKER) -out:$@ -pdb:$(LINK_PDBFILE) $($@_OBJS) $(filter %.res,$^) $(WIN32_EXE_LDFLAGS) $(LDFLAGS) $(MOZ_PROGRAM_LDFLAGS) $(STATIC_LIBS) $(SHARED_LIBS) $(OS_LIBS)
else
$(call EXPAND_CC_OR_CXX,$@) $(COMPUTED_CXX_LDFLAGS) $(PGO_CFLAGS) -o $@ $($@_OBJS) $(filter %.res,$^) $(WIN32_EXE_LDFLAGS) $(LDFLAGS) $(STATIC_LIBS) $(MOZ_PROGRAM_LDFLAGS) $(SHARED_LIBS) $(OS_LIBS)
$(call py_action,check_binary,--target $@)
$(call py_action,check_binary,$@)
endif # WINNT && !GNU_CC
ifdef ENABLE_STRIP
@ -487,9 +484,6 @@ else
$(HOST_CC) $(HOST_OUTOPTION)$@ $(HOST_C_LDFLAGS) $(HOST_LDFLAGS) $($(notdir $@)_OBJS) $(HOST_LIBS) $(HOST_EXTRA_LIBS)
endif
endif
ifndef CROSS_COMPILE
$(call py_action,check_binary,--host $@)
endif
$(LIBRARY): $(OBJS) $(STATIC_LIBS) $(EXTRA_DEPS) $(GLOBAL_DEPS)
$(REPORT_BUILD)
@ -530,7 +524,7 @@ $(SHARED_LIBRARY): $(OBJS) $(call resfile,$(SHARED_LIBRARY)) $(STATIC_LIBS) $(EX
$(REPORT_BUILD)
$(RM) $@
$(MKSHLIB) $($@_OBJS) $(filter %.res,$^) $(LDFLAGS) $(STATIC_LIBS) $(SHARED_LIBS) $(EXTRA_DSO_LDOPTS) $(MOZ_GLUE_LDFLAGS) $(OS_LIBS)
$(call py_action,check_binary,--target $@)
$(call py_action,check_binary,$@)
ifeq (_WINNT,$(GNU_CC)_$(OS_ARCH))
endif # WINNT && !GCC

View File

@ -20,12 +20,8 @@ CXXABI_MAX_VERSION = Version("1.3.7")
GLIBC_MAX_VERSION = Version("2.17")
LIBGCC_MAX_VERSION = Version("4.8")
HOST = {"platform": buildconfig.substs["HOST_OS_ARCH"], "readelf": "readelf"}
TARGET = {
"platform": buildconfig.substs["OS_TARGET"],
"readelf": buildconfig.substs.get("READELF", "readelf"),
}
PLATFORM = buildconfig.substs["OS_TARGET"]
READELF = buildconfig.substs.get("READELF", "readelf")
ADDR_RE = re.compile(r"[0-9a-f]{8,16}")
@ -63,14 +59,14 @@ def at_least_one(iter):
# Iterates the symbol table on ELF binaries.
def iter_elf_symbols(target, binary, all=False):
def iter_elf_symbols(binary, all=False):
ty = get_type(binary)
# Static libraries are ar archives. Assume they are ELF.
if ty == UNKNOWN and open(binary, "rb").read(8) == b"!<arch>\n":
ty = ELF
assert ty == ELF
for line in get_output(
target["readelf"], "--wide", "--syms" if all else "--dyn-syms", binary
READELF, "--wide", "--syms" if all else "--dyn-syms", binary
):
data = line.split()
if not (len(data) >= 8 and data[0].endswith(":") and data[0][:-1].isdigit()):
@ -93,14 +89,14 @@ def iter_elf_symbols(target, binary, all=False):
}
def iter_readelf_dynamic(target, binary):
for line in get_output(target["readelf"], "-d", binary):
def iter_readelf_dynamic(binary):
for line in get_output(READELF, "-d", binary):
data = line.split(None, 2)
if data and len(data) == 3 and data[0].startswith("0x"):
yield data[1].rstrip(")").lstrip("("), data[2]
def check_binary_compat(target, binary):
def check_binary_compat(binary):
if get_type(binary) != ELF:
raise Skip()
checks = (
@ -112,7 +108,7 @@ def check_binary_compat(target, binary):
unwanted = {}
try:
for sym in at_least_one(iter_elf_symbols(target, binary)):
for sym in at_least_one(iter_elf_symbols(binary)):
# Only check versions on undefined symbols
if sym["addr"] != 0:
continue
@ -141,11 +137,11 @@ def check_binary_compat(target, binary):
raise RuntimeError("\n".join(error))
def check_textrel(target, binary):
if target is HOST or get_type(binary) != ELF:
def check_textrel(binary):
if get_type(binary) != ELF:
raise Skip()
try:
for tag, value in at_least_one(iter_readelf_dynamic(target, binary)):
for tag, value in at_least_one(iter_readelf_dynamic(binary)):
if tag == "TEXTREL" or (tag == "FLAGS" and "TEXTREL" in value):
raise RuntimeError(
"We do not want text relocations in libraries and programs"
@ -167,11 +163,11 @@ def is_libxul(binary):
return "xul" in basename
def check_pt_load(target, binary):
if target is HOST or get_type(binary) != ELF or not is_libxul(binary):
def check_pt_load(binary):
if get_type(binary) != ELF or not is_libxul(binary):
raise Skip()
count = 0
for line in get_output(target["readelf"], "-l", binary):
for line in get_output(READELF, "-l", binary):
data = line.split()
if data and data[0] == "LOAD":
count += 1
@ -179,8 +175,8 @@ def check_pt_load(target, binary):
raise RuntimeError("Expected more than one PT_LOAD segment")
def check_mozglue_order(target, binary):
if target is HOST or target["platform"] != "Android":
def check_mozglue_order(binary):
if PLATFORM != "Android":
raise Skip()
# While this is very unlikely (libc being added by the compiler at the end
# of the linker command line), if libmozglue.so ends up after libc.so, all
@ -188,9 +184,7 @@ def check_mozglue_order(target, binary):
# case.
try:
mozglue = libc = None
for n, (tag, value) in enumerate(
at_least_one(iter_readelf_dynamic(target, binary))
):
for n, (tag, value) in enumerate(at_least_one(iter_readelf_dynamic(binary))):
if tag == "NEEDED":
if "[libmozglue.so]" in value:
mozglue = n
@ -204,7 +198,7 @@ def check_mozglue_order(target, binary):
raise RuntimeError("Could not parse readelf output?")
def check_networking(target, binary):
def check_networking(binary):
retcode = 0
networking_functions = set(
[
@ -242,7 +236,7 @@ def check_networking(target, binary):
bad_occurences_names = set()
try:
for sym in at_least_one(iter_elf_symbols(target, binary, all=True)):
for sym in at_least_one(iter_elf_symbols(binary, all=True)):
if sym["addr"] == 0 and sym["name"] in networking_functions:
bad_occurences_names.add(sym["name"])
except Empty:
@ -268,13 +262,13 @@ def check_networking(target, binary):
return retcode
def checks(target, binary):
def checks(binary):
# The clang-plugin is built as target but is really a host binary.
# Cheat and pretend we were passed the right argument.
# Cheat and pretend we weren't called.
if "clang-plugin" in binary:
target = HOST
return 0
checks = []
if buildconfig.substs.get("MOZ_STDCXX_COMPAT") and target["platform"] == "Linux":
if buildconfig.substs.get("MOZ_STDCXX_COMPAT") and PLATFORM == "Linux":
checks.append(check_binary_compat)
# Disabled for local builds because of readelf performance: See bug 1472496
@ -288,7 +282,7 @@ def checks(target, binary):
for c in checks:
try:
name = c.__name__
c(target, binary)
c(binary)
if buildconfig.substs.get("MOZ_AUTOMATION"):
print("TEST-PASS | {} | {}".format(name, basename))
except Skip:
@ -305,12 +299,6 @@ def checks(target, binary):
def main(args):
parser = argparse.ArgumentParser(description="Check built binaries")
parser.add_argument(
"--host", action="store_true", help="Perform checks for a host binary"
)
parser.add_argument(
"--target", action="store_true", help="Perform checks for a target binary"
)
parser.add_argument(
"--networking",
action="store_true",
@ -323,20 +311,9 @@ def main(args):
options = parser.parse_args(args)
if options.host == options.target:
print("Exactly one of --host or --target must be given", file=sys.stderr)
return 1
if options.networking and options.host:
print("--networking is only valid with --target", file=sys.stderr)
return 1
if options.networking:
return check_networking(TARGET, options.binary)
elif options.host:
return checks(HOST, options.binary)
elif options.target:
return checks(TARGET, options.binary)
return check_networking(options.binary)
return checks(options.binary)
if __name__ == "__main__":