This patch is part of the work to make LTO and function multi-versioning work correctly.
Currently, -mlong-calls, which is converted to cc1 option -arm-long-calls, is ignored when building with LTO because the option isn't passed to the linker or libLTO. This patch saves the option in the IR as a function attribute to fix this problem.
The corresponding llvm patch is here:
There are a few things to discuss:
- Should "arm-long-calls" be a binary attribute or a tri-state like "unsafe-fp-math" that takes a value "true" or "false"? I made it a binary attribute because it simplifies the backend and frontend without breaking backward compatibility, but might be use cases that I'm unaware of in which this approach wouldn't work.
- Since we are saving the option in the IR, should we stop passing it as a cc1 backend option and stop passing it to llvm:🆑:ParseCommandLineOptions? It's not needed if this attribute is a tri-state, but is needed if it's a binary to preserve backward compatibility. By "backward compatibility", I mean the following commands should produce the same result before and after this patch is committed:
- clang -target armv7-apple-ios -static -mlong-calls old.bc -o old
- clang -target armv7-apple-ios -static old.bc -o old
Here, old.bc is generated by an older version of clang that doesn't save "arm-long-calls" in the IR.