[llvm-branch-commits] [llvm] d77d2b7 - [Propeller] Make decoding BBAddrMaps trace through relocations

Aiden Grossman via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Sat Feb 25 02:41:31 PST 2023


Author: Aiden Grossman
Date: 2023-02-25T10:30:37Z
New Revision: d77d2b71558dd8de68c8d718a2dca17c1704b661

URL: https://github.com/llvm/llvm-project/commit/d77d2b71558dd8de68c8d718a2dca17c1704b661
DIFF: https://github.com/llvm/llvm-project/commit/d77d2b71558dd8de68c8d718a2dca17c1704b661.diff

LOG: [Propeller] Make decoding BBAddrMaps trace through relocations

Currently when using the LLVM tools (eg llvm-readobj, llvm-objdump) to
find information about basic block locations using the propeller tooling
in relocatable object files function addresses are not mapped properly
which causes problems. In llvm-readobj this means that incorrect
function names will be pulled. In llvm-objdum this means that most BBs
won't show up in the output if --symbolize-operands is used. This patch
changes the behavior of decodeBBAddrMap to trace through relocations
to get correct function addresses if it is going through a relocatable
object file. This fixes the behavior in both tools and also other
consumers of decodeBBAddrMap. Some helper functions have been added
in/refactoring done to aid in grabbing BB address map sections now that
in some cases both relocation and BB address map sections need to be
obtained at the same time.

Regression tests moved around/added.

Differential Revision: https://reviews.llvm.org/D143841

Added: 
    llvm/test/tools/llvm-objdump/X86/elf-bbaddrmap-symbolize-relocatable.yaml
    llvm/test/tools/llvm-readobj/ELF/bb-addr-map-relocatable.test

Modified: 
    llvm/include/llvm/Object/ELF.h
    llvm/lib/Object/ELF.cpp
    llvm/lib/Object/ELFObjectFile.cpp
    llvm/test/tools/llvm-objdump/X86/elf-bbaddrmap-disassemble-symbolize-operands.yaml
    llvm/tools/llvm-readobj/ELFDumper.cpp
    llvm/unittests/Object/ELFObjectFileTest.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/Object/ELF.h b/llvm/include/llvm/Object/ELF.h
