Currently, AsmPrinter code is organized in a way in which the labels of address-taken blocks are emitted in the previous section, which makes the relocation incorrect.
This patch reorganizes the code to switch to the basic block section before handling address-taken blocks.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp | ||
---|---|---|
3090 | I would like a comment which explains the condition but this comment isn't very helpful. Consider rewording or removing. | |
3108 | Wasn't there some concern about empty blocks being present which might confound this check? | |
llvm/test/CodeGen/X86/machine-function-splitter-blockaddress.ll | ||
3 ↗ | (On Diff #295133) | I think this should be part of basic block sections. MFS is using basic block sections and this addresses the underlying issue. |
llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp | ||
---|---|---|
3100 | Could you elaborate on what you mean by label is emitted prior to switching the section? Here it shows as label is emitted only after switching the section. Maybe a simple example would help. |
Thanks for the comments @tmsriram and @snehasish.
llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp | ||
---|---|---|
3090 | Thanks for the comment. If you look at D73674, this exact comment was initially there but we removed it because we wanted the same if-else block to serve other purposes as well. This patch kinds of reverts that change. | |
3100 | It's actually about the ".Ltmp" label emitted in the "MBB.hasAddressTaken()" if block. This patch moves the section switching code before that block. One thing I can suggest is to run the included test on trunk and see the failure. | |
3108 | It is OK for empty basic blocks to begin a section. | |
llvm/test/CodeGen/X86/machine-function-splitter-blockaddress.ll | ||
3 ↗ | (On Diff #295133) | Yes. Changed to a basic-block-sections test. |
lgtm with some minor comments.
llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp | ||
---|---|---|
3052 | Can you extend the comment here to state that this needs to happen before the if (MBB.hasAddressTaken()) part below? | |
llvm/test/CodeGen/X86/basic-block-sections-blockaddress.ll | ||
1 ↗ | (On Diff #295180) | nit: perhaps a better name for this file is "basic-block-sections-address-taken.ll" |
28 ↗ | (On Diff #295180) | I think you meant to only indent the instructions, the labels should be indented less here and above? |
llvm/test/CodeGen/X86/basic-block-sections-blockaddress.ll | ||
---|---|---|
28 ↗ | (On Diff #295180) | The excess indentation is here to satisfy the longest directive CHECK-LABEL. |
llvm/test/CodeGen/X86/basic-block-sections-blockaddress.ll | ||
---|---|---|
28 ↗ | (On Diff #295180) | Interesting, on my end I see that the indentation lines it up with the instructions below. Is this a phabricator quirk? |
- Rename test, and fix indentation.
llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp | ||
---|---|---|
3052 | Thanks for the comment, but I am not sure if it's necessary. (Likewise the alignment code above must be before switching the section, but we don't explicitly mention that). | |
llvm/test/CodeGen/X86/basic-block-sections-blockaddress.ll | ||
1 ↗ | (On Diff #295180) | Changed the test name to basic-block-sections-blockaddress-taken.ll. |
28 ↗ | (On Diff #295180) | The indentation for .Ltmp1: was incorrect. I fixed it. |
Can you extend the comment here to state that this needs to happen before the if (MBB.hasAddressTaken()) part below?