Skip to content

Commit

Permalink
Check output file size in opt script
Browse files Browse the repository at this point in the history
Summary: Clang has bugs where it may fail to compile a bitcode file to a native object file but not set a non zero exit code. To workaround this for the time being, check the size of the produced native object file in the wrapper script.

Reviewed By: rmaz

Differential Revision: D66659925

fbshipit-source-id: 7ea7b8031f0d87055580f182c69e0972ff894052
  • Loading branch information
NuriAmari authored and facebook-github-bot committed Dec 3, 2024
1 parent cea6e81 commit a5dc441
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions prelude/cxx/dist_lto/tools/dist_lto_opt_darwin.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,20 @@
# of this source tree.

"""
Python wrapper around clang intended to optimize and codegen bitcode files
to native object files for distributed thin lto. This script munges compiler
flags to prepare a suitable clang invocation.
Python wrapper around Clang intended to optimize and codegen bitcode files
to native object files for distributed thin lto targeting darwin. This script
exists to work around Clang bugs where Clang will fail silently.
"""

import argparse
import os
import subprocess
import sys

from typing import List

EXIT_SUCCESS, EXIT_FAILURE = 0, 1


def main(argv: List[str]) -> int:
parser = argparse.ArgumentParser()
Expand Down Expand Up @@ -49,12 +52,12 @@ def main(argv: List[str]) -> int:
]
)

# TODO(T187767988) - Check if returning the subprocesses exit code is sufficient. Server LLVM created such a wrapper
# script in the first place because of a bug in Clang where it fails but does not set a non-zero exit code (T116695431). Fbcode's
# version of this script measure the size of the output file to determine success. The task is closed, but if the bug
# still persists, we may need to do the same.
result = subprocess.run(clang_opt_flags)
return result.returncode
subprocess.check_call(clang_opt_flags)
# Work around Clang bug where it fails silently: T187767815
if os.stat(args.out).st_size == 0:
print("error: opt produced empty file")
return EXIT_FAILURE
return EXIT_SUCCESS


if __name__ == "__main__":
Expand Down

0 comments on commit a5dc441

Please sign in to comment.