Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[BOLT] Support computed goto and allow map addrs inside functions#120267

Merged
Asher8118 merged 13 commits intollvm:mainfrom
Asher8118:dynam_relocs
Mar 19, 2025
Merged

[BOLT] Support computed goto and allow map addrs inside functions#120267
Asher8118 merged 13 commits intollvm:mainfrom
Asher8118:dynam_relocs

Conversation

@Asher8118
Copy link
Contributor

@Asher8118Asher8118 commentedDec 17, 2024
edited
Loading

Create entry points for addresses referenced by dynamic relocations and allow getNewFunctionOrDataAddress to map addrs inside functions. By adding addresses referenced by dynamic relocations as entry points, this patch fixes an issue where bolt fails on code using computing goto's. This also fixes a mapping issue with the bugfix from this PR:#117766.

…ic relocations and allow getNewFunctionOrDataAddress to map addrs inside functions.By adding addresses referenced by dynamic relocations as entry points,this patch fixes an issue where bolt fails on code using computinggoto's. This also fixes a mapping issue with the bugfix from thisPR:llvm#117766.
@llvmbot
Copy link
Member

@llvm/pr-subscribers-bolt

Author: Rin Dobrescu (Rin18)

Changes

By adding addresses referenced by dynamic relocations as entry points, this patch fixes an issue where bolt fails on code using computing goto's. This also fixes a mapping issue with the bugfix from this PR:#117766.


Full diff:https://github.com/llvm/llvm-project/pull/120267.diff

2 Files Affected:

  • (modified) bolt/lib/Rewrite/RewriteInstance.cpp (+9-1)
  • (added) bolt/test/AArch64/computed-goto.s (+39)
diff --git a/bolt/lib/Rewrite/RewriteInstance.cpp b/bolt/lib/Rewrite/RewriteInstance.cppindex 4329235d470497..55fcd6b6e782c4 100644--- a/bolt/lib/Rewrite/RewriteInstance.cpp+++ b/bolt/lib/Rewrite/RewriteInstance.cpp@@ -2439,6 +2439,14 @@ void RewriteInstance::readDynamicRelocations(const SectionRef &Section,     if (Symbol)       SymbolIndex[Symbol] = getRelocationSymbol(InputFile, Rel);+    const uint64_t SymAddress = SymbolAddress + Addend;+    BinaryFunction *Func = BC->getBinaryFunctionContainingAddress(SymAddress);+    if(Func){+      const uint64_t FunctionOffset = SymAddress - Func->getAddress();+      if(FunctionOffset)+        Func->addEntryPointAtOffset(FunctionOffset);+    }+     BC->addDynamicRelocation(Rel.getOffset(), Symbol, RType, Addend);   } }@@ -5599,7 +5607,7 @@ uint64_t RewriteInstance::getNewFunctionOrDataAddress(uint64_t OldAddress) {         for (const BinaryBasicBlock &BB : *BF)           if (BB.isEntryPoint() &&               (BF->getAddress() + BB.getOffset()) == OldAddress)-            return BF->getOutputAddress() + BB.getOffset();+            return BB.getOutputStartAddress();       }       BC->errs() << "BOLT-ERROR: unable to get new address corresponding to "                     "input address 0x"diff --git a/bolt/test/AArch64/computed-goto.s b/bolt/test/AArch64/computed-goto.snew file mode 100644index 00000000000000..043f9a8e37e6b0--- /dev/null+++ b/bolt/test/AArch64/computed-goto.s@@ -0,0 +1,39 @@+# RUN: llvm-mc -filetype=obj -triple aarch64-unknown-unknown %s -o %t.o+# RUN: %clang %cflags %t.o -o %t.exe -Wl,-q+# RUN: llvm-bolt %t.exe -o %t.bolt 2>&1 | FileCheck %s++## Before bolt could handle mapping addresses within moved functions, it+## would bail out with an error of the form:+## BOLT-ERROR: unable to get new address corresponding to input address 0x10390 in function main. Consider adding this function to --skip-funcs=...+## These addresses arise if computed GOTO is in use.+## Check that bolt does not emit any error.++# CHECK-NOT: BOLT-ERROR++.globl  main+.p2align        2+.type   main,@function+main:+.cfi_startproc+        adrp    x8, .L__const.main.ptrs+8+        add     x8, x8, :lo12:.L__const.main.ptrs+8+        ldr     x9, [x8], #8+        br      x9++.Label0: // Block address taken+        ldr     x9, [x8], #8+        br      x9++.Label1: // Block address taken+        mov     w0, #42+        ret++.Lfunc_end0:+.size   main, .Lfunc_end0-main+.cfi_endproc+        .type   .L__const.main.ptrs,@object+        .section        .data.rel.ro,"aw",@progbits+        .p2align        3, 0x0+.L__const.main.ptrs:+        .xword  .Label0+        .xword  .Label1