index aaa0418b9ffa..8e69fb03e074 100644
--- a/llvm/include/llvm/Object/ELF.h
+++ b/llvm/include/llvm/Object/ELF.h
@@ -392,7 +392,9 @@ class ELFFile {
   Expected<ArrayRef<T>> getSectionContentsAsArray(const Elf_Shdr &Sec) const;
   Expected<ArrayRef<uint8_t>> getSectionContents(const Elf_Shdr &Sec) const;
   Expected<ArrayRef<uint8_t>> getSegmentContents(const Elf_Phdr &Phdr) const;
-  Expected<std::vector<BBAddrMap>> decodeBBAddrMap(const Elf_Shdr &Sec) const;
+  Expected<std::vector<BBAddrMap>>
+  decodeBBAddrMap(const Elf_Shdr &Sec,
+                  const std::optional<Elf_Shdr> &RelaSec = {}) const;
   Error getSectionAndRelocations(
       std::function<Expected<bool>(const Elf_Shdr &)> IsMatch,
       llvm::MapVector<const Elf_Shdr *, const Elf_Shdr *> &SecToRelocMap) const;

diff  --git a/llvm/lib/Object/ELF.cpp b/llvm/lib/Object/ELF.cpp
index c6a9e13e4265..67f234bc2a65 100644
--- a/llvm/lib/Object/ELF.cpp
+++ b/llvm/lib/Object/ELF.cpp
@@ -639,8 +639,19 @@ ELFFile<ELFT>::toMappedAddr(uint64_t VAddr, WarningHandler WarnHandler) const {
 }
 
 template <class ELFT>
-Expected<std::vector<BBAddrMap>>
-ELFFile<ELFT>::decodeBBAddrMap(const Elf_Shdr &Sec) const {
+Expected<std::vector<BBAddrMap>> ELFFile<ELFT>::decodeBBAddrMap(
+    const Elf_Shdr &Sec, const std::optional<Elf_Shdr> &RelaSec) const {
+  bool IsRelocatable = getHeader().e_type == ELF::ET_REL;
+  assert(!IsRelocatable || (IsRelocatable && RelaSec));
+  llvm::DenseMap<uint64_t, uint64_t> BBAddrMapTranslations;
+  if(IsRelocatable && RelaSec) {
+    Expected<Elf_Rela_Range> Relas = this->relas(*RelaSec);
+    if(!Relas) 
+      return Relas.takeError();
+    for (Elf_Rela Rela: *Relas) {
+      BBAddrMapTranslations[Rela.r_offset] = Rela.r_addend;
+    }
+  }
   Expected<ArrayRef<uint8_t>> ContentsOrErr = getSectionContents(Sec);
   if (!ContentsOrErr)
     return ContentsOrErr.takeError();
@@ -680,7 +691,12 @@ ELFFile<ELFT>::decodeBBAddrMap(const Elf_Shdr &Sec) const {
                            Twine(static_cast<int>(Version)));
       Data.getU8(Cur); // Feature byte
     }
+    uint64_t SectionOffset = Cur.tell();
     uintX_t Address = static_cast<uintX_t>(Data.getAddress(Cur));
+    if(IsRelocatable) {
+      assert(Address == 0);
+      Address = BBAddrMapTranslations[SectionOffset];
+    }
     uint32_t NumBlocks = ReadULEB128AsUInt32();
     std::vector<BBAddrMap::BBEntry> BBEntries;
     uint32_t PrevBBEndOffset = 0;

diff  --git a/llvm/lib/Object/ELFObjectFile.cpp b/llvm/lib/Object/ELFObjectFile.cpp
index 4ce240324b19..aa9570071bec 100644
--- a/llvm/lib/Object/ELFObjectFile.cpp
+++ b/llvm/lib/Object/ELFObjectFile.cpp
@@ -681,24 +681,36 @@ template <class ELFT>
 Expected<std::vector<BBAddrMap>> static readBBAddrMapImpl(
     const ELFFile<ELFT> &EF, std::optional<unsigned> TextSectionIndex) {
   using Elf_Shdr = typename ELFT::Shdr;
+  bool IsRelocatable = EF.getHeader().e_type == ELF::ET_REL;
   std::vector<BBAddrMap> BBAddrMaps;
+  llvm::MapVector<const Elf_Shdr*, const Elf_Shdr *> SectionRelocMap;
+
   const auto &Sections = cantFail(EF.sections());
-  for (const Elf_Shdr &Sec : Sections) {
+  auto IsMatch = [&](const Elf_Shdr &Sec) -> Expected<bool> {
     if (Sec.sh_type != ELF::SHT_LLVM_BB_ADDR_MAP &&
         Sec.sh_type != ELF::SHT_LLVM_BB_ADDR_MAP_V0)
-      continue;
-    if (TextSectionIndex) {
+      return false;
+    if(TextSectionIndex) {
       Expected<const Elf_Shdr *> TextSecOrErr = EF.getSection(Sec.sh_link);
       if (!TextSecOrErr)
-        return createError("unable to get the linked-to section for " +
-                           describe(EF, Sec) + ": " +
-                           toString(TextSecOrErr.takeError()));
+        return TextSecOrErr.takeError();
       if (*TextSectionIndex != std::distance(Sections.begin(), *TextSecOrErr))
-        continue;
+        return false;
     }
-    Expected<std::vector<BBAddrMap>> BBAddrMapOrErr = EF.decodeBBAddrMap(Sec);
+    return true;
+  };
+  
+  Error PossibleSecRelocError = EF.getSectionAndRelocations(IsMatch, SectionRelocMap);
+  if(PossibleSecRelocError)
+    return std::move(PossibleSecRelocError);
+
+  for (auto const& [Sec, RelocSec] : SectionRelocMap) {
+    std::optional<Elf_Shdr> RelaSec = {};
+    if(IsRelocatable)
+      RelaSec = *RelocSec;
+    Expected<std::vector<BBAddrMap>> BBAddrMapOrErr = EF.decodeBBAddrMap(*Sec, RelaSec);
     if (!BBAddrMapOrErr)
-      return createError("unable to read " + describe(EF, Sec) + ": " +
+      return createError("unable to read " + describe(EF, *Sec) + ": " +
                          toString(BBAddrMapOrErr.takeError()));
     std::move(BBAddrMapOrErr->begin(), BBAddrMapOrErr->end(),
               std::back_inserter(BBAddrMaps));

diff  --git a/llvm/test/tools/llvm-objdump/X86/elf-bbaddrmap-disassemble-symbolize-operands.yaml b/llvm/test/tools/llvm-objdump/X86/elf-bbaddrmap-disassemble-symbolize-operands.yaml
index 2d4a52211f81..cf4ac77b3d15 100644
--- a/llvm/test/tools/llvm-objdump/X86/elf-bbaddrmap-disassemble-symbolize-operands.yaml
+++ b/llvm/test/tools/llvm-objdump/X86/elf-bbaddrmap-disassemble-symbolize-operands.yaml
@@ -5,19 +5,12 @@
 # UNSUPPORTED: system-windows
 
 ## Executable object file.
-# RUN: yaml2obj --docnum=1 -DTYPE=ET_EXEC -DFOO_ADDR=0x4000 -DBAR_ADDR=0x5000 %s -o %t1
+# RUN: yaml2obj --docnum=1 -DFOO_ADDR=0x4000 -DBAR_ADDR=0x5000 %s -o %t1
 # RUN: llvm-objdump %t1 -d --symbolize-operands -M intel --no-show-raw-insn --no-leading-addr | \
 # RUN:   FileCheck %s -DSYM=symbol --match-full-lines --check-prefixes=INTEL
 # RUN: llvm-objdump %t1 -d --symbolize-operands -M att --no-show-raw-insn --no-leading-addr | \
 # RUN:   FileCheck %s -DSYM=symbol --match-full-lines --check-prefixes=ATT
 
-## Relocatable object file.
-# RUN: yaml2obj --docnum=1 -DTYPE=ET_REL -DFOO_ADDR=0x0 -DBAR_ADDR=0x0 %s -o %t2
-# RUN: llvm-objdump %t2 -d --symbolize-operands -M intel --no-show-raw-insn --no-leading-addr | \
-# RUN:   FileCheck %s -DSYM=foo+0x200c --match-full-lines --check-prefix=INTEL
-# RUN: llvm-objdump %t2 -d --symbolize-operands -M att --no-show-raw-insn --no-leading-addr | \
-# RUN:   FileCheck %s -DSYM=foo+0x200c --match-full-lines --check-prefix=ATT
-
 ## Executable object file with a single SHT_LLVM_BB_ADDR_MAP for multiple text sections.
 # RUN: yaml2obj --docnum=2 %s -o %t3
 # RUN: llvm-objdump %t3 -d --symbolize-operands -M intel --no-show-raw-insn --no-leading-addr | \
@@ -78,7 +71,7 @@
 FileHeader:
   Class:   ELFCLASS64
   Data:    ELFDATA2LSB
-  Type:    [[TYPE]]
+  Type:    ET_EXEC
   Machine: EM_X86_64
 Sections:
   - Name:    .text.foo

diff  --git a/llvm/test/tools/llvm-objdump/X86/elf-bbaddrmap-symbolize-relocatable.yaml b/llvm/test/tools/llvm-objdump/X86/elf-bbaddrmap-symbolize-relocatable.yaml
new file mode 100644
index 000000000000..31fbcffbf474
--- /dev/null
+++ b/llvm/test/tools/llvm-objdump/X86/elf-bbaddrmap-symbolize-relocatable.yaml
@@ -0,0 +1,137 @@
+## Test that in the presence of SHT_LLVM_BB_ADDR_MAP sections,
+## --symbolize-operands can display <BB*> labels properly in a relocatable
+## object file.
+
+# Fails on windows (https://github.com/llvm/llvm-project/issues/60013).
+# UNSUPPORTED: system-windows
+
+## Relocatable Object file.
+# RUN: yaml2obj %s -o %t1
+# RUN: llvm-objdump %t1 -d --symbolize-operands -M intel --no-show-raw-insn --no-leading-addr | \
+# RUN:   FileCheck %s -DSYM=symbol --match-full-lines --check-prefixes=INTEL
+# RUN: llvm-objdump %t1 -d --symbolize-operands -M att --no-show-raw-insn --no-leading-addr | \
+# RUN:   FileCheck %s -DSYM=symbol --match-full-lines --check-prefixes=ATT
+
+--- !ELF
+FileHeader:
+  Class:           ELFCLASS64
+  Data:            ELFDATA2LSB
+  Type:            ET_REL
+  Machine:         EM_X86_64
+  SectionHeaderStringTable: .strtab
+Sections:
+  - Name:    .text
+    Type:    SHT_PROGBITS
+    Flags:   [ SHF_ALLOC, SHF_EXECINSTR ]
+    Content: 554889E5897DFC8B45FCC1E0015DC390554889E5897DF8837DF8050F8E0E0000008B45F883E8058945FCE9060000008B45F88945FC8B45FC5DC3
+  - Name:    .llvm_bb_addr_map
+    Type:    SHT_LLVM_BB_ADDR_MAP
+    Link:    .text
+    Entries:
+      - Version: 2
+        BBEntries:
+          - ID:              0
+            AddressOffset:   0x0
+            Size:            0xF
+            Metadata:        0x1
+      - Version: 2
+        BBEntries:
+          - ID:              0
+            AddressOffset:   0x0
+            Size:            0x11
+            Metadata:        0x8
+          - ID:              1
+            AddressOffset:   0x0
+            Size:            0xE
+            Metadata:        0x0
+          - ID:              2
+            AddressOffset:   0x0
+            Size:            0x6
+            Metadata:        0x8
+          - ID:              3
+            AddressOffset:   0x0
+            Size:            0x5
+            Metadata:        0x1
+  - Name:  .rela.llvm_bb_addr_map
+    Type:  SHT_RELA
+    Flags: [ SHF_INFO_LINK ]
+    Link:  .symtab
+    Info:  .llvm_bb_addr_map
+    Relocations:
+      - Offset: 0x2
+        Symbol: .text
+        Type:   R_X86_64_64
+      - Offset: 0x11
+        Symbol: .text
+        Type:   R_X86_64_64
+        Addend: 16
+Symbols:
+  - Name:    a
+    Section: .text
+    Value:   0x0
+  - Name:    c
+    Section: .text
+    Value:   0x10
+  - Name:    .text
+    Type:    STT_SECTION
+    Section: .text
+
+# ATT:      <a>:
+# ATT-NEXT: <BB0>:
+# ATT-NEXT:   pushq   %rbp
+# ATT-NEXT:   movq    %rsp, %rbp
+# ATT-NEXT:   movl    %edi, -0x4(%rbp)
+# ATT-NEXT:   movl    -0x4(%rbp), %eax
+# ATT-NEXT:   shll    $0x1, %eax
+# ATT-NEXT:   popq    %rbp
+# ATT-NEXT:   retq
+# ATT-NEXT:   nop
+# ATT:      <c>:
+# ATT-NEXT: <BB0>:
+# ATT-NEXT:   pushq   %rbp
+# ATT-NEXT:   movq    %rsp, %rbp
+# ATT-NEXT:   movl    %edi, -0x8(%rbp)
+# ATT-NEXT:   cmpl    $0x5, -0x8(%rbp)
+# ATT-NEXT:   jle      <BB2>
+# ATT-NEXT: <BB1>:
+# ATT-NEXT:   movl    -0x8(%rbp), %eax
+# ATT-NEXT:   subl    $0x5, %eax
+# ATT-NEXT:   movl    %eax, -0x4(%rbp)
+# ATT-NEXT:   jmp      <BB3>
+# ATT-NEXT: <BB2>:
+# ATT-NEXT:   movl    -0x8(%rbp), %eax
+# ATT-NEXT:   movl    %eax, -0x4(%rbp)
+# ATT-NEXT: <BB3>:
+# ATT-NEXT:   movl    -0x4(%rbp), %eax
+# ATT-NEXT:   popq    %rbp
+# ATT-NEXT:   retq
+
+# INTEL:      <a>:
+# INTEL-NEXT: <BB0>:
+# INTEL-NEXT:   push    rbp
+# INTEL-NEXT:   mov     rbp, rsp
+# INTEL-NEXT:   mov     dword ptr [rbp - 0x4], edi
+# INTEL-NEXT:   mov     eax, dword ptr [rbp - 0x4]
+# INTEL-NEXT:   shl     eax, 0x1
+# INTEL-NEXT:   pop     rbp
+# INTEL-NEXT:   ret
+# INTEL-NEXT:   nop
+# INTEL:      <c>:
+# INTEL-NEXT: <BB0>:
+# INTEL-NEXT:   push    rbp
+# INTEL-NEXT:   mov     rbp, rsp
+# INTEL-NEXT:   mov     dword ptr [rbp - 0x8], edi
+# INTEL-NEXT:   cmp     dword ptr [rbp - 0x8], 0x5
+# INTEL-NEXT:   jle      <BB2>
+# INTEL-NEXT: <BB1>:
+# INTEL-NEXT:   mov     eax, dword ptr [rbp - 0x8]
+# INTEL-NEXT:   sub     eax, 0x5
+# INTEL-NEXT:   mov     dword ptr [rbp - 0x4], eax
+# INTEL-NEXT:   jmp      <BB3>
+# INTEL-NEXT: <BB2>:
+# INTEL-NEXT:   mov     eax, dword ptr [rbp - 0x8]
+# INTEL-NEXT:   mov     dword ptr [rbp - 0x4], eax
+# INTEL-NEXT: <BB3>:
+# INTEL-NEXT:   mov     eax, dword ptr [rbp - 0x4]
+# INTEL-NEXT:   pop     rbp
+# INTEL-NEXT:   ret

diff  --git a/llvm/test/tools/llvm-readobj/ELF/bb-addr-map-relocatable.test b/llvm/test/tools/llvm-readobj/ELF/bb-addr-map-relocatable.test
new file mode 100644
index 000000000000..0ccc55d2335a
--- /dev/null
+++ b/llvm/test/tools/llvm-readobj/ELF/bb-addr-map-relocatable.test
@@ -0,0 +1,131 @@
+## This test checks how we handle the --bb-addr-map option on relocatable
+## object files.
+
+## Fails on windows (https://github.com/llvm/llvm-project/issues/60013).
+## UNSUPPORTED: system-windows
+
+# RUN: yaml2obj %s -o %t1.o
+# RUN: llvm-readobj %t1.o --bb-addr-map | FileCheck %s
+
+# CHECK:      BBAddrMap [
+# CHECK-NEXT:   Function {
+# CHECK-NEXT:     At: 0x0
+# CHECK-NEXT:     Name: <?>
+# CHECK-NEXT:     BB entries [
+# CHECK-NEXT:       {
+# CHECK-NEXT:         ID: 0
+# CHECK-NEXT:         Offset: 0x0
+# CHECK-NEXT:         Size: 0xF
+# CHECK-NEXT:         HasReturn: Yes
+# CHECK-NEXT:         HasTailCall: No
+# CHECK-NEXT:         IsEHPad: No
+# CHECK-NEXT:         CanFallThrough: No
+# CHECK-NEXT:       }
+# CHECK-NEXT:     ]
+# CHECK-NEXT:   }
+# CHECK-NEXT:   Function {
+# CHECK-NEXT:     At: 0x10
+# CHECK-NEXT:     Name: <?>
+# CHECK-NEXT:     BB entries [
+# CHECK-NEXT:       {
+# CHECK-NEXT:         ID: 0
+# CHECK-NEXT:         Offset: 0x0
+# CHECK-NEXT:         Size: 0x11
+# CHECK-NEXT:         HasReturn: No
+# CHECK-NEXT:         HasTailCall: No
+# CHECK-NEXT:         IsEHPad: No
+# CHECK-NEXT:         CanFallThrough: Yes
+# CHECK-NEXT:       }
+# CHECK-NEXT:       {
+# CHECK-NEXT:         ID: 1
+# CHECK-NEXT:         Offset: 0x11
+# CHECK-NEXT:         Size: 0xE
+# CHECK-NEXT:         HasReturn: No
+# CHECK-NEXT:         HasTailCall: No
+# CHECK-NEXT:         IsEHPad: No
+# CHECK-NEXT:         CanFallThrough: No
+# CHECK-NEXT:       }
+# CHECK-NEXT:       {
+# CHECK-NEXT:         ID: 2
+# CHECK-NEXT:         Offset: 0x1F
+# CHECK-NEXT:         Size: 0x6
+# CHECK-NEXT:         HasReturn: No
+# CHECK-NEXT:         HasTailCall: No
+# CHECK-NEXT:         IsEHPad: No
+# CHECK-NEXT:         CanFallThrough: Yes
+# CHECK-NEXT:       }
+# CHECK-NEXT:       {
+# CHECK-NEXT:         ID: 3
+# CHECK-NEXT:         Offset: 0x25
+# CHECK-NEXT:         Size: 0x5
+# CHECK-NEXT:         HasReturn: Yes
+# CHECK-NEXT:         HasTailCall: No
+# CHECK-NEXT:         IsEHPad: No
+# CHECK-NEXT:         CanFallThrough: No
+# CHECK-NEXT:       }
+# CHECK-NEXT:     ]
+# CHECK-NEXT:   }
+# CHECK-NEXT: ]
+
+--- !ELF
+FileHeader:
+  Class:           ELFCLASS64
+  Data:            ELFDATA2LSB
+  Type:            ET_REL
+  Machine:         EM_X86_64
+  SectionHeaderStringTable: .strtab
+Sections:
+  - Name:    .text
+    Type:    SHT_PROGBITS
+    Flags:   [ SHF_ALLOC, SHF_EXECINSTR ]
+  - Name:    .llvm_bb_addr_map
+    Type:    SHT_LLVM_BB_ADDR_MAP
+    Link:    .text
+    Entries:
+      - Version: 2
+        BBEntries:
+          - ID:              0
+            AddressOffset:   0x0
+            Size:            0xF
+            Metadata:        0x1
+      - Version: 2
+        BBEntries:
+          - ID:              0
+            AddressOffset:   0x0
+            Size:            0x11
+            Metadata:        0x8
+          - ID:              1
+            AddressOffset:   0x0
+            Size:            0xE
+            Metadata:        0x0
+          - ID:              2
+            AddressOffset:   0x0
+            Size:            0x6
+            Metadata:        0x8
+          - ID:              3
+            AddressOffset:   0x0
+            Size:            0x5
+            Metadata:        0x1
+  - Name:  .rela.llvm_bb_addr_map
+    Type:  SHT_RELA
+    Flags: [ SHF_INFO_LINK ]
+    Link:  .symtab
+    Info:  .llvm_bb_addr_map
+    Relocations:
+      - Offset: 0x2
+        Symbol: .text
+        Type:   R_X86_64_64
+      - Offset: 0x11
+        Symbol: .text
+        Type:   R_X86_64_64
+        Addend: 16
+Symbols:
+  - Name:    a
+    Section: .text
+    Value:   0x0
+  - Name:    c
+    Section: .text
+    Value:   0x10
+  - Name:    .text
+    Type:    STT_SECTION
+    Section: .text

diff  --git a/llvm/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumper.cpp
index 37394ae60572..0487cc9e123e 100644
--- a/llvm/tools/llvm-readobj/ELFDumper.cpp
+++ b/llvm/tools/llvm-readobj/ELFDumper.cpp
@@ -7093,20 +7093,26 @@ template <class ELFT> void LLVMELFDumper<ELFT>::printCGProfile() {
 
 template <class ELFT> void LLVMELFDumper<ELFT>::printBBAddrMaps() {
   bool IsRelocatable = this->Obj.getHeader().e_type == ELF::ET_REL;
-  for (const Elf_Shdr &Sec : cantFail(this->Obj.sections())) {
-    if (Sec.sh_type != SHT_LLVM_BB_ADDR_MAP &&
-        Sec.sh_type != SHT_LLVM_BB_ADDR_MAP_V0) {
-      continue;
-    }
+  using Elf_Shdr = typename ELFT::Shdr;
+  auto IsMatch = [&](const Elf_Shdr &Sec) -> bool {
+    return Sec.sh_type == ELF::SHT_LLVM_BB_ADDR_MAP ||
+           Sec.sh_type == ELF::SHT_LLVM_BB_ADDR_MAP_V0;
+  };
+  llvm::MapVector<const Elf_Shdr *, const Elf_Shdr *> Sections;
+  this->getSectionAndRelocations(IsMatch, Sections);
+  for (auto const& [Sec, RelocSec] : Sections) {
     std::optional<const Elf_Shdr *> FunctionSec;
     if (IsRelocatable)
       FunctionSec =
-          unwrapOrError(this->FileName, this->Obj.getSection(Sec.sh_link));
+          unwrapOrError(this->FileName, this->Obj.getSection(Sec->sh_link));
     ListScope L(W, "BBAddrMap");
+    std::optional<Elf_Shdr> RelaSec = {};
+    if(IsRelocatable)
+      RelaSec = *RelocSec;
     Expected<std::vector<BBAddrMap>> BBAddrMapOrErr =
-        this->Obj.decodeBBAddrMap(Sec);
+        this->Obj.decodeBBAddrMap(*Sec, RelaSec);
     if (!BBAddrMapOrErr) {
-      this->reportUniqueWarning("unable to dump " + this->describe(Sec) + ": " +
+      this->reportUniqueWarning("unable to dump " + this->describe(*Sec) + ": " +
                                 toString(BBAddrMapOrErr.takeError()));
       continue;
     }
@@ -7119,7 +7125,7 @@ template <class ELFT> void LLVMELFDumper<ELFT>::printBBAddrMaps() {
       if (FuncSymIndex.empty())
         this->reportUniqueWarning(
             "could not identify function symbol for address (0x" +
-            Twine::utohexstr(AM.Addr) + ") in " + this->describe(Sec));
+            Twine::utohexstr(AM.Addr) + ") in " + this->describe(*Sec));
       else
         FuncName = this->getStaticSymbolName(FuncSymIndex.front());
       W.printString("Name", FuncName);

diff  --git a/llvm/unittests/Object/ELFObjectFileTest.cpp b/llvm/unittests/Object/ELFObjectFileTest.cpp
index 99595eba0962..745f0cd717e8 100644
--- a/llvm/unittests/Object/ELFObjectFileTest.cpp
+++ b/llvm/unittests/Object/ELFObjectFileTest.cpp
@@ -720,9 +720,7 @@ TEST(ELFObjectFileTest, ReadBBAddrMap) {
 )";
 
   DoCheckFails(InvalidLinkedYamlString, /*TextSectionIndex=*/4,
-               "unable to get the linked-to section for "
-               "SHT_LLVM_BB_ADDR_MAP_V0 section with index 4: invalid section "
-               "index: 10");
+               "invalid section index: 10");
   // Linked sections are not checked when we don't target a specific text
   // section.
   DoCheckSucceeds(InvalidLinkedYamlString, /*TextSectionIndex=*/std::nullopt,


        


More information about the llvm-branch-commits mailing list