-
Notifications
You must be signed in to change notification settings - Fork 11.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit removes the complexity introduced by pending labels in https://reviews.llvm.org/D5915 by using a simpler approach. D5915 aimed to ensure padding placement before `.Ltmp0` for the following code, but at the cost of expensive per-instruction `flushPendingLabels`. ``` // similar to llvm/test/MC/X86/AlignedBundling/labeloffset.s .bundle_lock align_to_end calll .L0$pb .bundle_unlock .L0$pb: popl %eax .Ltmp0: //// padding should be inserted before this label instead of after addl $_GLOBAL_OFFSET_TABLE_+(.Ltmp0-.L0$pb), %eax ``` (D5915 was adjusted by https://reviews.llvm.org/D8072 and https://reviews.llvm.org/D71368) This patch achieves the same goal by setting the offset of the empty MCDataFragment (`Prev`) in `layoutBundle`. This eliminates the need for pending labels and simplifies the code. llvm/test/MC/MachO/pending-labels.s (D71368): relocation symbols are changed, but the result is still supported by linkers.
- Loading branch information
Showing
8 changed files
with
23 additions
and
157 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7500646
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi,
We are working on building LLDB and QEMU for mac-arm64 and we noticed that their dependency libffi has build failures under tip of tree clang. We bisect the clang and trace it back to this patch.
The error message is:
Full build output is https://logs.chromium.org/logs/fuchsia/buildbucket/cr-buildbucket/8736348038352263873/+/u/build_llvm_dependencies/libffi/build/stdout
Could you take a look please?
7500646
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
libffi has a known issue with a pending fix libffi/libffi#857 .
Older Clang versions were not rigid enough to detect this issue. That said, the issue is unrelated to this commit and I believe your bisection result pointed to a wrong commit.
7500646
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thx for pointing out the upstream issue. We will try a libffi roll once it is landed.
But bisection result is correct.
Clang build for revision "75006466296ed4b0f845cbbec4bf77c21de43b40" (this patch). failed to build libffi (https://ci.chromium.org/ui/p/fuchsia/builders/toolchain.ci.shadow/lldb-mac-arm64/b8736348038352263873/overview) . You can fetch the clang from cas in task: https://ci.chromium.org/ui/p/fuchsia/builders/toolchain.ci.shadow/clang-mac-arm64/b8736387029429984945/overview (CAS URL :https://cas-viewer.appspot.com/projects/chromium-swarm/instances/default_instance/blobs/8abd312ecdf45b6b028366dd47473a3242d6c0c9b31c5d29960e8b1546206b4f/578/tree)
Clang build for revision "a091bfe71fdde4358dbfc73926f875cb05121c00" (this patch's parent) pass the libffi build (https://ci.chromium.org/ui/p/fuchsia/builders/toolchain.ci.shadow/lldb-mac-arm64/b8736347996491450193/overview I purposely crashes the build after successfully built libffi). You can fetch this version of clang from task: https://ci.chromium.org/ui/p/fuchsia/builders/toolchain.ci.shadow/clang-mac-arm64/b8736386985363052689/overview (CAS URL: https://cas-viewer.appspot.com/projects/chromium-swarm/instances/default_instance/blobs/dd046fa76346b08fe9643685f1b64a223fb54b19286cd29daeb67af4e34c092a/578/tree)
I was a bit skeptical as well, but this patch did trigger the libffi build failure.
7500646
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The file looks like the file, which will be modified by libffi/libffi#857 .
Do you have a smaller assembly reproduce? A commit last year https://reviews.llvm.org/D153167 should technically catch this assembler issue, though it's possible there were some scenarios only caught by this commit or some assembler changes I made in recent months. Perhaps "pending labels" did paper over some issues.
I'd like to improve llvm/test/MC testsuite to report errors for such cases we previously missed.
7500646
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We confirmed that this change is indeed the culprit. This assembler constraint didn't exist before and you've now imposed it on all users without any way to opt out. Although this change might be desirable, it's a breaking change that is going to affect every existing user of libffi on Apple Silicon (and potentially other projects as well). Even if libffi/libffi#857 is merged, it'll take years for every project that depends on libffi to pick it up, and in the meantime users won't be able to build with Clang 19 and newer. I think we should revert this change and cherry-pick the revert into the 19.1.1 release.
7500646
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: this is a workaround even if you don't modify the libffi source.
You can undefine
HAVE_AS_CFI_PSEUDO_OP
to make#define cfi_*
no-op, since the CFI was broken by older Clang anyway.I don't think "this assembler constraint didn't exist before" is a good reason to restore the previous broken behavior.
Even outside assemblers, we've made a lot of changes to change silent breakage to explicit rejection.
FWIW: https://reviews.llvm.org/D153167 (2023-06) rejected a lot of invalid cases.
Pending labels were probably more broken on Mach-O (https://reviews.llvm.org/D71368 2019), so removing pending labels might lead to more legitimate rejection.
7500646
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That doesn't work, at least not without patching the code, since
HAVE_AS_CFI_PSEUDO_OP
is defined in the generated header.There's no documented assembler semantics that says that this syntax is invalid. The correct solution is to address the issue with pending labels implementation rather than breaking the compatibility with other assemblers.
7500646
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apple's cctools as was modified from binutils. LLVM integrated assembler ported its behavior but the implementation has always been brittle and there hasn't been many diagnostics.
There isn't a spec about .subsections_via_symbols's behavior. We have to reason about them with code.
As early as 2010 (even before ede8e6d),
_bar
below triggers a new data fragment and becomes its atom.L1
belongs to the earlier fragment with_foo
as the atom, whileL2
belongs to the latter fragment with_bar
as the atom.Label differences with different atoms (e.g.
L2 - L1
) are invalid when relocations are disallowed.(The linker might move the two subsection to different place, and
L2 - L1
without relocations cannot be represented.)Similarly (if we replace
L1
with a.cfi_startproc
), when a non-privatefoo
appears between .cfi_startproc/.cfi_endproc, this should be invalid.(https://reviews.llvm.org/D5915 (2014), intended for ELF, changed Mach-O behavior as well and made the invalid
.cfi_offset
legal.)Actually there is a parse-time error when the assembler has seen
.globl
(https://reviews.llvm.org/D153167 2023):If
.globl foo
is moved after.cfi_endproc
, there will not be such an error, but the case is still invalid.I want to see arguments that libffi is so important that requires a workaround implemented in the assembler.
If that is justified, we could add a temporary
cl::opt<bool>
to changeevaluateAsAbsolute
toevaluateKnownAbsolute
inMCAssembler::relaxDwarfCallFrameFragment
.