@github-actions
Copy link

github-actionsbot commentedDec 17, 2024
edited
Loading

✅ With the latest revision this PR passed the C/C++ code formatter.

Copy link
Contributor

@aaupovaaupov left a comment

Choose a reason for hiding this comment

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

Looks good overall. The PR isn't limited to AArch64, so please drop that from the title. Please make the title more concise, e.g. "Support computed goto", expanding what is changed in the summary.

@Asher8118Asher8118 changed the title[BOLT][AArch64] Create entry points for addresses referenced by dynamic relocations and allow getNewFunctionOrDataAddress to map addrs inside functions.[BOLT] Support computed goto and allow map addrs inside functions.Dec 18, 2024
@Asher8118
Copy link
ContributorAuthor

Looks good overall. The PR isn't limited to AArch64, so please drop that from the title. Please make the title more concise, e.g. "Support computed goto", expanding what is changed in the summary.

Thanks for pointing this out, I'll change the title and summary.

@ms178
Copy link

@Rin18 FYI, this patch might help to improve the usage of BOLT in Python as discussed in a related Python issue, see the comment and discussion in:python/cpython#124948 (comment)

Maybe it is a good test case for this MR, too.

@Asher8118
Copy link
ContributorAuthor

@Rin18 FYI, this patch might help to improve the usage of BOLT in Python as discussed in a related Python issue, see the comment and discussion in:python/cpython#124948 (comment)

Maybe it is a good test case for this MR, too.

Thanks for bringing this to my attention, I'll need to look into the mentioned issue and see if this patch impacts it.

@ms178
Copy link

Thanks for bringing this to my attention, I'll need to look into the mentioned issue and see if this patch impacts it.

Great, please also notice some downstream work on the python side which works around the current BOLT issues and might provide some hints:astral-sh/python-build-standalone#463

Ideally, there should be no need to use--skip-funcs=sre_ucs1_match/1,_PyEval_EvalFrameDefault.localalias/1

@Asher8118
Copy link
ContributorAuthor

Asher8118 commentedJan 3, 2025
edited
Loading

Thanks for bringing this to my attention, I'll need to look into the mentioned issue and see if this patch impacts it.

Great, please also notice some downstream work on the python side which works around the current BOLT issues and might provide some hints:astral-sh/python-build-standalone#463

Ideally, there should be no need to use--skip-funcs=sre_ucs1_match/1,_PyEval_EvalFrameDefault.localalias/1

I've taken a look at the link to the issue you've mentioned. This patch provides support for computed goto's. Once the PR is merged, it should get rid of the need to provide the--skip-funcs flag.

ms178 reacted with thumbs up emoji

ms178 added a commit to ms178/archpkgbuilds that referenced this pull requestJan 10, 2025
- Updated BOLT flags; unfortunately three functions still need to get skipped even with a patched LLVM withllvm/llvm-project#120267
@Asher8118
Copy link
ContributorAuthor

I've added another test that is target independent. Is there anything else needed to approve this patch?

