Skip to content

[SHT_LLVM_BB_ADDR_MAP] Deprecate SHT_LLVM_BB_ADDR_MAP versions 0 and 1. #74107

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions llvm/include/llvm/BinaryFormat/ELF.h
Original file line number Diff line number Diff line change
Expand Up @@ -1034,9 +1034,6 @@ enum : unsigned {
SHT_LLVM_SYMPART = 0x6fff4c05, // Symbol partition specification.
SHT_LLVM_PART_EHDR = 0x6fff4c06, // ELF header for loadable partition.
SHT_LLVM_PART_PHDR = 0x6fff4c07, // Phdrs for loadable partition.
SHT_LLVM_BB_ADDR_MAP_V0 =
0x6fff4c08, // LLVM Basic Block Address Map (old version kept for
// backward-compatibility).
SHT_LLVM_CALL_GRAPH_PROFILE = 0x6fff4c09, // LLVM Call Graph Profile.
SHT_LLVM_BB_ADDR_MAP = 0x6fff4c0a, // LLVM Basic Block Address Map.
SHT_LLVM_OFFLOADING = 0x6fff4c0b, // LLVM device offloading data.
Expand Down
16 changes: 6 additions & 10 deletions llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1376,16 +1376,12 @@ void AsmPrinter::emitBBAddrMapSection(const MachineFunction &MF) {
for (const MachineBasicBlock &MBB : MF) {
const MCSymbol *MBBSymbol =
MBB.isEntryBlock() ? FunctionSymbol : MBB.getSymbol();
// TODO: Remove this check when version 1 is deprecated.
if (BBAddrMapVersion > 1) {
OutStreamer->AddComment("BB id");
// Emit the BB ID for this basic block.
// We only emit BaseID since CloneID is unset for
// basic-block-sections=labels.
// TODO: Emit the full BBID when labels and sections can be mixed
// together.
OutStreamer->emitULEB128IntValue(MBB.getBBID()->BaseID);
}
OutStreamer->AddComment("BB id");
// Emit the BB ID for this basic block.
// We only emit BaseID since CloneID is unset for
// basic-block-sections=labels.
// TODO: Emit the full BBID when labels and sections can be mixed together.
OutStreamer->emitULEB128IntValue(MBB.getBBID()->BaseID);
// Emit the basic block offset relative to the end of the previous block.
// This is zero unless the block is padded due to alignment.
emitLabelDifferenceAsULEB128(MBBSymbol, PrevMBBEndSymbol);
Expand Down
2 changes: 0 additions & 2 deletions llvm/lib/MC/MCSectionELF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,6 @@ void MCSectionELF::printSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
OS << "llvm_sympart";
else if (Type == ELF::SHT_LLVM_BB_ADDR_MAP)
OS << "llvm_bb_addr_map";
else if (Type == ELF::SHT_LLVM_BB_ADDR_MAP_V0)
OS << "llvm_bb_addr_map_v0";
else if (Type == ELF::SHT_LLVM_OFFLOADING)
OS << "llvm_offloading";
else if (Type == ELF::SHT_LLVM_LTO)
Expand Down
17 changes: 8 additions & 9 deletions llvm/lib/Object/ELF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,6 @@ StringRef llvm::object::getELFSectionTypeName(uint32_t Machine, unsigned Type) {
STRINGIFY_ENUM_CASE(ELF, SHT_LLVM_SYMPART);
STRINGIFY_ENUM_CASE(ELF, SHT_LLVM_PART_EHDR);
STRINGIFY_ENUM_CASE(ELF, SHT_LLVM_PART_PHDR);
STRINGIFY_ENUM_CASE(ELF, SHT_LLVM_BB_ADDR_MAP_V0);
STRINGIFY_ENUM_CASE(ELF, SHT_LLVM_BB_ADDR_MAP);
STRINGIFY_ENUM_CASE(ELF, SHT_LLVM_OFFLOADING);
STRINGIFY_ENUM_CASE(ELF, SHT_LLVM_LTO);
Expand Down Expand Up @@ -703,9 +702,11 @@ ELFFile<ELFT>::decodeBBAddrMap(const Elf_Shdr &Sec,
Version = Data.getU8(Cur);
if (!Cur)
break;
if (Version > 2)
return createError("unsupported SHT_LLVM_BB_ADDR_MAP version: " +
if (Version != 2) {
return createError(Twine((Version < 2 ? "deprecated" : "unsupported")) +
" SHT_LLVM_BB_ADDR_MAP version: " +
Twine(static_cast<int>(Version)));
}
Data.getU8(Cur); // Feature byte
}
uint64_t SectionOffset = Cur.tell();
Expand All @@ -728,15 +729,13 @@ ELFFile<ELFT>::decodeBBAddrMap(const Elf_Shdr &Sec,
for (uint32_t BlockIndex = 0;
!MetadataDecodeErr && !ULEBSizeErr && Cur && (BlockIndex < NumBlocks);
++BlockIndex) {
uint32_t ID = Version >= 2 ? ReadULEB128AsUInt32() : BlockIndex;
uint32_t ID = ReadULEB128AsUInt32();
uint32_t Offset = ReadULEB128AsUInt32();
uint32_t Size = ReadULEB128AsUInt32();
uint32_t MD = ReadULEB128AsUInt32();
if (Version >= 1) {
// Offset is calculated relative to the end of the previous BB.
Offset += PrevBBEndOffset;
PrevBBEndOffset = Offset + Size;
}
// Offset is calculated relative to the end of the previous BB.
Offset += PrevBBEndOffset;
PrevBBEndOffset = Offset + Size;
Expected<BBAddrMap::BBEntry::Metadata> MetadataOrErr =
BBAddrMap::BBEntry::Metadata::decode(MD);
if (!MetadataOrErr) {
Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/Object/ELFObjectFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -723,8 +723,7 @@ Expected<std::vector<BBAddrMap>> static readBBAddrMapImpl(

const auto &Sections = cantFail(EF.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)
if (Sec.sh_type != ELF::SHT_LLVM_BB_ADDR_MAP)
return false;
if (!TextSectionIndex)
return true;
Expand Down
28 changes: 13 additions & 15 deletions llvm/lib/ObjectYAML/ELFEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1395,31 +1395,29 @@ void ELFState<ELFT>::writeSectionContent(

for (const ELFYAML::BBAddrMapEntry &E : *Section.Entries) {
// Write version and feature values.
if (Section.Type == llvm::ELF::SHT_LLVM_BB_ADDR_MAP) {
if (E.Version > 2)
WithColor::warning() << "unsupported SHT_LLVM_BB_ADDR_MAP version: "
<< static_cast<int>(E.Version)
<< "; encoding using the most recent version";
CBA.write(E.Version);
CBA.write(E.Feature);
SHeader.sh_size += 2;
if (E.Version != 2) {
WithColor::warning() << (E.Version < 2 ? "deprecated" : "unsupported")
<< " SHT_LLVM_BB_ADDR_MAP version: "
<< static_cast<int>(E.Version)
<< "; encoding using the most recent version";
}
CBA.write(E.Version);
CBA.write(E.Feature);
SHeader.sh_size += 2;
// Write the address of the function.
CBA.write<uintX_t>(E.Address, ELFT::TargetEndianness);
// Write number of BBEntries (number of basic blocks in the function). This
// is overridden by the 'NumBlocks' YAML field when specified.
// Write number of BBEntries (number of basic blocks in the function).
// This is overridden by the 'NumBlocks' YAML field when specified.
uint64_t NumBlocks =
E.NumBlocks.value_or(E.BBEntries ? E.BBEntries->size() : 0);
SHeader.sh_size += sizeof(uintX_t) + CBA.writeULEB128(NumBlocks);
// Write all BBEntries.
if (!E.BBEntries)
continue;
for (const ELFYAML::BBAddrMapEntry::BBEntry &BBE : *E.BBEntries) {
if (Section.Type == llvm::ELF::SHT_LLVM_BB_ADDR_MAP && E.Version > 1)
SHeader.sh_size += CBA.writeULEB128(BBE.ID);
SHeader.sh_size += CBA.writeULEB128(BBE.AddressOffset) +
CBA.writeULEB128(BBE.Size) +
CBA.writeULEB128(BBE.Metadata);
SHeader.sh_size +=
CBA.writeULEB128(BBE.ID) + CBA.writeULEB128(BBE.AddressOffset) +
CBA.writeULEB128(BBE.Size) + CBA.writeULEB128(BBE.Metadata);
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions llvm/lib/ObjectYAML/ELFYAML.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,6 @@ void ScalarEnumerationTraits<ELFYAML::ELF_SHT>::enumeration(
ECase(SHT_LLVM_SYMPART);
ECase(SHT_LLVM_PART_EHDR);
ECase(SHT_LLVM_PART_PHDR);
ECase(SHT_LLVM_BB_ADDR_MAP_V0);
ECase(SHT_LLVM_BB_ADDR_MAP);
ECase(SHT_LLVM_OFFLOADING);
ECase(SHT_LLVM_LTO);
Expand Down Expand Up @@ -1678,7 +1677,6 @@ void MappingTraits<std::unique_ptr<ELFYAML::Chunk>>::mapping(
Section.reset(new ELFYAML::CallGraphProfileSection());
sectionMapping(IO, *cast<ELFYAML::CallGraphProfileSection>(Section.get()));
break;
case ELF::SHT_LLVM_BB_ADDR_MAP_V0:
case ELF::SHT_LLVM_BB_ADDR_MAP:
if (!IO.outputting())
Section.reset(new ELFYAML::BBAddrMapSection());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,6 @@
# ATT-NEXT: jmp <BB1>
# ATT-NEXT: <BB5>:
# ATT-NEXT: retq
# ATT: <bar>:
# ATT-NEXT: <BB0>:
# ATT-NEXT: pushq %rax
# ATT-NEXT: movl %edx, %eax
# ATT-NEXT: je <BB2>
# ATT-NEXT: <BB1>:
# ATT-NEXT: xorl %esi, %esi
# ATT-NEXT: <BB2>:
# ATT-NEXT: callq <bar>
# ATT-NEXT: retq

# INTEL: <foo>:
# INTEL-NEXT: <BB3>:
Expand All @@ -52,16 +42,6 @@
# INTEL-NEXT: jmp <BB1>
# INTEL-NEXT: <BB5>:
# INTEL-NEXT: ret
# INTEL: <bar>:
# INTEL-NEXT: <BB0>:
# INTEL-NEXT: push rax
# INTEL-NEXT: mov eax, edx
# INTEL-NEXT: je <BB2>
# INTEL-NEXT: <BB1>:
# INTEL-NEXT: xor esi, esi
# INTEL-NEXT: <BB2>:
# INTEL-NEXT: call <bar>
# INTEL-NEXT: ret

## This object file contains a separate text section and SHT_LLVM_BB_ADDR_MAP
## section for each of the two functions foo and bar.
Expand Down Expand Up @@ -111,30 +91,11 @@ Sections:
AddressOffset: 0x0
Size: 0x1
Metadata: 0x2
- Name: .llvm_bb_addr_map.bar
Type: SHT_LLVM_BB_ADDR_MAP
Link: .text.bar
Entries:
- Version: 1
Address: [[BAR_ADDR]]
BBEntries:
- AddressOffset: 0x0
Size: 0x1
Metadata: 0x1
- AddressOffset: 0x4
Size: 0x2
Metadata: 0x0
- AddressOffset: 0x0
Size: 0x6
Metadata: 0x0

Symbols:
- Name: foo
Section: .text.foo
Value: [[FOO_ADDR]]
- Name: bar
Section: .text.bar
Value: [[BAR_ADDR]]
- Name: symbol
Section: .data
Value: 0x600c
Expand All @@ -153,11 +114,6 @@ Sections:
Address: 0x4000
Flags: [SHF_ALLOC, SHF_EXECINSTR]
Content: '503b0505200000907d02ebf5c3'
- Name: .text.bar
Type: SHT_PROGBITS
Address: 0x5000
Flags: [SHF_ALLOC, SHF_EXECINSTR]
Content: '5089d0740231f6e8f4ffffffc3'
- Name: .data
Type: SHT_PROGBITS
Flags: [SHF_ALLOC, SHF_WRITE]
Expand Down Expand Up @@ -185,26 +141,11 @@ Sections:
AddressOffset: 0x0
Size: 0x1
Metadata: 0x2
- Version: 1
Address: 0x5000
BBEntries:
- AddressOffset: 0x0
Size: 0x1
Metadata: 0x1
- AddressOffset: 0x4
Size: 0x2
Metadata: 0x0
- AddressOffset: 0x0
Size: 0x6
Metadata: 0x0

Symbols:
- Name: foo
Section: .text.foo
Value: 0x4000
- Name: bar
Section: .text.bar
Value: 0x5000
- Name: symbol
Section: .data
Value: 0x600c
100 changes: 0 additions & 100 deletions llvm/test/tools/llvm-readobj/ELF/bb-addr-map.test
Original file line number Diff line number Diff line change
Expand Up @@ -171,103 +171,3 @@ Symbols:
Section: .text.bar
Type: STT_FUNC
Value: 0x33333

## Check that using the SHT_LLVM_BB_ADDR_MAP_V0 section type generates the same
## result as using the SHT_LLVM_BB_ADDR_MAP section type with Version=0.
## The Version field is required even for SHT_LLVM_BB_ADDR_MAP_V0 but it
## should not impact the result. This unideal behavior will be gone once
## SHT_LLVM_BB_ADDR_MAP_V0 is deprecated.

# RUN: yaml2obj --docnum=2 %s -DVERSION=255 -DSECTION_TYPE=SHT_LLVM_BB_ADDR_MAP_V0 -o %t2.type0
# RUN: llvm-readobj %t2.type0 --bb-addr-map 2>&1 | FileCheck %s --check-prefix=V0

# RUN: yaml2obj --docnum=2 %s -DVERSION=0 -DSECTION_TYPE=SHT_LLVM_BB_ADDR_MAP -o %t2.version0
# RUN: llvm-readobj %t2.version0 --bb-addr-map 2>&1 | FileCheck %s --check-prefix=V0

# V0: BBAddrMap [
# V0-NEXT: Function {
# V0-NEXT: At: 0x11111
# V0-NEXT: Name: foo
# V0-NEXT: BB entries [
# V0-NEXT: {
# V0-NEXT: ID: 0
# V0-NEXT: Offset: 0x1
# V0-NEXT: Size: 0x2
# V0-NEXT: HasReturn:
# V0-NEXT: HasTailCall:
# V0-NEXT: IsEHPad:
# V0-NEXT: CanFallThrough:
# V0-NEXT: HasIndirectBranch:
# V0-NEXT: }
# V0-NEXT: {
# V0-NEXT: ID: 1
# V0-NEXT: Offset: 0x4
# V0-NEXT: Size: 0x5
# V0-NEXT: HasReturn:
# V0-NEXT: HasTailCall:
# V0-NEXT: IsEHPad:
# V0-NEXT: CanFallThrough:
# V0-NEXT: HasIndirectBranch:
# V0-NEXT: }
# V0-NEXT: ]
# V0-NEXT: }

## Check version 1 (without BB IDs).
# RUN: yaml2obj --docnum=2 %s -DVERSION=1 -DSECTION_TYPE=SHT_LLVM_BB_ADDR_MAP -o %t3
# RUN: llvm-readobj %t3 --bb-addr-map 2>&1 | FileCheck %s --check-prefix=V1

# V1: BBAddrMap [
# V1-NEXT: Function {
# V1-NEXT: At: 0x11111
# V1-NEXT: Name: foo
# V1-NEXT: BB entries [
# V1-NEXT: {
# V1-NEXT: ID: 0
# V1-NEXT: Offset: 0x1
# V1-NEXT: Size: 0x2
# V1-NEXT: HasReturn:
# V1-NEXT: HasTailCall:
# V1-NEXT: IsEHPad:
# V1-NEXT: CanFallThrough:
# V1-NEXT: HasIndirectBranch:
# V1-NEXT: }
# V1-NEXT: {
# V1-NEXT: ID: 1
# V1-NEXT: Offset: 0x7
# V1-NEXT: Size: 0x5
# V1-NEXT: HasReturn:
# V1-NEXT: HasTailCall:
# V1-NEXT: IsEHPad:
# V1-NEXT: CanFallThrough:
# V1-NEXT: HasIndirectBranch:
# V1-NEXT: }
# V1-NEXT: ]
# V1-NEXT: }

--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_EXEC
Sections:
- Name: .text.foo
Type: SHT_PROGBITS
Flags: [SHF_ALLOC]
- Name: .llvm_bb_addr_map
Type: [[SECTION_TYPE]]
Link: .text.foo
Entries:
- Version: [[VERSION]]
Address: 0x11111
BBEntries:
- AddressOffset: 0x1
Size: 0x2
Metadata: 0x3
- AddressOffset: 0x4
Size: 0x5
Metadata: 0x6
Symbols:
- Name: foo
Section: .text.foo
Type: STT_FUNC
Value: 0x11111
Loading