← Back to Pull requests

[DRAFT][bolt] Resolve duplicated symbols name through versioning #203223

Open
yavtuk opened this pull request with 81 lines diff across 2 files
View on GitHub
yavtuk yavtuk commented on Jun 11, 2026 09:43 UTC
Author

Related to PR

Diff: 81 lines (+80 / -1) across 2 files Reviewer: Jinjie-Huang Review duration: 249057m
All Vouch review confidence checks passed
Residual risk 0.04 = Change Risk (0.38) × (1 − Review Confidence (0.90)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.38 · 81 lines diff across 2 files
0.38
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.94 · 4 substantive comment(s)
0.94
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 50%
90%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.264
Real PR Conversation Timeline
6 items
llvmorg-github-actions[bot] llvmorg-github-actions[bot] commented on Jun 11, 2026 09:44 UTC
Bot

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-bolt

Author: Alexey Moksyakov (yavtuk)

<details>
<summary>Changes</summary>

Related to PR

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

2 Files Affected:

  • (modified) bolt/lib/Rewrite/RewriteInstance.cpp (+32-1)

  • (added) bolt/test/duplicate_symbols.test (+44)
  • ``````

    diff --git a/bolt/lib/Rewrite/RewriteInstance.cpp b/bolt/lib/Rewrite/RewriteInstance.cpp
    index 9364e32939982..f4898b01a2528 100644
    --- a/bolt/lib/Rewrite/RewriteInstance.cpp
    +++ b/bolt/lib/Rewrite/RewriteInstance.cpp
    @@ -933,6 +933,34 @@ void RewriteInstance::discoverFileObjects() {
     
         return false;
       };
    +
    +  // read dynamic symbols name and version
    +  DenseMap<uint64_t, std::string> DynSymNames;
    +  Expected<std::vector<VersionEntry>> SymbolVersionOrErr =
    +      InputFile->readDynsymVersions();
    +  if (SymbolVersionOrErr && !SymbolVersionOrErr->empty()) {
    +    ArrayRef<VersionEntry> SymbolVersions = *SymbolVersionOrErr;
    +    for (const SymbolRef &Symbol : InputFile->getDynamicSymbolIterators()) {
    +      const uint64_t SymAddress = cantFail(Symbol.getAddress());
    +      if (!isSymbolInMemory(Symbol) || !SymAddress)
    +        continue;
    +      Expected<StringRef> NameOrError = Symbol.getName();
    +      if (!NameOrError) {
    +        consumeError(NameOrError.takeError());
    +        continue;
    +      }
    +      StringRef SymbolName = *NameOrError;
    +      if (SymbolName.empty())
    +        continue;
    +      const VersionEntry &Ver =
    +          SymbolVersions[Symbol.getRawDataRefImpl().d.b - 1];
    +      if (Ver.Name.empty())
    +        continue;
    +      DynSymNames[SymAddress] =
    +          SymbolName.str() + (Ver.IsVerDef ? "@@" : "@") + Ver.Name;
    +    }
    +  }
    +
       for (const SymbolRef &Symbol : InputFile->symbols())
         if (isSymbolInMemory(Symbol)) {
           SymbolInfo SymInfo{cantFail(Symbol.getAddress()), Symbol};
    @@ -1034,7 +1062,10 @@ void RewriteInstance::discoverFileObjects() {
         if (SymbolType == SymbolRef::ST_File)
           continue;
     
    -    StringRef SymName = cantFail(Symbol.getName(), "cannot get symbol name");
    +    StringRef SymName =
    +        DynSymNames.find(SymbolAddress) != DynSymNames.end()
    +            ? DynSymNames[SymbolAddress]
    +            : cantFail(Symbol.getName(), "cannot get symbol name");
         if (SymbolAddress == 0) {
           if (opts::Verbosity >= 1 && SymbolType == SymbolRef::ST_Function)
             BC->errs() << "BOLT-WARNING: function with 0 address seen\n";
    diff --git a/bolt/test/duplicate_symbols.test b/bolt/test/duplicate_symbols.test
    new file mode 100644
    index 0000000000000..5047c7d496c0f
    --- /dev/null
    +++ b/bolt/test/duplicate_symbols.test
    @@ -0,0 +1,44 @@
    +## Verify that BOLT can correctly process binaries with duplicate symbols.
    +
    +# REQUIRES: system-linux
    +
    +# RUN: llvm-mc -filetype=obj -triple x86_64-unknown-linux %s -o %t.o
    +
    +## Shared library with the duplicate symbol "foo", which requires a version script.
    +# RUN: echo "VERS_1 { global: foo; }; VERS_2 { global: foo; } VERS_1;" > %t.map
    +# RUN: ld.lld %t.o -o %t.so -shared --version-script %t.map
    +# RUN: llvm-bolt %t.so -o %t.so.bolt 2>&1 | FileCheck %s --check-prefix=CHECK-SHARED
    +
    +# CHECK-SHARED-NOT: bad input binary, global symbol "foo" is not unique
    +
    +## Main executable with the duplicate symbol "foo",
    +## linked from a static object/archive without needing a version script.
    +# RUN: ld.lld %t.o -o %t.exe
    +# RUN: not llvm-bolt %t.exe -o %t.exe.bolt 2>&1 | FileCheck %s  --check-prefix=CHECK-STATIC
    +
    +# CHECK-STATIC: BOLT-WARNING: bad input binary, global symbol "foo" is not unique
    +
    +.text
    +.globl _start
    +.type _start, @function
    +_start:
    +  call foo_v1
    +  call foo_v2
    +  ret
    +.size _start, .-_start
    +
    +.globl foo_v1
    +.type foo_v1, @function
    +foo_v1:
    +  nop
    +  nop
    +.size foo_v1, .-foo_v1
    +
    +.globl foo_v2
    +.type foo_v2, @function
    +foo_v2:
    +  ret
    +.size foo_v2, .-foo_v2
    +
    +.symver foo_v1, foo@VERS_1
    +.symver foo_v2, foo@@VERS_2
    \ No newline at end of file
    
    
    ``````

    </details>

    github-actions[bot] github-actions[bot] commented on Jun 11, 2026 09:47 UTC
    Bot

    <!--PREMERGE ADVISOR COMMENT: Linux-->

    :penguin: Linux x64 Test Results

    673 tests passed
    59 tests skipped

    :white_check_mark: The build succeeded and all tests passed.

    Jinjie-Huang Jinjie-Huang commented on code on Jun 11, 2026 12:42 UTC
    Code Review
    bolt/lib/Rewrite/RewriteInstance.cpp:1
    @@ -933,6 +933,38 @@ void RewriteInstance::discoverFileObjects() {
     
         return false;
       };
    +
    +  // read dynamic symbols name and version
    +  DenseMap<uint64_t, std::string> DynSymNames;
    +  Expected<std::vector<VersionEntry>> SymbolVersionOrErr =
    +      InputFile->readDynsymVersions();
    +  if (SymbolVersionOrErr && !SymbolVersionOrErr->empty()) {
    +    ArrayRef<VersionEntry> SymbolVersions = *SymbolVersionOrErr;
    +    for (const SymbolRef &Symbol : InputFile->getDynamicSymbolIterators()) {
    +      const SymbolRef::Type SymbolType = cantFail(Symbol.getType());
    +      if (SymbolType != SymbolRef::ST_Function)
    +        continue;
    +
    +      const uint64_t SymAddress = cantFail(Symbol.getAddress());
    +      if (!isSymbolInMemory(Symbol) || !SymAddress)
    +        continue;
    +      Expected<StringRef> NameOrError = Symbol.getName();
    +      if (!NameOrError) {
    +        consumeError(NameOrError.takeError());
    +        continue;
    +      }
    +      StringRef SymbolName = *NameOrError;
    +      if (SymbolName.empty())
    +        continue;
    +      const VersionEntry &Ver =
    +          SymbolVersions[Symbol.getRawDataRefImpl().d.b - 1];
    +      if (Ver.Name.empty())
    +        continue;
    +      DynSymNames[SymAddress] =

    I'm wondering if all symbol names (e.g., those obtained via relocations, code) come with their versioning information? If not, could this potentially lead to incorrect behavior?

    paschalis-mpeis paschalis-mpeis commented on Jun 12, 2026 14:51 UTC
    Reviewer

    Hey Alexey,

    Thanks for your patch. Registering a versioned name would break parent fragment lookups later. Please check X86/libmysqlclient-entry-cold.test.

    You can also check this by adding foo.cold to your test.

    yavtuk yavtuk commented on Jun 12, 2026 16:32 UTC
    Author

    Hey Alexey,

    > Thanks for your patch. Registering a versioned name would break parent fragment lookups later. Please check X86/libmysqlclient-entry-cold.test.

    > You can also check this by adding foo.cold to your test.

    Hi. Got it. Will check, thanks

    Reviewers
    Assignees
    yavtuk yavtuk
    Labels
    risk: low confidence: 90.4% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 37.8% (MEDIUM) · Higher = larger blast radius
    37.8%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 90.4% · Lower = rushed or shallow review
    90.4%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 3.6% · Safe to merge
    3.6%