Closed
Description
LLVM's MergeFunctions introduces aliases which can trigger a bug in macOS's ld64
linker when compiling with ThinLTO: https://github.com/froydnj/ld64-aliases-bug
For this reason Firefox has to be built with a patched version of ld64
when compiling with xLTO. Since the bug in question is pretty nasty (the above example shows a program just returning a different value with no indication that anything is wrong), we should probably try to not trigger it.
Right now, however, it seems that one cannot even turn the MergeFunctions pass off in stable Rust. (I wonder if the pass should even be disabled by default on macOS?)
cc @rust-lang/compiler, @rust-lang/wg-codegen & @peterhj (this seems related to #57356)
Metadata
Metadata
Assignees
Labels
Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.Area: Code generationArea: linking into static, shared libraries and binariesIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessOperating system: macOSRelevant to the compiler team, which will review and decide on the PR/issue.
Activity
nox commentedon Sep 9, 2019
michaelwoerister commentedon Sep 9, 2019
It's not a bug in mergefunc. It might not even be a bug in ThinLTO. It's just that mergefunc is the only thing in
rustc
that generates symbol aliases in LLVM IR, and these are what can lead to "miscompilations" when using the macOS linker.nikic commentedon Sep 9, 2019
Has the ld64 bug been reported somewhere?
nox commentedon Sep 9, 2019
We could use
mergefunc-use-aliases
to prevent the pass from emitting aliases on macOS, AFAIK.https://github.com/llvm-mirror/llvm/blob/2afd9e698dbfc2f3011baf3bfdb47d03c253272b/lib/Transforms/IPO/MergeFunctions.cpp#L168-L171
nikic commentedon Sep 9, 2019
@nox This is already supported via either
-Z merge-functions=trampolines
ormerge_functions: MergeFunctions::Trampolines
in the target spec.nox commentedon Sep 9, 2019
@nikic Do you mean that the test case also fails with
mergefunc-use-aliases
enabled, or that we already have a knob to disable them?nox commentedon Sep 9, 2019
rust/src/librustc_codegen_llvm/llvm_util.rs
Lines 65 to 74 in 185b9ac
Answering my own question, we already have a knob for that.
nox commentedon Sep 9, 2019
Which was added because aliases already cause issues on other architectures.
peterhj commentedon Sep 9, 2019
As @nikic and @nox point to there is the unstable
-Z merge-functions
option which I've only tested on nightly. I guess there could be a stabilized-C merge-functions
option, but maybe what you really want to do is to patch the x86_64 macos target definition (I believe this is the correct one: https://github.com/rust-lang/rust/blob/97ba4c95d00108ac79c86d2bbc6834b1fef008a2/src/librustc_target/spec/x86_64_apple_darwin.rs).michaelwoerister commentedon Sep 10, 2019
@nikic
Yes, I've been told that it has been reported to Apple.
On nightly, one can already control the mergefunc pass. On stable, however, one is stuck with the default behavior. That's what this issue is mostly about.
pnkfelix commentedon Sep 10, 2019
@michaelwoerister just want to double-check my understanding: I would have thought one could use the
-C
options-C no-prepopulate-passes
and-C passes=val
to override the set of passes, even on the stable channel.Am I incorrect about this?
(If I am correct, I nonetheless will admit that this is an ugly (and very fragile) method to opt out of the MergeFunctions pass)
11 remaining items