Skip to content

Commit 778d7c6

Browse files
committed
[SHT_LLVM_BB_ADDR_MAP] Deprecate SHT_LLVM_BB_ADDR_MAP versions 0 and 1.
1 parent ce00133 commit 778d7c6

File tree

13 files changed

+50
-294
lines changed

13 files changed

+50
-294
lines changed

llvm/include/llvm/BinaryFormat/ELF.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,9 +1034,6 @@ enum : unsigned {
10341034
SHT_LLVM_SYMPART = 0x6fff4c05, // Symbol partition specification.
10351035
SHT_LLVM_PART_EHDR = 0x6fff4c06, // ELF header for loadable partition.
10361036
SHT_LLVM_PART_PHDR = 0x6fff4c07, // Phdrs for loadable partition.
1037-
SHT_LLVM_BB_ADDR_MAP_V0 =
1038-
0x6fff4c08, // LLVM Basic Block Address Map (old version kept for
1039-
// backward-compatibility).
10401037
SHT_LLVM_CALL_GRAPH_PROFILE = 0x6fff4c09, // LLVM Call Graph Profile.
10411038
SHT_LLVM_BB_ADDR_MAP = 0x6fff4c0a, // LLVM Basic Block Address Map.
10421039
SHT_LLVM_OFFLOADING = 0x6fff4c0b, // LLVM device offloading data.

llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,16 +1376,12 @@ void AsmPrinter::emitBBAddrMapSection(const MachineFunction &MF) {
13761376
for (const MachineBasicBlock &MBB : MF) {
13771377
const MCSymbol *MBBSymbol =
13781378
MBB.isEntryBlock() ? FunctionSymbol : MBB.getSymbol();
1379-
// TODO: Remove this check when version 1 is deprecated.
1380-
if (BBAddrMapVersion > 1) {
1381-
OutStreamer->AddComment("BB id");
1382-
// Emit the BB ID for this basic block.
1383-
// We only emit BaseID since CloneID is unset for
1384-
// basic-block-sections=labels.
1385-
// TODO: Emit the full BBID when labels and sections can be mixed
1386-
// together.
1387-
OutStreamer->emitULEB128IntValue(MBB.getBBID()->BaseID);
1388-
}
1379+
OutStreamer->AddComment("BB id");
1380+
// Emit the BB ID for this basic block.
1381+
// We only emit BaseID since CloneID is unset for
1382+
// basic-block-sections=labels.
1383+
// TODO: Emit the full BBID when labels and sections can be mixed together.
1384+
OutStreamer->emitULEB128IntValue(MBB.getBBID()->BaseID);
13891385
// Emit the basic block offset relative to the end of the previous block.
13901386
// This is zero unless the block is padded due to alignment.
13911387
emitLabelDifferenceAsULEB128(MBBSymbol, PrevMBBEndSymbol);

llvm/lib/MC/MCSectionELF.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,6 @@ void MCSectionELF::printSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
168168
OS << "llvm_sympart";
169169
else if (Type == ELF::SHT_LLVM_BB_ADDR_MAP)
170170
OS << "llvm_bb_addr_map";
171-
else if (Type == ELF::SHT_LLVM_BB_ADDR_MAP_V0)
172-
OS << "llvm_bb_addr_map_v0";
173171
else if (Type == ELF::SHT_LLVM_OFFLOADING)
174172
OS << "llvm_offloading";
175173
else if (Type == ELF::SHT_LLVM_LTO)

llvm/lib/Object/ELF.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,6 @@ StringRef llvm::object::getELFSectionTypeName(uint32_t Machine, unsigned Type) {
310310
STRINGIFY_ENUM_CASE(ELF, SHT_LLVM_SYMPART);
311311
STRINGIFY_ENUM_CASE(ELF, SHT_LLVM_PART_EHDR);
312312
STRINGIFY_ENUM_CASE(ELF, SHT_LLVM_PART_PHDR);
313-
STRINGIFY_ENUM_CASE(ELF, SHT_LLVM_BB_ADDR_MAP_V0);
314313
STRINGIFY_ENUM_CASE(ELF, SHT_LLVM_BB_ADDR_MAP);
315314
STRINGIFY_ENUM_CASE(ELF, SHT_LLVM_OFFLOADING);
316315
STRINGIFY_ENUM_CASE(ELF, SHT_LLVM_LTO);
@@ -703,9 +702,11 @@ ELFFile<ELFT>::decodeBBAddrMap(const Elf_Shdr &Sec,
703702
Version = Data.getU8(Cur);
704703
if (!Cur)
705704
break;
706-
if (Version > 2)
707-
return createError("unsupported SHT_LLVM_BB_ADDR_MAP version: " +
705+
if (Version != 2) {
706+
return createError(Twine((Version < 2 ? "deprecated" : "unsupported")) +
707+
" SHT_LLVM_BB_ADDR_MAP version: " +
708708
Twine(static_cast<int>(Version)));
709+
}
709710
Data.getU8(Cur); // Feature byte
710711
}
711712
uint64_t SectionOffset = Cur.tell();
@@ -728,15 +729,13 @@ ELFFile<ELFT>::decodeBBAddrMap(const Elf_Shdr &Sec,
728729
for (uint32_t BlockIndex = 0;
729730
!MetadataDecodeErr && !ULEBSizeErr && Cur && (BlockIndex < NumBlocks);
730731
++BlockIndex) {
731-
uint32_t ID = Version >= 2 ? ReadULEB128AsUInt32() : BlockIndex;
732+
uint32_t ID = ReadULEB128AsUInt32();
732733
uint32_t Offset = ReadULEB128AsUInt32();
733734
uint32_t Size = ReadULEB128AsUInt32();
734735
uint32_t MD = ReadULEB128AsUInt32();
735-
if (Version >= 1) {
736-
// Offset is calculated relative to the end of the previous BB.
737-
Offset += PrevBBEndOffset;
738-
PrevBBEndOffset = Offset + Size;
739-
}
736+
// Offset is calculated relative to the end of the previous BB.
737+
Offset += PrevBBEndOffset;
738+
PrevBBEndOffset = Offset + Size;
740739
Expected<BBAddrMap::BBEntry::Metadata> MetadataOrErr =
741740
BBAddrMap::BBEntry::Metadata::decode(MD);
742741
if (!MetadataOrErr) {

llvm/lib/Object/ELFObjectFile.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -723,8 +723,7 @@ Expected<std::vector<BBAddrMap>> static readBBAddrMapImpl(
723723

724724
const auto &Sections = cantFail(EF.sections());
725725
auto IsMatch = [&](const Elf_Shdr &Sec) -> Expected<bool> {
726-
if (Sec.sh_type != ELF::SHT_LLVM_BB_ADDR_MAP &&
727-
Sec.sh_type != ELF::SHT_LLVM_BB_ADDR_MAP_V0)
726+
if (Sec.sh_type != ELF::SHT_LLVM_BB_ADDR_MAP)
728727
return false;
729728
if (!TextSectionIndex)
730729
return true;

llvm/lib/ObjectYAML/ELFEmitter.cpp

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1395,31 +1395,29 @@ void ELFState<ELFT>::writeSectionContent(
13951395

13961396
for (const ELFYAML::BBAddrMapEntry &E : *Section.Entries) {
13971397
// Write version and feature values.
1398-
if (Section.Type == llvm::ELF::SHT_LLVM_BB_ADDR_MAP) {
1399-
if (E.Version > 2)
1400-
WithColor::warning() << "unsupported SHT_LLVM_BB_ADDR_MAP version: "
1401-
<< static_cast<int>(E.Version)
1402-
<< "; encoding using the most recent version";
1403-
CBA.write(E.Version);
1404-
CBA.write(E.Feature);
1405-
SHeader.sh_size += 2;
1398+
if (E.Version != 2) {
1399+
WithColor::warning() << (E.Version < 2 ? "deprecated" : "unsupported")
1400+
<< " SHT_LLVM_BB_ADDR_MAP version: "
1401+
<< static_cast<int>(E.Version)
1402+
<< "; encoding using the most recent version";
14061403
}
1404+
CBA.write(E.Version);
1405+
CBA.write(E.Feature);
1406+
SHeader.sh_size += 2;
14071407
// Write the address of the function.
14081408
CBA.write<uintX_t>(E.Address, ELFT::TargetEndianness);
1409-
// Write number of BBEntries (number of basic blocks in the function). This
1410-
// is overridden by the 'NumBlocks' YAML field when specified.
1409+
// Write number of BBEntries (number of basic blocks in the function).
1410+
// This is overridden by the 'NumBlocks' YAML field when specified.
14111411
uint64_t NumBlocks =
14121412
E.NumBlocks.value_or(E.BBEntries ? E.BBEntries->size() : 0);
14131413
SHeader.sh_size += sizeof(uintX_t) + CBA.writeULEB128(NumBlocks);
14141414
// Write all BBEntries.
14151415
if (!E.BBEntries)
14161416
continue;
14171417
for (const ELFYAML::BBAddrMapEntry::BBEntry &BBE : *E.BBEntries) {
1418-
if (Section.Type == llvm::ELF::SHT_LLVM_BB_ADDR_MAP && E.Version > 1)
1419-
SHeader.sh_size += CBA.writeULEB128(BBE.ID);
1420-
SHeader.sh_size += CBA.writeULEB128(BBE.AddressOffset) +
1421-
CBA.writeULEB128(BBE.Size) +
1422-
CBA.writeULEB128(BBE.Metadata);
1418+
SHeader.sh_size +=
1419+
CBA.writeULEB128(BBE.ID) + CBA.writeULEB128(BBE.AddressOffset) +
1420+
CBA.writeULEB128(BBE.Size) + CBA.writeULEB128(BBE.Metadata);
14231421
}
14241422
}
14251423
}

llvm/lib/ObjectYAML/ELFYAML.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,6 @@ void ScalarEnumerationTraits<ELFYAML::ELF_SHT>::enumeration(
683683
ECase(SHT_LLVM_SYMPART);
684684
ECase(SHT_LLVM_PART_EHDR);
685685
ECase(SHT_LLVM_PART_PHDR);
686-
ECase(SHT_LLVM_BB_ADDR_MAP_V0);
687686
ECase(SHT_LLVM_BB_ADDR_MAP);
688687
ECase(SHT_LLVM_OFFLOADING);
689688
ECase(SHT_LLVM_LTO);
@@ -1678,7 +1677,6 @@ void MappingTraits<std::unique_ptr<ELFYAML::Chunk>>::mapping(
16781677
Section.reset(new ELFYAML::CallGraphProfileSection());
16791678
sectionMapping(IO, *cast<ELFYAML::CallGraphProfileSection>(Section.get()));
16801679
break;
1681-
case ELF::SHT_LLVM_BB_ADDR_MAP_V0:
16821680
case ELF::SHT_LLVM_BB_ADDR_MAP:
16831681
if (!IO.outputting())
16841682
Section.reset(new ELFYAML::BBAddrMapSection());

llvm/test/tools/llvm-objdump/X86/elf-bbaddrmap-disassemble-symbolize-operands.yaml

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,6 @@
3030
# ATT-NEXT: jmp <BB1>
3131
# ATT-NEXT: <BB5>:
3232
# ATT-NEXT: retq
33-
# ATT: <bar>:
34-
# ATT-NEXT: <BB0>:
35-
# ATT-NEXT: pushq %rax
36-
# ATT-NEXT: movl %edx, %eax
37-
# ATT-NEXT: je <BB2>
38-
# ATT-NEXT: <BB1>:
39-
# ATT-NEXT: xorl %esi, %esi
40-
# ATT-NEXT: <BB2>:
41-
# ATT-NEXT: callq <bar>
42-
# ATT-NEXT: retq
4333

4434
# INTEL: <foo>:
4535
# INTEL-NEXT: <BB3>:
@@ -52,16 +42,6 @@
5242
# INTEL-NEXT: jmp <BB1>
5343
# INTEL-NEXT: <BB5>:
5444
# INTEL-NEXT: ret
55-
# INTEL: <bar>:
56-
# INTEL-NEXT: <BB0>:
57-
# INTEL-NEXT: push rax
58-
# INTEL-NEXT: mov eax, edx
59-
# INTEL-NEXT: je <BB2>
60-
# INTEL-NEXT: <BB1>:
61-
# INTEL-NEXT: xor esi, esi
62-
# INTEL-NEXT: <BB2>:
63-
# INTEL-NEXT: call <bar>
64-
# INTEL-NEXT: ret
6545

6646
## This object file contains a separate text section and SHT_LLVM_BB_ADDR_MAP
6747
## section for each of the two functions foo and bar.
@@ -111,30 +91,11 @@ Sections:
11191
AddressOffset: 0x0
11292
Size: 0x1
11393
Metadata: 0x2
114-
- Name: .llvm_bb_addr_map.bar
115-
Type: SHT_LLVM_BB_ADDR_MAP
116-
Link: .text.bar
117-
Entries:
118-
- Version: 1
119-
Address: [[BAR_ADDR]]
120-
BBEntries:
121-
- AddressOffset: 0x0
122-
Size: 0x1
123-
Metadata: 0x1
124-
- AddressOffset: 0x4
125-
Size: 0x2
126-
Metadata: 0x0
127-
- AddressOffset: 0x0
128-
Size: 0x6
129-
Metadata: 0x0
13094

13195
Symbols:
13296
- Name: foo
13397
Section: .text.foo
13498
Value: [[FOO_ADDR]]
135-
- Name: bar
136-
Section: .text.bar
137-
Value: [[BAR_ADDR]]
13899
- Name: symbol
139100
Section: .data
140101
Value: 0x600c
@@ -153,11 +114,6 @@ Sections:
153114
Address: 0x4000
154115
Flags: [SHF_ALLOC, SHF_EXECINSTR]
155116
Content: '503b0505200000907d02ebf5c3'
156-
- Name: .text.bar
157-
Type: SHT_PROGBITS
158-
Address: 0x5000
159-
Flags: [SHF_ALLOC, SHF_EXECINSTR]
160-
Content: '5089d0740231f6e8f4ffffffc3'
161117
- Name: .data
162118
Type: SHT_PROGBITS
163119
Flags: [SHF_ALLOC, SHF_WRITE]
@@ -185,26 +141,11 @@ Sections:
185141
AddressOffset: 0x0
186142
Size: 0x1
187143
Metadata: 0x2
188-
- Version: 1
189-
Address: 0x5000
190-
BBEntries:
191-
- AddressOffset: 0x0
192-
Size: 0x1
193-
Metadata: 0x1
194-
- AddressOffset: 0x4
195-
Size: 0x2
196-
Metadata: 0x0
197-
- AddressOffset: 0x0
198-
Size: 0x6
199-
Metadata: 0x0
200144

201145
Symbols:
202146
- Name: foo
203147
Section: .text.foo
204148
Value: 0x4000
205-
- Name: bar
206-
Section: .text.bar
207-
Value: 0x5000
208149
- Name: symbol
209150
Section: .data
210151
Value: 0x600c

llvm/test/tools/llvm-readobj/ELF/bb-addr-map.test

Lines changed: 0 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -171,103 +171,3 @@ Symbols:
171171
Section: .text.bar
172172
Type: STT_FUNC
173173
Value: 0x33333
174-
175-
## Check that using the SHT_LLVM_BB_ADDR_MAP_V0 section type generates the same
176-
## result as using the SHT_LLVM_BB_ADDR_MAP section type with Version=0.
177-
## The Version field is required even for SHT_LLVM_BB_ADDR_MAP_V0 but it
178-
## should not impact the result. This unideal behavior will be gone once
179-
## SHT_LLVM_BB_ADDR_MAP_V0 is deprecated.
180-
181-
# RUN: yaml2obj --docnum=2 %s -DVERSION=255 -DSECTION_TYPE=SHT_LLVM_BB_ADDR_MAP_V0 -o %t2.type0
182-
# RUN: llvm-readobj %t2.type0 --bb-addr-map 2>&1 | FileCheck %s --check-prefix=V0
183-
184-
# RUN: yaml2obj --docnum=2 %s -DVERSION=0 -DSECTION_TYPE=SHT_LLVM_BB_ADDR_MAP -o %t2.version0
185-
# RUN: llvm-readobj %t2.version0 --bb-addr-map 2>&1 | FileCheck %s --check-prefix=V0
186-
187-
# V0: BBAddrMap [
188-
# V0-NEXT: Function {
189-
# V0-NEXT: At: 0x11111
190-
# V0-NEXT: Name: foo
191-
# V0-NEXT: BB entries [
192-
# V0-NEXT: {
193-
# V0-NEXT: ID: 0
194-
# V0-NEXT: Offset: 0x1
195-
# V0-NEXT: Size: 0x2
196-
# V0-NEXT: HasReturn:
197-
# V0-NEXT: HasTailCall:
198-
# V0-NEXT: IsEHPad:
199-
# V0-NEXT: CanFallThrough:
200-
# V0-NEXT: HasIndirectBranch:
201-
# V0-NEXT: }
202-
# V0-NEXT: {
203-
# V0-NEXT: ID: 1
204-
# V0-NEXT: Offset: 0x4
205-
# V0-NEXT: Size: 0x5
206-
# V0-NEXT: HasReturn:
207-
# V0-NEXT: HasTailCall:
208-
# V0-NEXT: IsEHPad:
209-
# V0-NEXT: CanFallThrough:
210-
# V0-NEXT: HasIndirectBranch:
211-
# V0-NEXT: }
212-
# V0-NEXT: ]
213-
# V0-NEXT: }
214-
215-
## Check version 1 (without BB IDs).
216-
# RUN: yaml2obj --docnum=2 %s -DVERSION=1 -DSECTION_TYPE=SHT_LLVM_BB_ADDR_MAP -o %t3
217-
# RUN: llvm-readobj %t3 --bb-addr-map 2>&1 | FileCheck %s --check-prefix=V1
218-
219-
# V1: BBAddrMap [
220-
# V1-NEXT: Function {
221-
# V1-NEXT: At: 0x11111
222-
# V1-NEXT: Name: foo
223-
# V1-NEXT: BB entries [
224-
# V1-NEXT: {
225-
# V1-NEXT: ID: 0
226-
# V1-NEXT: Offset: 0x1
227-
# V1-NEXT: Size: 0x2
228-
# V1-NEXT: HasReturn:
229-
# V1-NEXT: HasTailCall:
230-
# V1-NEXT: IsEHPad:
231-
# V1-NEXT: CanFallThrough:
232-
# V1-NEXT: HasIndirectBranch:
233-
# V1-NEXT: }
234-
# V1-NEXT: {
235-
# V1-NEXT: ID: 1
236-
# V1-NEXT: Offset: 0x7
237-
# V1-NEXT: Size: 0x5
238-
# V1-NEXT: HasReturn:
239-
# V1-NEXT: HasTailCall:
240-
# V1-NEXT: IsEHPad:
241-
# V1-NEXT: CanFallThrough:
242-
# V1-NEXT: HasIndirectBranch:
243-
# V1-NEXT: }
244-
# V1-NEXT: ]
245-
# V1-NEXT: }
246-
247-
--- !ELF
248-
FileHeader:
249-
Class: ELFCLASS64
250-
Data: ELFDATA2LSB
251-
Type: ET_EXEC
252-
Sections:
253-
- Name: .text.foo
254-
Type: SHT_PROGBITS
255-
Flags: [SHF_ALLOC]
256-
- Name: .llvm_bb_addr_map
257-
Type: [[SECTION_TYPE]]
258-
Link: .text.foo
259-
Entries:
260-
- Version: [[VERSION]]
261-
Address: 0x11111
262-
BBEntries:
263-
- AddressOffset: 0x1
264-
Size: 0x2
265-
Metadata: 0x3
266-
- AddressOffset: 0x4
267-
Size: 0x5
268-
Metadata: 0x6
269-
Symbols:
270-
- Name: foo
271-
Section: .text.foo
272-
Type: STT_FUNC
273-
Value: 0x11111

0 commit comments

Comments
 (0)