Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

llvm: convert bitcode in static archives to object code #112154

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions Formula/llvm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,24 @@ def install

# Install Emacs modes
elisp.install llvmpath.glob("utils/emacs/*.el") + share.glob("clang/*.el")

return if OS.linux? || !pgo_build
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably nice to have a lto_enabled variable that could be used throughout in case this ever changes. Can be a separate style PR however.


# Convert LTO-generated bitcode in our static archives to MachO. Adapted from Fedora:
# https://src.fedoraproject.org/rpms/redhat-rpm-config/blob/rawhide/f/brp-llvm-compile-lto-elf
lib.glob("*.a").each do |static_archive|
mktemp do
system bin/"llvm-ar", "x", static_archive
Pathname.glob("*.o").each do |bc_file|
file_type = Utils.safe_popen_read("file", bc_file)
next unless file_type.match?("LLVM bitcode")

system bin/"clang", "-fno-lto", "-Wno-unused-command-line-argument",
"-x", "ir", bc_file, "-c", "-o", bc_file
system bin/"llvm-ar", "r", static_archive, bc_file
end
end
end
end

def caveats
Expand Down Expand Up @@ -643,6 +661,17 @@ def caveats
assert_equal "int main() { printf(\"Hello world!\"); }\n",
shell_output("#{bin}/clang-format -style=google clangformattest.c")

# Test static analyzer
(testpath/"unreachable.c").write <<~EOS
unsigned int func(unsigned int a) {
unsigned int *z = 0;
if ((a & 1) && ((a & 1) ^1))
return *z; // unreachable
return 0;
}
EOS
system bin/"clang", "--analyze", "-Xanalyzer", "-analyzer-constraints=z3", "unreachable.c"

# This will fail if the clang bindings cannot find `libclang`.
with_env(PYTHONPATH: prefix/Language::Python.site_packages(python3)) do
system python3, "-c", <<~EOS
Expand All @@ -651,6 +680,10 @@ def caveats
EOS
end

# Check that lldb can use Python
lldb_script_interpreter_info = JSON.parse(shell_output("#{bin}/lldb --print-script-interpreter-info"))
assert_equal "python", lldb_script_interpreter_info["language"]

# Ensure LLVM did not regress output of `llvm-config --system-libs` which for a time
# was known to output incorrect linker flags; e.g., `-llibxml2.tbd` instead of `-lxml2`.
# On the other hand, note that a fully qualified path to `dylib` or `tbd` is OK, e.g.,
Expand Down