Today `-split-machine-functions` and `-fbasic-block-sections={all,list}`
cannot be combined with `-basic-block-sections=labels` (the labels
option will be ignored).
The inconsistency comes from the way basic block address map -- the
underlying mechanism for basic block labels -- encodes basic block
addresses
(https://lists.llvm.org/pipermail/llvm-dev/2020-July/143512.html).
Specifically, basic block offsets are computed relative to the function
begin symbol. This relies on functions being contiguous which is not the
case for MFS and basic block section binaries. This means Propeller
cannot use binary profiles collected from these binaries, which limits
the applicability of Propeller for iterative optimization.
To make the `SHT_LLVM_BB_ADDR_MAP` feature work with basic block section
binaries, we propose modifying the encoding of this section as follows.
First let us review the current encoding which emits the address of each
function and its number of basic blocks, followed by basic block entries
for each basic block.
| | |
|--|--|
| Address of the function | Function Address |
| Number of basic blocks in this function | NumBlocks |
| BB entry 1
| BB entry 2
| ...
| BB entry #NumBlocks
To make this work for basic block sections, we treat each basic block
section similar to a function, except that basic block sections of the
same function must be encapsulated in the same structure so we can map
all of them to their single function.
We modify the encoding to first emit the number of basic block sections
(BB ranges) in the function. Then we emit the address map of each basic
block section section as before: the base address of the section, its
number of blocks, and BB entries for its basic block. The first section
in the BB address map is always the function entry section.
| | |
|--|--|
| Number of sections for this function | NumBBRanges |
| Section 1 begin address | BaseAddress[1] |
| Number of basic blocks in section 1 | NumBlocks[1] |
| BB entries for Section 1
|..................|
| Section #NumBBRanges begin address | BaseAddress[NumBBRanges] |
| Number of basic blocks in section #NumBBRanges |
NumBlocks[NumBBRanges] |
| BB entries for Section #NumBBRanges
The encoding of basic block entries remains as before with the minor
change that each basic block offset is now computed relative to the
begin symbol of its containing BB section.
This patch adds a new boolean codegen option `-basic-block-address-map`.
Correspondingly, the front-end flag `-fbasic-block-address-map` and LLD
flag `--lto-basic-block-address-map` are introduced.
Analogously, we add a new TargetOption field `BBAddrMap`. This means BB
address maps are either generated for all functions in the compiling
unit, or for none (depending on `TargetOptions::BBAddrMap`).
This patch keeps the functionality of the old
`-fbasic-block-sections=labels` option but does not remove it. A
subsequent patch will remove the obsolete option.
We refactor the `BasicBlockSections` pass by separating the BB address
map and BB sections handing to their own functions (named
`handleBBAddrMap` and `handleBBSections`). `handleBBSections` renumbers
basic blocks and places them in their assigned sections.
`handleBBAddrMap` is invoked after `handleBBSections` (if requested) and
only renumbers the blocks.
- New tests added:
- Two tests basic-block-address-map-with-basic-block-sections.ll and
basic-block-address-map-with-mfs.ll to exercise the combination of
`-basic-block-address-map` with `-basic-block-sections=list` and
'-split-machine-functions`.
- A driver sanity test for the `-fbasic-block-address-map` option
(basic-block-address-map.c).
- An LLD test for testing the `--lto-basic-block-address-map` option.
This reuses the LLVM IR from `lld/test/ELF/lto/basic-block-sections.ll`.
- Renamed and modified the two existing codegen tests for basic block
address map (`basic-block-sections-labels-functions-sections.ll` and
`basic-block-sections-labels.ll`)
- Removed `SHT_LLVM_BB_ADDR_MAP_V0` tests. Full deprecation of
`SHT_LLVM_BB_ADDR_MAP_V0` and `SHT_LLVM_BB_ADDR_MAP` version less than 2
will happen in a separate PR in a few months.
231 lines
6.9 KiB
Plaintext
231 lines
6.9 KiB
Plaintext
## This test checks how we handle the --bb-addr-map option on relocatable
|
|
## object files.
|
|
|
|
# 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 Ranges [
|
|
# CHECK-NEXT: {
|
|
# CHECK-NEXT: Base Address: 0x0
|
|
# 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: HasIndirectBranch: No
|
|
# CHECK-NEXT: }
|
|
# CHECK-NEXT: ]
|
|
# CHECK-NEXT: }
|
|
# CHECK-NEXT: ]
|
|
# CHECK-NEXT: }
|
|
# CHECK-NEXT: Function {
|
|
# CHECK-NEXT: At: 0x10
|
|
# CHECK-NEXT: Name: <?>
|
|
# CHECK-NEXT: BB Ranges [
|
|
# CHECK-NEXT: {
|
|
# CHECK-NEXT: Base Address: 0x10
|
|
# 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: HasIndirectBranch: No
|
|
# CHECK-NEXT: }
|
|
# CHECK-NEXT: ]
|
|
# CHECK-NEXT: }
|
|
# CHECK-NEXT: ]
|
|
# CHECK-NEXT: }
|
|
# CHECK-NEXT: ]
|
|
|
|
--- !ELF
|
|
FileHeader:
|
|
Class: ELFCLASS64
|
|
Data: ELFDATA2LSB
|
|
Type: ET_REL
|
|
Machine: EM_X86_64
|
|
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
|
|
BBRanges:
|
|
- BBEntries:
|
|
- ID: 0
|
|
AddressOffset: 0x0
|
|
Size: 0xF
|
|
Metadata: 0x1
|
|
- Version: 2
|
|
BBRanges:
|
|
- BBEntries:
|
|
- ID: 0
|
|
AddressOffset: 0x0
|
|
Size: 0x11
|
|
Metadata: 0x8
|
|
- 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
|
|
|
|
## Check that if we have a relocatable file and no relocation section for
|
|
## a SHT_LLVM_BB_ADDR_MAP section, we give the appropriate warnings.
|
|
|
|
--- !ELF
|
|
FileHeader:
|
|
Class: ELFCLASS64
|
|
Data: ELFDATA2LSB
|
|
Type: ET_REL
|
|
Machine: EM_X86_64
|
|
Sections:
|
|
- Name: .text
|
|
Type: SHT_PROGBITS
|
|
Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
|
|
- Name: .llvm_bb_addr_map
|
|
Type: SHT_LLVM_BB_ADDR_MAP
|
|
Link: .text
|
|
|
|
# RUN: yaml2obj %s --docnum=2 -o %t2.o
|
|
# RUN: llvm-readobj %t2.o --bb-addr-map 2>&1 | FileCheck %s --check-prefix=NO-RELA -DFILE=%t2.o
|
|
|
|
# NO-RELA: warning: '[[FILE]]': unable to get relocation section for SHT_LLVM_BB_ADDR_MAP section with index 2
|
|
|
|
## Check that we get a warning if we expect a relocation and it is not present.
|
|
|
|
--- !ELF
|
|
FileHeader:
|
|
Class: ELFCLASS64
|
|
Data: ELFDATA2LSB
|
|
Type: ET_REL
|
|
Machine: EM_X86_64
|
|
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
|
|
BBRanges:
|
|
- BBEntries:
|
|
- ID: 0
|
|
AddressOffset: 0x0
|
|
Size: 0xF
|
|
Metadata: 0x1
|
|
- Name: .rela.llvm_bb_addr_map
|
|
Type: SHT_RELA
|
|
Flags: [ SHF_INFO_LINK ]
|
|
Info: .llvm_bb_addr_map
|
|
|
|
# RUN: yaml2obj %s --docnum=3 -o %t3.o
|
|
# RUN: llvm-readobj %t3.o --bb-addr-map 2>&1 | FileCheck %s --check-prefix=MISSING-RELOCATION -DFILE=%t3.o
|
|
|
|
# MISSING-RELOCATION: warning: '[[FILE]]': unable to dump SHT_LLVM_BB_ADDR_MAP section with index 2: failed to get relocation data for offset: 2 in section SHT_LLVM_BB_ADDR_MAP section with index 2
|
|
|
|
## Check that if we have a missing relocated section, we fail and give the
|
|
## appropriate warning.
|
|
|
|
--- !ELF
|
|
FileHeader:
|
|
Class: ELFCLASS64
|
|
Data: ELFDATA2LSB
|
|
Type: ET_REL
|
|
Machine: EM_X86_64
|
|
Sections:
|
|
- Name: .rela.llvm_bb_addr_map
|
|
Type: SHT_RELA
|
|
Flags: [ SHF_INFO_LINK ]
|
|
Info: 0xFF
|
|
|
|
# RUN: yaml2obj %s --docnum=4 -o %t4.o
|
|
# RUN: llvm-readobj %t4.o --bb-addr-map 2>&1 | FileCheck %s --check-prefix=NO-RELOCATED-SECTION -DFILE=%t4.o
|
|
|
|
# NO-RELOCATED-SECTION: warning: '[[FILE]]': failed to get SHT_LLVM_BB_ADDR_MAP section(s): SHT_RELA section with index 1: failed to get a relocated section: invalid section index: 255
|
|
|
|
## Check that if we have an ET_DYN file with a .rela.dyn section, we don't get
|
|
## a warning about a missing relocation section and can get the baddrmap data.
|
|
|
|
--- !ELF
|
|
FileHeader:
|
|
Class: ELFCLASS64
|
|
Data: ELFDATA2LSB
|
|
Type: ET_DYN
|
|
Machine: EM_X86_64
|
|
Sections:
|
|
- Name: .rela.dyn
|
|
Type: SHT_RELA
|
|
Flags: [ SHF_ALLOC ]
|
|
- Name: .llvm_bb_addr_map
|
|
Type: SHT_LLVM_BB_ADDR_MAP
|
|
Flags: [ SHF_LINK_ORDER ]
|
|
Entries:
|
|
- Version: 2
|
|
BBRanges:
|
|
- BaseAddress: 0xF
|
|
BBEntries:
|
|
- ID: 0
|
|
AddressOffset: 0x0
|
|
Size: 0xF
|
|
Metadata: 0x1
|
|
|
|
# RUN: yaml2obj %s --docnum=5 -o %t5.o
|
|
# RUN: llvm-readobj %t5.o --bb-addr-map 2>&1 | FileCheck %s --check-prefix=ET-DYN-NO-WARNING -DFILE=%t5.o
|
|
|
|
# ET-DYN-NO-WARNING: BBAddrMap [
|
|
# ET-DYN-NO-WARNING: Function {
|
|
# ET-DYN-NO-WARNING: At: 0xF
|
|
# ET-DYN-NO-WARNING: Name: <?>
|
|
# ET-DYN-NO-WARNING: BB Ranges [
|
|
# ET-DYN-NO-WARNING: {
|
|
# ET-DYN-NO-WARNING: Base Address: 0xF
|
|
# ET-DYN-NO-WARNING: BB Entries [
|
|
# ET-DYN-NO-WARNING: {
|
|
# ET-DYN-NO-WARNING: ID: 0
|
|
# ET-DYN-NO-WARNING: Offset: 0x0
|
|
# ET-DYN-NO-WARNING: Size: 0xF
|
|
# ET-DYN-NO-WARNING: HasReturn: Yes
|
|
# ET-DYN-NO-WARNING: HasTailCall: No
|
|
# ET-DYN-NO-WARNING: IsEHPad: No
|
|
# ET-DYN-NO-WARNING: CanFallThrough: No
|
|
# ET-DYN-NO-WARNING: HasIndirectBranch: No
|
|
# ET-DYN-NO-WARNING: }
|
|
# ET-DYN-NO-WARNING: ]
|
|
# ET-DYN-NO-WARNING: }
|
|
# ET-DYN-NO-WARNING: ]
|
|
# ET-DYN-NO-WARNING: }
|
|
# ET-DYN-NO-WARNING: ]
|