indygreg added a commit to indygreg/toolchain-tools that referenced this pull requestMar 8, 2025
The vendored patches were produced from the latest versions of thefollowing PRs:*llvm/llvm-project#114990*llvm/llvm-project#120267The first improves codegen for computed gotos. There was aregression in LLVM 19 causing a ~10% performance drop in CPython.The second enables BOLT to work with computed gotos. This enablesBOLT to accomplish more on CPython.
indygreg added a commit to indygreg/toolchain-tools that referenced this pull requestMar 8, 2025
The vendored patches were produced from the latest versions of thefollowing PRs:*llvm/llvm-project#114990*llvm/llvm-project#120267The first improves codegen for computed gotos. There was aregression in LLVM 19 causing a ~10% performance drop in CPython.The second enables BOLT to work with computed gotos. This enablesBOLT to accomplish more on CPython.
indygreg added a commit to indygreg/toolchain-tools that referenced this pull requestMar 9, 2025
The vendored patches were produced from the latest versions of thefollowing PRs:*llvm/llvm-project#114990*llvm/llvm-project#120267The first improves codegen for computed gotos. There was aregression in LLVM 19 causing a ~10% performance drop in CPython.The second enables BOLT to work with computed gotos. This enablesBOLT to accomplish more on CPython.
indygreg added a commit to indygreg/toolchain-tools that referenced this pull requestMar 9, 2025
The vendored patches were produced from the latest versions of thefollowing PRs:*llvm/llvm-project#114990*llvm/llvm-project#120267The first improves codegen for computed gotos. There was aregression in LLVM 19 causing a ~10% performance drop in CPython.The second enables BOLT to work with computed gotos. This enablesBOLT to accomplish more on CPython.
indygreg added a commit to indygreg/toolchain-tools that referenced this pull requestMar 9, 2025
The vendored patches were produced from the latest versions of thefollowing PRs:*llvm/llvm-project#114990*llvm/llvm-project#120267The first improves codegen for computed gotos. There was aregression in LLVM 19 causing a ~10% performance drop in CPython.The second enables BOLT to work with computed gotos. This enablesBOLT to accomplish more on CPython.
if (const uint64_t ReferenceOffset =
ReferencedAddress - Func->getAddress()) {
Func->addEntryPointAtOffset(ReferenceOffset);
} else if (ReferencedAddress < Func->getAddress()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

SinceFunc is discovered usinggetBinaryFunctionContainingAddress(ReferencedAddress), we should never hit this condition. You can useReferencedOffset unconditionally.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

I think we can hit the case where the contained address is the same as the function address, leadingReferenceOffset to be 0. But the else if condition is redundant you're right. I have removed it.

Copy link
Contributor

@maksfbmaksfb left a comment

Choose a reason for hiding this comment

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

Looks good, but please address the comment regarding the hex print before committing. Thanks!

}
} else {
BC->errs() << "BOLT-ERROR: referenced address at 0x"
<< ReferencedAddress
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
<< ReferencedAddress
<<Twine::utohexstr(ReferencedAddress)

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

please address the comment regarding the hex print before committing

I apologise, I thought I addressed that in my previous commit. It is in hex print now. Thanks for the review!

maksfb reacted with thumbs up emoji
@Asher8118Asher8118 merged commit3bba268 intollvm:mainMar 19, 2025
10 checks passed
@tuliom
Copy link
Contributor

Testindirect-goto-relocs.test is failing on aarch64 in theCHECK-NO-PIE-NOT scenario:

RUN: at line 8: /builddir/build/BUILD/llvm-21.0.0_pre20250321.gfe6bced9e40f7d-build/llvm-project-fe6bced9e40f7d4c35550c51ef9cdc7be2a055e7/llvm/redhat-linux-build/bin/llvm-bolt --runtime-instrumentation-lib=/builddir/build/BUILD/llvm-21.0.0_pre20250321.gfe6bced9e40f7d-build/llvm-project-fe6bced9e40f7d4c35550c51ef9cdc7be2a055e7/llvm/redhat-linux-build/tools/bolt/bolt_rt-bins/lib/libbolt_rt_instr.a --runtime-hugify-lib=/builddir/build/BUILD/llvm-21.0.0_pre20250321.gfe6bced9e40f7d-build/llvm-project-fe6bced9e40f7d4c35550c51ef9cdc7be2a055e7/llvm/redhat-linux-build/tools/bolt/bolt_rt-bins/lib/libbolt_rt_hugify.a /builddir/build/BUILD/llvm-21.0.0_pre20250321.gfe6bced9e40f7d-build/llvm-project-fe6bced9e40f7d4c35550c51ef9cdc7be2a055e7/llvm/redhat-linux-build/tools/bolt/test/Output/indirect-goto-relocs.test.tmp.exe -o /builddir/build/BUILD/llvm-21.0.0_pre20250321.gfe6bced9e40f7d-build/llvm-project-fe6bced9e40f7d4c35550c51ef9cdc7be2a055e7/llvm/redhat-linux-build/tools/bolt/test/Output/indirect-goto-relocs.test.tmp.bolt --print-cfg | /builddir/build/BUILD/llvm-21.0.0_pre20250321.gfe6bced9e40f7d-build/llvm-project-fe6bced9e40f7d4c35550c51ef9cdc7be2a055e7/llvm/redhat-linux-build/bin/FileCheck --check-prefix=CHECK-NO-PIE /builddir/build/BUILD/llvm-21.0.0_pre20250321.gfe6bced9e40f7d-build/llvm-project-fe6bced9e40f7d4c35550c51ef9cdc7be2a055e7/bolt/test/indirect-goto-relocs.test+ /builddir/build/BUILD/llvm-21.0.0_pre20250321.gfe6bced9e40f7d-build/llvm-project-fe6bced9e40f7d4c35550c51ef9cdc7be2a055e7/llvm/redhat-linux-build/bin/llvm-bolt --runtime-instrumentation-lib=/builddir/build/BUILD/llvm-21.0.0_pre20250321.gfe6bced9e40f7d-build/llvm-project-fe6bced9e40f7d4c35550c51ef9cdc7be2a055e7/llvm/redhat-linux-build/tools/bolt/bolt_rt-bins/lib/libbolt_rt_instr.a --runtime-hugify-lib=/builddir/build/BUILD/llvm-21.0.0_pre20250321.gfe6bced9e40f7d-build/llvm-project-fe6bced9e40f7d4c35550c51ef9cdc7be2a055e7/llvm/redhat-linux-build/tools/bolt/bolt_rt-bins/lib/libbolt_rt_hugify.a /builddir/build/BUILD/llvm-21.0.0_pre20250321.gfe6bced9e40f7d-build/llvm-project-fe6bced9e40f7d4c35550c51ef9cdc7be2a055e7/llvm/redhat-linux-build/tools/bolt/test/Output/indirect-goto-relocs.test.tmp.exe -o /builddir/build/BUILD/llvm-21.0.0_pre20250321.gfe6bced9e40f7d-build/llvm-project-fe6bced9e40f7d4c35550c51ef9cdc7be2a055e7/llvm/redhat-linux-build/tools/bolt/test/Output/indirect-goto-relocs.test.tmp.bolt --print-cfg+ /builddir/build/BUILD/llvm-21.0.0_pre20250321.gfe6bced9e40f7d-build/llvm-project-fe6bced9e40f7d4c35550c51ef9cdc7be2a055e7/llvm/redhat-linux-build/bin/FileCheck --check-prefix=CHECK-NO-PIE /builddir/build/BUILD/llvm-21.0.0_pre20250321.gfe6bced9e40f7d-build/llvm-project-fe6bced9e40f7d4c35550c51ef9cdc7be2a055e7/bolt/test/indirect-goto-relocs.test/builddir/build/BUILD/llvm-21.0.0_pre20250321.gfe6bced9e40f7d-build/llvm-project-fe6bced9e40f7d4c35550c51ef9cdc7be2a055e7/bolt/test/indirect-goto-relocs.test:18:19: error: CHECK-NO-PIE-NOT: excluded string found in inputCHECK-NO-PIE-NOT: IsMultiEntry: 1                  ^<stdin>:365:2: note: found here IsMultiEntry: 1 ^~~~~~~~~~~~~~~/builddir/build/BUILD/llvm-21.0.0_pre20250321.gfe6bced9e40f7d-build/llvm-project-fe6bced9e40f7d4c35550c51ef9cdc7be2a055e7/bolt/test/indirect-goto-relocs.test:19:19: error: CHECK-NO-PIE-NOT: excluded string found in inputCHECK-NO-PIE-NOT: Secondary Entry Points : {{.*}}                  ^<stdin>:369:2: note: found here Secondary Entry Points : __ENTRY_.Ltmp3, __ENTRY_.Ltmp2, __ENTRY_.Ltmp1 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Input file: <stdin>Check file: /builddir/build/BUILD/llvm-21.0.0_pre20250321.gfe6bced9e40f7d-build/llvm-project-fe6bced9e40f7d4c35550c51ef9cdc7be2a055e7/bolt/test/indirect-goto-relocs.test-dump-input=help explains the following input dump.Input was:<<<<<<        .        .        .      360:  Offset : 0x76c       361:  Section : .text       362:  Orc Section : .local.text.main       363:  LSDA : 0x0       364:  IsSimple : 0       365:  IsMultiEntry: 1 not:18      !~~~~~~~~~~~~~~  error: no match expected      366:  IsSplit : 0       367:  BB Count : 6       368:  Hash : b6244c5a20ea24fa       369:  Secondary Entry Points : __ENTRY_.Ltmp3, __ENTRY_.Ltmp2, __ENTRY_.Ltmp1 not:19      !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  error: no match expected      370:  CFI Instrs : 5       371:  BB Layout : .LBB07, .Ltmp8, .Ltmp1, .Ltmp2, .Ltmp3, .Ltmp9       372: }       373: .LBB07 (16 instructions, align : 1)       374:  Entry Point         .        .        .>>>>>>

@Rin18 , can you reproduce this?

A full log is available at:https://download.copr.fedorainfracloud.org/results/@fedora-llvm-team/llvm-snapshots-big-merge-20250321/fedora-rawhide-aarch64/08800037-llvm/builder-live.log.gz

@Asher8118
Copy link
ContributorAuthor

can you reproduce this?

@tuliom yes I am able to reproduce this after pulling all the changes from main. Looks like something changed while I was working on the patch and extra entry points for dynamic relocations are added even in the NON-PIE case. I'll have to look into which commit adds this problem.

tuliom reacted with heart emoji

@Asher8118
Copy link
ContributorAuthor

Asher8118 commentedMar 25, 2025
edited
Loading

@tuliom after doing a bisect I've found the commit from this PR to be the reason for the failure:#120187.
My apologies, I added the wrong PR initially, it is the commit from this PR that I found during the bisect:#120713. Trying to understand the cause.

@Asher8118
Copy link
ContributorAuthor

@aaupov@maksfb would you be ok with removing the NO-PIE case from theindirect-goto-relocs.test while finding a fix for the failure?

@maksfb
Copy link
Contributor

@aaupov@maksfb would you be ok with removing the NO-PIE case from theindirect-goto-relocs.test while finding a fix for the failure?

Does the test fail regardless of the change in this (#120267) PR? Yes, it's reasonable to back it out.

@Asher8118
Copy link
ContributorAuthor

@aaupov@maksfb would you be ok with removing the NO-PIE case from theindirect-goto-relocs.test while finding a fix for the failure?

Does the test fail regardless of the change in this (#120267) PR? Yes, it's reasonable to back it out.

Yes, I've checked the NO-PIE test without the changes in my PR and it fails. Thanks, I'll remove the test.

Asher8118 pushed a commit to Asher8118/llvm-project-fork that referenced this pull requestMar 26, 2025
This test was added in PR:llvm#120267.The -no-pie case in the above mentioned test needs to be removedas subsequent changes have caused it to fail.
Asher8118 pushed a commit that referenced this pull requestMar 26, 2025
This test was added in PR:#120267. The -no-pie case inthe above mentioned test needs to be removed as subsequent changes havecaused it to fail.
llvm-syncbot pushed a commit to arm/arm-toolchain that referenced this pull requestMar 26, 2025
This test was added in PR:llvm/llvm-project#120267. The -no-pie case inthe above mentioned test needs to be removed as subsequent changes havecaused it to fail.
ash-arm pushed a commit to arm/large-bolt-tests that referenced this pull requestSep 18, 2025
The python and postgres tests ensure that,followingllvm/llvm-project#120267,bolt can successfully run on those binaries without any errorsand without the need for the --skip-funcs flag. The rustc andnginx tests only check that bolt can successfully run with no errorson those binaries.
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@aaupovaaupovaaupov left review comments

@yota9yota9yota9 left review comments

@maksfbmaksfbmaksfb approved these changes

@rafaelaulerrafaelaulerAwaiting requested review from rafaelaulerrafaelauler is a code owner

@ayermoloayermoloAwaiting requested review from ayermoloayermolo is a code owner

@dccidcciAwaiting requested review from dcci

@peterwaller-armpeterwaller-armAwaiting requested review from peterwaller-arm

Assignees

No one assigned

Labels

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

10 participants

@Asher8118@llvmbot@ms178@ilinpv@zanieb@aaupov@tuliom@maksfb@yota9@ash-arm

Comments


[8]ページ先頭

©2009-2026 Movatter.jp